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');
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 $this->drupalPostForm(NULL, ['title[0][value]' => 'paragraphed_title'], t('Save and publish'));
57 // Attempt to add a translation.
58 $node = $this->drupalGetNodeByTitle('paragraphed_title');
59 $this->drupalGet('node/' . $node->id() . '/translations');
60 $this->clickLink(t('Add'));
61 // Save the translation.
62 $this->drupalPostForm(NULL, [], t('Save and keep published (this translation)'));
63 $this->assertText('paragraphed_test paragraphed_title has been updated.');
67 * Tests content translation form translatability constraints messages.
69 public function testContentTranslationForm() {
71 'administer languages',
72 'administer content translation',
73 'create content translations',
74 'translate any entity',
77 // Check warning message is displayed.
78 $this->drupalGet('admin/config/regional/content-language');
79 $this->assertText('(* unsupported) Paragraphs fields do not support translation.');
81 $this->addParagraphedContentType('paragraphed_test', 'paragraphs_field');
83 // Check error message is not displayed.
84 $this->drupalGet('admin/config/regional/content-language');
85 $this->assertText('(* unsupported) Paragraphs fields do not support translation.');
86 $this->assertNoRaw('<div class="messages messages--error');
88 // Add a second language.
89 ConfigurableLanguage::create(['id' => 'de'])->save();
91 // Enable translation for paragraphed content type.
93 'entity_types[node]' => TRUE,
94 'settings[node][paragraphed_test][translatable]' => TRUE,
95 'settings[node][paragraphed_test][fields][paragraphs_field]' => FALSE,
97 $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
99 // Check error message is still not displayed.
100 $this->drupalGet('admin/config/regional/content-language');
101 $this->assertText('(* unsupported) Paragraphs fields do not support translation.');
102 $this->assertNoRaw('<div class="messages messages--error');
104 // Check content type field management warning.
105 $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs_field');
106 $this->assertText('Paragraphs fields do not support translation.');
108 // Make the paragraphs field translatable.
110 'entity_types[node]' => TRUE,
111 'settings[node][paragraphed_test][translatable]' => TRUE,
112 'settings[node][paragraphed_test][fields][paragraphs_field]' => TRUE,
114 $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
116 // Check content type field management error.
117 $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs_field');
118 $this->assertText('Paragraphs fields do not support translation.');
119 $this->assertRaw('<div class="messages messages--error');
121 // Check a not paragraphs translatable field does not display the message.
122 $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/add-field');
124 'new_storage_type' => 'field_ui:entity_reference:node',
125 'label' => 'new_no_paragraphs_field',
126 'field_name' => 'new_no_paragraphs_field',
128 $this->drupalPostForm(NULL, $edit, t('Save and continue'));
129 $this->drupalPostForm(NULL, [], t('Save field settings'));
130 $this->assertNoText('Paragraphs fields do not support translation.');
131 $this->assertNoRaw('<div class="messages messages--warning');
135 * Tests that we can use paragraphs widget only for paragraphs.
137 public function testAvoidUsingParagraphsWithWrongEntity() {
138 $node_type = NodeType::create([
143 $this->loginAsAdmin([
144 'edit any article content',
146 $this->addParagraphsType('paragraphed_type');
148 // Create reference to node.
149 $this->fieldUIAddNewField('admin/structure/types/manage/article', 'node_reference', 'NodeReference', 'entity_reference_revisions', [
150 'cardinality' => 'number',
151 'cardinality_number' => 1,
152 'settings[target_type]' => 'node',
154 'settings[handler_settings][target_bundles][article]' => 'article',
156 $this->drupalGet('admin/structure/types/manage/article/form-display');
157 $this->assertNoOption('edit-fields-field-node-reference-type', 'entity_reference_paragraphs');
158 $this->assertNoOption('edit-fields-field-node-reference-type', 'paragraphs');