3 namespace Drupal\paragraphs\Tests\Experimental;
5 use Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait;
8 * Tests the configuration of paragraphs in relation to ief.
12 class ParagraphsExperimentalInlineEntityFormTest extends ParagraphsExperimentalTestBase {
14 use ParagraphsTestBaseTrait;
21 public static $modules = [
26 * Tests the revision of paragraphs.
28 public function testParagraphsIEFPreview() {
29 // Create article content type with a paragraphs field.
30 $this->addParagraphedContentType('article');
31 $this->loginAsAdmin(['create article content', 'edit any article content']);
33 // Create the paragraphs type simple.
34 $this->addParagraphsType('simple');
35 $this->addParagraphsType('text');
37 // Create a reference to an article.
38 $this->fieldUIAddNewField('admin/structure/paragraphs_type/simple', 'article', 'Article', 'field_ui:entity_reference:node', [
39 'settings[target_type]' => 'node',
40 'cardinality' => 'number',
41 'cardinality_number' => 1,
44 'settings[handler_settings][target_bundles][article]' => TRUE
47 // Enable IEF simple widget.
48 $this->drupalGet('admin/structure/paragraphs_type/simple/form-display');
50 'fields[field_article][type]' => 'inline_entity_form_simple',
52 $this->drupalPostForm(NULL, $edit, t('Save'));
54 // Set the paragraphs widget edit mode to "Closed" and the closed mode to
57 'edit_mode' => 'closed',
58 'closed_mode' => 'preview',
60 $this->setParagraphsWidgetSettings('article', 'field_paragraphs', $settings);
62 // Create node with one paragraph.
63 $this->drupalGet('node/add/article');
64 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_simple_add_more');
66 // Set the values and save.
68 'title[0][value]' => 'Dummy1',
69 'field_paragraphs[0][subform][field_article][0][inline_entity_form][title][0][value]' => 'Dummy2',
71 $this->drupalPostForm(NULL, $edit, t('Save'));
73 // Go back into edit page.
74 $node = $this->getNodeByTitle('Dummy1');
75 $this->drupalGet('node/' . $node->id() . '/edit');
77 // Try to open the previewed paragraph.
78 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit');
82 * Tests the reordering of previewed paragraphs.
84 public function testParagraphsIEFChangeOrder() {
85 // Create article content type with a paragraphs field.
86 $this->addParagraphedContentType('article');
87 $this->loginAsAdmin(['create article content', 'edit any article content']);
89 // Create the paragraphs type simple.
90 $this->addParagraphsType('simple');
91 $this->addParagraphsType('text');
94 // Create a reference to an article.
95 $this->fieldUIAddNewField('admin/structure/paragraphs_type/simple', 'article', 'Article', 'field_ui:entity_reference:node', [
96 'settings[target_type]' => 'node',
97 'cardinality' => 'number',
98 'cardinality_number' => '1',
101 'settings[handler_settings][target_bundles][article]' => TRUE
104 // Set cardinality explicit to -1.
105 $this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_paragraphs/storage');
107 'settings[target_type]' => 'paragraph',
108 'cardinality' => '-1',
110 $this->drupalPostForm(NULL, $edit, t('Save field settings'));
112 // Enable IEF simple widget.
113 $this->drupalGet('admin/structure/paragraphs_type/simple/form-display');
115 'fields[field_article][type]' => 'inline_entity_form_simple',
117 $this->drupalPostForm(NULL, $edit, t('Save'));
119 // Set the paragraphs widget closed mode to preview.
120 $this->setParagraphsWidgetSettings('article', 'field_paragraphs', ['closed_mode' => 'preview']);
122 // Create node with one paragraph.
123 $this->drupalGet('node/add/article');
124 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_simple_add_more');
126 // Set the values and save.
128 'title[0][value]' => 'Article 1',
129 'field_paragraphs[0][subform][field_article][0][inline_entity_form][title][0][value]' => 'Basic page 1',
132 $this->drupalPostForm(NULL, $edit, t('Save'));
134 // Go back into edit page.
135 $node = $this->getNodeByTitle('Article 1');
136 $this->drupalGet('node/' . $node->id() . '/edit');
138 // Create second paragraph.
139 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_simple_add_more');
141 // Set the values of second paragraph.
143 'field_paragraphs[1][subform][field_article][0][inline_entity_form][title][0][value]' => 'Basic 2'
145 $this->drupalPostForm(NULL, $edit, t('Save'));