3 namespace Drupal\paragraphs\Tests\Classic;
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\node\Entity\NodeType;
9 * Tests paragraphs configuration.
13 class ParagraphsConfigTest extends ParagraphsTestBase {
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.
36 $this->addParagraphedContentType('paragraphed_test', 'paragraphs_field', 'entity_reference_paragraphs');
37 $this->addParagraphsType('paragraph_type_test');
38 $this->addParagraphsType('text');
40 // Add a second language.
41 ConfigurableLanguage::create(['id' => 'de'])->save();
43 // Enable translation for paragraphed content type. Do not enable
44 // translation for the ERR paragraphs field nor for fields on the
47 'entity_types[node]' => TRUE,
48 'settings[node][paragraphed_test][translatable]' => TRUE,
49 'settings[node][paragraphed_test][fields][paragraphs_field]' => FALSE,
51 $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
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'));
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.');
68 * Tests content translation form translatability constraints messages.
70 public function testContentTranslationForm() {
72 'administer languages',
73 'administer content translation',
74 'create content translations',
75 'translate any entity',
78 // Check warning message is displayed.
79 $this->drupalGet('admin/config/regional/content-language');
80 $this->assertText('(* unsupported) Paragraphs fields do not support translation.');
82 $this->addParagraphedContentType('paragraphed_test', 'paragraphs_field', 'entity_reference_paragraphs');
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][paragraphs_field]' => 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.paragraphs_field');
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][paragraphs_field]' => 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.paragraphs_field');
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_paragraphs_field',
127 'field_name' => 'new_no_paragraphs_field',
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 required Paragraphs field.
138 public function testRequiredParagraphsField() {
139 $this->loginAsAdmin();
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');
146 // Make the paragraphs field required and save configuration.
147 $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
151 $this->drupalPostForm(NULL, $edit, 'Save settings');
152 $this->assertText('Saved paragraphs configuration.');
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">');
158 'title[0][value]' => 'test_title',
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.');
168 * Tests that we can use paragraphs widget only for paragraphs.
170 public function testAvoidUsingParagraphsWithWrongEntity() {
171 $node_type = NodeType::create([
176 $this->loginAsAdmin([
177 'edit any article content',
179 $this->addParagraphsType('paragraphed_type');
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',
187 'settings[handler_settings][target_bundles][article]' => 'article',
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');
195 * Test included Paragraph types.
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');
204 $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
206 'settings[handler_settings][negate]' => 0,
207 'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1,
209 $this->drupalPostForm(NULL, $edit, 'Save settings');
210 $this->assertText('Saved paragraphs configuration.');
212 $this->drupalGet('node/add/paragraphed_test');
213 $this->assertText('Add paragraph_type_test');
214 $this->assertNoText('Add text');
218 * Test excluded Paragraph types.
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');
227 $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
229 'settings[handler_settings][negate]' => 1,
230 'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1,
232 $this->drupalPostForm(NULL, $edit, 'Save settings');
233 $this->assertText('Saved paragraphs configuration.');
235 $this->drupalGet('node/add/paragraphed_test');
236 $this->assertText('Add paragraph_type_test');
237 $this->assertNoText('Add text');