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