Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / src / Tests / Classic / ParagraphsInlineEntityFormTest.php
1 <?php
2
3 namespace Drupal\paragraphs\Tests\Classic;
4
5 /**
6  * Tests the configuration of paragraphs in relation to ief.
7  *
8  * @group paragraphs
9  */
10 class ParagraphsInlineEntityFormTest extends ParagraphsTestBase {
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', 'entity_reference_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'));
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
77     // Create article content type with a paragraphs field.
78     $this->addParagraphedContentType('article', 'field_paragraphs', 'entity_reference_paragraphs');
79     $this->loginAsAdmin(['create article content', 'edit any article content']);
80
81     // Create the paragraphs type simple.
82     $this->addParagraphsType('simple');
83     $this->addParagraphsType('text');
84
85
86     // Create a reference to an article.
87     $this->fieldUIAddNewField('admin/structure/paragraphs_type/simple', 'article', 'Article', 'field_ui:entity_reference:node', [
88       'settings[target_type]' => 'node',
89       'cardinality' => 'number',
90       'cardinality_number' => '1',
91     ], [
92       'required' => TRUE,
93       'settings[handler_settings][target_bundles][article]' => TRUE
94     ]);
95
96     // Set cardinality explicit to -1.
97     $this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_paragraphs/storage');
98     $edit = [
99       'settings[target_type]' => 'paragraph',
100       'cardinality' => '-1',
101     ];
102     $this->drupalPostForm(NULL, $edit, t('Save field settings'));
103
104     // Enable IEF simple widget.
105     $this->drupalGet('admin/structure/paragraphs_type/simple/form-display');
106     $edit = [
107       'fields[field_article][type]' => 'inline_entity_form_simple',
108     ];
109     $this->drupalPostForm(NULL, $edit, t('Save'));
110
111     // Set the paragraphs widget mode to preview.
112     $this->setParagraphsWidgetMode('article', 'field_paragraphs', 'preview');
113
114     // Create node with one paragraph.
115     $this->drupalGet('node/add/article');
116     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_simple_add_more');
117
118     // Set the values and save.
119     $edit = [
120       'title[0][value]' => 'Article 1',
121       'field_paragraphs[0][subform][field_article][0][inline_entity_form][title][0][value]' => 'Basic page 1',
122     ];
123
124     $this->drupalPostForm(NULL, $edit, t('Save'));
125
126     // Go back into edit page.
127     $node = $this->getNodeByTitle('Article 1');
128     $this->drupalGet('node/' . $node->id() . '/edit');
129
130     // Create second paragraph.
131     $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_simple_add_more');
132
133     // Set the values of second paragraph and change the order.
134     $edit = [
135       'field_paragraphs[1][subform][field_article][0][inline_entity_form][title][0][value]' => 'Basic 2',
136       'field_paragraphs[0][_weight]' => -1,
137       'field_paragraphs[1][_weight]' => -2,
138     ];
139     $this->drupalPostForm(NULL, $edit, t('Save'));
140   }
141
142 }