Version 1
[yaffs-website] / web / modules / contrib / paragraphs / src / Tests / Experimental / ParagraphsExperimentalInlineEntityFormTest.php
1 <?php
2
3 namespace Drupal\paragraphs\Tests\Experimental;
4
5 /**
6  * Tests the configuration of paragraphs in relation to ief.
7  *
8  * @group paragraphs
9  */
10 class ParagraphsExperimentalInlineEntityFormTest extends ParagraphsExperimentalTestBase {
11
12   /**
13    * Modules to enable.
14    *
15    * @var array
16    */
17   public static $modules = [
18     'inline_entity_form',
19   ];
20
21   /**
22    * Tests the revision of paragraphs.
23    */
24   public function testParagraphsIEFPreview() {
25     // Create article content type with a paragraphs field.
26     $this->addParagraphedContentType('article', 'field_paragraphs');
27     $this->loginAsAdmin(['create article content', 'edit any article content']);
28
29     // Create the paragraphs type simple.
30     $this->addParagraphsType('simple');
31     $this->addParagraphsType('text');
32
33     // Create a reference to an article.
34     $this->fieldUIAddNewField('admin/structure/paragraphs_type/simple', 'article', 'Article', 'field_ui:entity_reference:node', [
35       'settings[target_type]' => 'node',
36       'cardinality' => 'number',
37       'cardinality_number' => 1,
38     ], [
39       'required' => TRUE,
40       'settings[handler_settings][target_bundles][article]' => TRUE
41     ]);
42
43     // Enable IEF simple widget.
44     $this->drupalGet('admin/structure/paragraphs_type/simple/form-display');
45     $edit = [
46       'fields[field_article][type]' => 'inline_entity_form_simple',
47     ];
48     $this->drupalPostForm(NULL, $edit, t('Save'));
49
50     // Set the paragraphs widget mode to preview.
51     $this->setParagraphsWidgetMode('article', 'field_paragraphs', 'preview');
52
53     // Create node with one paragraph.
54     $this->drupalGet('node/add/article');
55     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_simple_add_more');
56
57     // Set the values and save.
58     $edit = [
59       'title[0][value]' => 'Dummy1',
60       'field_paragraphs[0][subform][field_article][0][inline_entity_form][title][0][value]' => 'Dummy2',
61     ];
62     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
63
64     // Go back into edit page.
65     $node = $this->getNodeByTitle('Dummy1');
66     $this->drupalGet('node/' . $node->id() . '/edit');
67
68     // Try to open the previewed paragraph.
69     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit');
70   }
71
72   /**
73    * Tests the reordering of previewed paragraphs.
74    */
75   public function testParagraphsIEFChangeOrder() {
76     // Create article content type with a paragraphs field.
77     $this->addParagraphedContentType('article', 'field_paragraphs');
78     $this->loginAsAdmin(['create article content', 'edit any article content']);
79
80     // Create the paragraphs type simple.
81     $this->addParagraphsType('simple');
82     $this->addParagraphsType('text');
83
84
85     // Create a reference to an article.
86     $this->fieldUIAddNewField('admin/structure/paragraphs_type/simple', 'article', 'Article', 'field_ui:entity_reference:node', [
87       'settings[target_type]' => 'node',
88       'cardinality' => 'number',
89       'cardinality_number' => '1',
90     ], [
91       'required' => TRUE,
92       'settings[handler_settings][target_bundles][article]' => TRUE
93     ]);
94
95     // Set cardinality explicit to -1.
96     $this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_paragraphs/storage');
97     $edit = [
98       'settings[target_type]' => 'paragraph',
99       'cardinality' => '-1',
100     ];
101     $this->drupalPostForm(NULL, $edit, t('Save field settings'));
102
103     // Enable IEF simple widget.
104     $this->drupalGet('admin/structure/paragraphs_type/simple/form-display');
105     $edit = [
106       'fields[field_article][type]' => 'inline_entity_form_simple',
107     ];
108     $this->drupalPostForm(NULL, $edit, t('Save'));
109
110     // Set the paragraphs widget mode to preview.
111     $this->setParagraphsWidgetMode('article', 'field_paragraphs', 'preview');
112
113     // Create node with one paragraph.
114     $this->drupalGet('node/add/article');
115     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_simple_add_more');
116
117     // Set the values and save.
118     $edit = [
119       'title[0][value]' => 'Article 1',
120       'field_paragraphs[0][subform][field_article][0][inline_entity_form][title][0][value]' => 'Basic page 1',
121     ];
122
123     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
124
125     // Go back into edit page.
126     $node = $this->getNodeByTitle('Article 1');
127     $this->drupalGet('node/' . $node->id() . '/edit');
128
129     // Create second paragraph.
130     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_simple_add_more');
131
132     // Set the values of second paragraph and change the order.
133     $edit = [
134       'field_paragraphs[1][subform][field_article][0][inline_entity_form][title][0][value]' => 'Basic 2',
135       'field_paragraphs[0][_weight]' => -1,
136       'field_paragraphs[1][_weight]' => -2,
137     ];
138     $this->drupalPostForm(NULL, $edit, t('Save and keep published'));
139   }
140
141 }