Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / src / Tests / Experimental / ParagraphsExperimentalConfigTest.php
1 <?php
2
3 namespace Drupal\paragraphs\Tests\Experimental;
4
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\node\Entity\NodeType;
7
8 /**
9  * Tests paragraphs configuration.
10  *
11  * @group paragraphs
12  */
13 class ParagraphsExperimentalConfigTest extends ParagraphsExperimentalTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = array(
21     'content_translation',
22   );
23
24   /**
25    * Tests adding paragraphs with no translation enabled.
26    */
27   public function testFieldTranslationDisabled() {
28     $this->loginAsAdmin([
29       'administer languages',
30       'administer content translation',
31       'create content translations',
32       'translate any entity',
33     ]);
34
35     // Add a paragraphed content type.
36
37     $this->addParagraphedContentType('paragraphed_test');
38     $this->addParagraphsType('paragraph_type_test');
39     $this->addParagraphsType('text');
40
41     // Add a second language.
42     ConfigurableLanguage::create(['id' => 'de'])->save();
43
44     // Enable translation for paragraphed content type. Do not enable
45     // translation for the ERR paragraphs field nor for fields on the
46     // paragraph type.
47     $edit = [
48       'entity_types[node]' => TRUE,
49       'settings[node][paragraphed_test][translatable]' => TRUE,
50       'settings[node][paragraphed_test][fields][field_paragraphs]' => FALSE,
51     ];
52     $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
53
54     // Create a node with a paragraph.
55     $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'field_paragraphs_paragraph_type_test_add_more');
56     $edit = ['title[0][value]' => 'paragraphed_title'];
57     $this->drupalPostForm(NULL, $edit, t('Save'));
58
59     // Attempt to add a translation.
60     $node = $this->drupalGetNodeByTitle('paragraphed_title');
61     $this->drupalGet('node/' . $node->id() . '/translations');
62     $this->clickLink(t('Add'));
63     // Save the translation.
64     $this->drupalPostForm(NULL, [], t('Save (this translation)'));
65     $this->assertText('paragraphed_test paragraphed_title has been updated.');
66   }
67
68   /**
69    * Tests content translation form translatability constraints messages.
70    */
71   public function testContentTranslationForm() {
72     $this->loginAsAdmin([
73       'administer languages',
74       'administer content translation',
75       'create content translations',
76       'translate any entity',
77     ]);
78
79     // Check warning message is displayed.
80     $this->drupalGet('admin/config/regional/content-language');
81     $this->assertText('(* unsupported) Paragraphs fields do not support translation.');
82
83     $this->addParagraphedContentType('paragraphed_test');
84     // Check error message is not displayed.
85     $this->drupalGet('admin/config/regional/content-language');
86     $this->assertText('(* unsupported) Paragraphs fields do not support translation.');
87     $this->assertNoRaw('<div class="messages messages--error');
88
89     // Add a second language.
90     ConfigurableLanguage::create(['id' => 'de'])->save();
91
92     // Enable translation for paragraphed content type.
93     $edit = [
94       'entity_types[node]' => TRUE,
95       'settings[node][paragraphed_test][translatable]' => TRUE,
96       'settings[node][paragraphed_test][fields][field_paragraphs]' => FALSE,
97     ];
98     $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
99
100     // Check error message is still not displayed.
101     $this->drupalGet('admin/config/regional/content-language');
102     $this->assertText('(* unsupported) Paragraphs fields do not support translation.');
103     $this->assertNoRaw('<div class="messages messages--error');
104
105     // Check content type field management warning.
106     $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.field_paragraphs');
107     $this->assertText('Paragraphs fields do not support translation.');
108
109     // Make the paragraphs field translatable.
110     $edit = [
111       'entity_types[node]' => TRUE,
112       'settings[node][paragraphed_test][translatable]' => TRUE,
113       'settings[node][paragraphed_test][fields][field_paragraphs]' => TRUE,
114     ];
115     $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
116
117     // Check content type field management error.
118     $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.field_paragraphs');
119     $this->assertText('Paragraphs fields do not support translation.');
120     $this->assertRaw('<div class="messages messages--error');
121
122     // Check a not paragraphs translatable field does not display the message.
123     $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/add-field');
124     $edit = [
125       'new_storage_type' => 'field_ui:entity_reference:node',
126       'label' => 'new_no_field_paragraphs',
127       'field_name' => 'new_no_field_paragraphs',
128     ];
129     $this->drupalPostForm(NULL, $edit, t('Save and continue'));
130     $this->drupalPostForm(NULL, [], t('Save field settings'));
131     $this->assertNoText('Paragraphs fields do not support translation.');
132     $this->assertNoRaw('<div class="messages messages--warning');
133   }
134
135   /**
136    * Tests that we can use paragraphs widget only for paragraphs.
137    */
138   public function testAvoidUsingParagraphsWithWrongEntity() {
139     $node_type = NodeType::create([
140       'type' => 'article',
141       'name' => 'article',
142     ]);
143     $node_type->save();
144     $this->loginAsAdmin([
145       'edit any article content',
146     ]);
147     $this->addParagraphsType('paragraphed_type');
148
149     // Create reference to node.
150     $this->fieldUIAddNewField('admin/structure/types/manage/article', 'node_reference', 'NodeReference', 'entity_reference_revisions', [
151       'cardinality' => 'number',
152       'cardinality_number' => 1,
153       'settings[target_type]' => 'node',
154     ], [
155       'settings[handler_settings][target_bundles][article]' => 'article',
156     ]);
157     $this->drupalGet('admin/structure/types/manage/article/form-display');
158     $this->assertNoOption('edit-fields-field-node-reference-type', 'entity_reference_paragraphs');
159     $this->assertNoOption('edit-fields-field-node-reference-type', 'paragraphs');
160   }
161
162   /**
163    * Test included Paragraph types.
164    */
165   public function testIncludedParagraphTypes() {
166     $this->loginAsAdmin();
167     // Add a Paragraph content type and 2 Paragraphs types.
168     $this->addParagraphedContentType('paragraphed_test', 'paragraphs');
169     $this->addParagraphsType('paragraph_type_test');
170     $this->addParagraphsType('text');
171
172     $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
173     $edit = [
174       'settings[handler_settings][negate]' => 0,
175       'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1,
176     ];
177     $this->drupalPostForm(NULL, $edit, 'Save settings');
178     $this->assertText('Saved paragraphs configuration.');
179
180     $this->drupalGet('node/add/paragraphed_test');
181     $this->assertText('Add paragraph_type_test');
182     $this->assertNoText('Add text');
183     $edit = [
184       'title[0][value]' => 'Testing included types'
185     ];
186     $this->drupalPostForm(NULL, $edit, t('Save'));
187     $this->assertText('paragraphed_test Testing included types has been created.');
188
189     // Include all types.
190     $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
191     $edit = [
192       'settings[handler_settings][negate]' => 0,
193       'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1,
194       'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1,
195     ];
196     $this->drupalPostForm(NULL, $edit, 'Save settings');
197     $this->drupalGet('node/add/paragraphed_test');
198     $button_paragraphed_type_test = $this->xpath('//input[@id=:id]', [':id' => 'paragraphs-paragraph-type-test-add-more']);
199     $button_text = $this->xpath('//input[@id=:id]', [':id' => 'paragraphs-text-add-more']);
200     $this->assertNotNull($button_paragraphed_type_test);
201     $this->assertNotNull($button_text);
202     $edit = [
203       'title[0][value]' => 'Testing all excluded types'
204     ];
205     $this->drupalPostForm(NULL, $edit, t('Save'));
206     $this->assertText('paragraphed_test Testing all excluded types has been created.');
207   }
208
209   /**
210    * Test excluded Paragraph types.
211    */
212   public function testExcludedParagraphTypes() {
213     $this->loginAsAdmin();
214     // Add a Paragraph content type and 2 Paragraphs types.
215     $this->addParagraphedContentType('paragraphed_test', 'paragraphs');
216     $this->addParagraphsType('paragraph_type_test');
217     $this->addParagraphsType('text');
218
219     $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
220     $edit = [
221       'settings[handler_settings][negate]' => 1,
222       'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1,
223     ];
224     $this->drupalPostForm(NULL, $edit, 'Save settings');
225     $this->assertText('Saved paragraphs configuration.');
226
227     $this->drupalGet('node/add/paragraphed_test');
228     $this->assertText('Add paragraph_type_test');
229     $this->assertNoText('Add text');
230     $edit = [
231       'title[0][value]' => 'Testing excluded types'
232     ];
233     $this->drupalPostForm(NULL, $edit, t('Save'));
234     $this->assertText('paragraphed_test Testing excluded types has been created.');
235
236     // Exclude all types.
237     $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
238     $edit = [
239       'settings[handler_settings][negate]' => 1,
240       'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1,
241       'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1,
242     ];
243     $this->drupalPostForm(NULL, $edit, 'Save settings');
244     $this->drupalGet('node/add/paragraphed_test');
245     $this->assertText('You are not allowed to add any of the Paragraph types.');
246     $edit = [
247       'title[0][value]' => 'Testing all excluded types'
248     ];
249     $this->drupalPostForm(NULL, $edit, t('Save'));
250     $this->assertText('paragraphed_test Testing all excluded types has been created.');
251   }
252 }