Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / src / Tests / Classic / ParagraphsConfigTest.php
1 <?php
2
3 namespace Drupal\paragraphs\Tests\Classic;
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 ParagraphsConfigTest extends ParagraphsTestBase {
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     $this->addParagraphedContentType('paragraphed_test', 'paragraphs_field', 'entity_reference_paragraphs');
37     $this->addParagraphsType('paragraph_type_test');
38     $this->addParagraphsType('text');
39
40     // Add a second language.
41     ConfigurableLanguage::create(['id' => 'de'])->save();
42
43     // Enable translation for paragraphed content type. Do not enable
44     // translation for the ERR paragraphs field nor for fields on the
45     // paragraph type.
46     $edit = [
47       'entity_types[node]' => TRUE,
48       'settings[node][paragraphed_test][translatable]' => TRUE,
49       'settings[node][paragraphed_test][fields][paragraphs_field]' => FALSE,
50     ];
51     $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
52
53     // Create a node with a paragraph.
54     $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'paragraphs_field_paragraph_type_test_add_more');
55     $edit = ['title[0][value]' => 'paragraphed_title'];
56     $this->drupalPostForm(NULL, $edit, t('Save'));
57
58     // Attempt to add a translation.
59     $node = $this->drupalGetNodeByTitle('paragraphed_title');
60     $this->drupalGet('node/' . $node->id() . '/translations');
61     $this->clickLink(t('Add'));
62     // Save the translation.
63    $this->drupalPostForm(NULL, [], t('Save (this translation)'));
64     $this->assertText('paragraphed_test paragraphed_title has been updated.');
65   }
66
67   /**
68    * Tests content translation form translatability constraints messages.
69    */
70   public function testContentTranslationForm() {
71     $this->loginAsAdmin([
72       'administer languages',
73       'administer content translation',
74       'create content translations',
75       'translate any entity',
76     ]);
77
78     // Check warning message is displayed.
79     $this->drupalGet('admin/config/regional/content-language');
80     $this->assertText('(* unsupported) Paragraphs fields do not support translation.');
81
82     $this->addParagraphedContentType('paragraphed_test', 'paragraphs_field', 'entity_reference_paragraphs');
83
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][paragraphs_field]' => 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.paragraphs_field');
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][paragraphs_field]' => 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.paragraphs_field');
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_paragraphs_field',
127       'field_name' => 'new_no_paragraphs_field',
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 required Paragraphs field.
137    */
138   public function testRequiredParagraphsField() {
139     $this->loginAsAdmin();
140
141     // Add a Paragraph content type and 2 Paragraphs types.
142     $this->addParagraphedContentType('paragraphed_test', 'paragraphs', 'entity_reference_paragraphs');
143     $this->addParagraphsType('paragraph_type_test');
144     $this->addParagraphsType('text');
145
146     // Make the paragraphs field required and save configuration.
147     $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
148     $edit = [
149       'required' => TRUE,
150     ];
151     $this->drupalPostForm(NULL, $edit, 'Save settings');
152     $this->assertText('Saved paragraphs configuration.');
153
154     // Assert that the field is displayed in the form as required.
155     $this->drupalGet('node/add/paragraphed_test');
156     $this->assertRaw('<strong class="form-required" data-drupal-selector="edit-paragraphs-title">');
157     $edit = [
158       'title[0][value]' => 'test_title',
159     ];
160     $this->drupalPostForm(NULL, $edit, t('Save'));
161     $this->assertText('paragraphs field is required.');
162     $this->drupalPostAjaxForm(NULL, [], 'paragraphs_paragraph_type_test_add_more');
163     $this->drupalPostForm(NULL, $edit, t('Save'));
164     $this->assertText('paragraphed_test test_title has been created.');
165   }
166
167   /**
168    * Tests that we can use paragraphs widget only for paragraphs.
169    */
170   public function testAvoidUsingParagraphsWithWrongEntity() {
171     $node_type = NodeType::create([
172       'type' => 'article',
173       'name' => 'article',
174     ]);
175     $node_type->save();
176     $this->loginAsAdmin([
177       'edit any article content',
178     ]);
179     $this->addParagraphsType('paragraphed_type');
180
181     // Create reference to node.
182     $this->fieldUIAddNewField('admin/structure/types/manage/article', 'node_reference', 'NodeReference', 'entity_reference_revisions', [
183       'cardinality' => 'number',
184       'cardinality_number' => 1,
185       'settings[target_type]' => 'node',
186     ], [
187       'settings[handler_settings][target_bundles][article]' => 'article',
188     ]);
189     $this->drupalGet('admin/structure/types/manage/article/form-display');
190     $this->assertNoOption('edit-fields-field-node-reference-type', 'entity_reference_paragraphs');
191     $this->assertNoOption('edit-fields-field-node-reference-type', 'paragraphs');
192   }
193
194   /**
195    * Test included Paragraph types.
196    */
197   public function testIncludedParagraphTypes() {
198     $this->loginAsAdmin();
199     // Add a Paragraph content type and 2 Paragraphs types.
200     $this->addParagraphedContentType('paragraphed_test', 'paragraphs', 'entity_reference_paragraphs');
201     $this->addParagraphsType('paragraph_type_test');
202     $this->addParagraphsType('text');
203
204     $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
205     $edit = [
206       'settings[handler_settings][negate]' => 0,
207       'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1,
208     ];
209     $this->drupalPostForm(NULL, $edit, 'Save settings');
210     $this->assertText('Saved paragraphs configuration.');
211
212     $this->drupalGet('node/add/paragraphed_test');
213     $this->assertText('Add paragraph_type_test');
214     $this->assertNoText('Add text');
215   }
216
217   /**
218    * Test excluded Paragraph types.
219    */
220   public function testExcludedParagraphTypes() {
221     $this->loginAsAdmin();
222     // Add a Paragraph content type and 2 Paragraphs types.
223     $this->addParagraphedContentType('paragraphed_test', 'paragraphs', 'entity_reference_paragraphs');
224     $this->addParagraphsType('paragraph_type_test');
225     $this->addParagraphsType('text');
226
227     $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
228     $edit = [
229       'settings[handler_settings][negate]' => 1,
230       'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1,
231     ];
232     $this->drupalPostForm(NULL, $edit, 'Save settings');
233     $this->assertText('Saved paragraphs configuration.');
234
235     $this->drupalGet('node/add/paragraphed_test');
236     $this->assertText('Add paragraph_type_test');
237     $this->assertNoText('Add text');
238   }
239
240 }