3 namespace Drupal\paragraphs\Tests\Experimental;
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\node\Entity\NodeType;
9 * Tests paragraphs configuration.
13 class ParagraphsExperimentalConfigTest extends ParagraphsExperimentalTestBase {
20 public static $modules = array(
21 'content_translation',
25 * Tests adding paragraphs with no translation enabled.
27 public function testFieldTranslationDisabled() {
29 'administer languages',
30 'administer content translation',
31 'create content translations',
32 'translate any entity',
35 // Add a paragraphed content type.
37 $this->addParagraphedContentType('paragraphed_test');
38 $this->addParagraphsType('paragraph_type_test');
39 $this->addParagraphsType('text');
41 // Add a second language.
42 ConfigurableLanguage::create(['id' => 'de'])->save();
44 // Enable translation for paragraphed content type. Do not enable
45 // translation for the ERR paragraphs field nor for fields on the
48 'entity_types[node]' => TRUE,
49 'settings[node][paragraphed_test][translatable]' => TRUE,
50 'settings[node][paragraphed_test][fields][field_paragraphs]' => FALSE,
52 $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
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'));
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.');
69 * Tests content translation form translatability constraints messages.
71 public function testContentTranslationForm() {
73 'administer languages',
74 'administer content translation',
75 'create content translations',
76 'translate any entity',
79 // Check warning message is displayed.
80 $this->drupalGet('admin/config/regional/content-language');
81 $this->assertText('(* unsupported) Paragraphs fields do not support translation.');
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');
89 // Add a second language.
90 ConfigurableLanguage::create(['id' => 'de'])->save();
92 // Enable translation for paragraphed content type.
94 'entity_types[node]' => TRUE,
95 'settings[node][paragraphed_test][translatable]' => TRUE,
96 'settings[node][paragraphed_test][fields][field_paragraphs]' => FALSE,
98 $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
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');
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.');
109 // Make the paragraphs field translatable.
111 'entity_types[node]' => TRUE,
112 'settings[node][paragraphed_test][translatable]' => TRUE,
113 'settings[node][paragraphed_test][fields][field_paragraphs]' => TRUE,
115 $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
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');
122 // Check a not paragraphs translatable field does not display the message.
123 $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/add-field');
125 'new_storage_type' => 'field_ui:entity_reference:node',
126 'label' => 'new_no_field_paragraphs',
127 'field_name' => 'new_no_field_paragraphs',
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');
136 * Tests that we can use paragraphs widget only for paragraphs.
138 public function testAvoidUsingParagraphsWithWrongEntity() {
139 $node_type = NodeType::create([
144 $this->loginAsAdmin([
145 'edit any article content',
147 $this->addParagraphsType('paragraphed_type');
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',
155 'settings[handler_settings][target_bundles][article]' => 'article',
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');
163 * Test included Paragraph types.
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');
172 $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
174 'settings[handler_settings][negate]' => 0,
175 'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1,
177 $this->drupalPostForm(NULL, $edit, 'Save settings');
178 $this->assertText('Saved paragraphs configuration.');
180 $this->drupalGet('node/add/paragraphed_test');
181 $this->assertText('Add paragraph_type_test');
182 $this->assertNoText('Add text');
184 'title[0][value]' => 'Testing included types'
186 $this->drupalPostForm(NULL, $edit, t('Save'));
187 $this->assertText('paragraphed_test Testing included types has been created.');
189 // Include all types.
190 $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
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,
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);
203 'title[0][value]' => 'Testing all excluded types'
205 $this->drupalPostForm(NULL, $edit, t('Save'));
206 $this->assertText('paragraphed_test Testing all excluded types has been created.');
210 * Test excluded Paragraph types.
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');
219 $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
221 'settings[handler_settings][negate]' => 1,
222 'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1,
224 $this->drupalPostForm(NULL, $edit, 'Save settings');
225 $this->assertText('Saved paragraphs configuration.');
227 $this->drupalGet('node/add/paragraphed_test');
228 $this->assertText('Add paragraph_type_test');
229 $this->assertNoText('Add text');
231 'title[0][value]' => 'Testing excluded types'
233 $this->drupalPostForm(NULL, $edit, t('Save'));
234 $this->assertText('paragraphed_test Testing excluded types has been created.');
236 // Exclude all types.
237 $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
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,
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.');
247 'title[0][value]' => 'Testing all excluded types'
249 $this->drupalPostForm(NULL, $edit, t('Save'));
250 $this->assertText('paragraphed_test Testing all excluded types has been created.');