3 namespace Drupal\paragraphs\Tests\Experimental;
6 * Tests the configuration of paragraphs in relation to ief.
10 class ParagraphsExperimentalInlineEntityFormTest extends ParagraphsExperimentalTestBase {
17 public static $modules = [
22 * Tests the revision of paragraphs.
24 public function testParagraphsIEFPreview() {
25 // Create article content type with a paragraphs field.
26 $this->addParagraphedContentType('article', 'field_paragraphs');
27 $this->loginAsAdmin(['create article content', 'edit any article content']);
29 // Create the paragraphs type simple.
30 $this->addParagraphsType('simple');
31 $this->addParagraphsType('text');
33 // Create a reference to an article.
34 $this->fieldUIAddNewField('admin/structure/paragraphs_type/simple', 'article', 'Article', 'field_ui:entity_reference:node', [
35 'settings[target_type]' => 'node',
36 'cardinality' => 'number',
37 'cardinality_number' => 1,
40 'settings[handler_settings][target_bundles][article]' => TRUE
43 // Enable IEF simple widget.
44 $this->drupalGet('admin/structure/paragraphs_type/simple/form-display');
46 'fields[field_article][type]' => 'inline_entity_form_simple',
48 $this->drupalPostForm(NULL, $edit, t('Save'));
50 // Set the paragraphs widget mode to preview.
51 $this->setParagraphsWidgetMode('article', 'field_paragraphs', 'preview');
53 // Create node with one paragraph.
54 $this->drupalGet('node/add/article');
55 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_simple_add_more');
57 // Set the values and save.
59 'title[0][value]' => 'Dummy1',
60 'field_paragraphs[0][subform][field_article][0][inline_entity_form][title][0][value]' => 'Dummy2',
62 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
64 // Go back into edit page.
65 $node = $this->getNodeByTitle('Dummy1');
66 $this->drupalGet('node/' . $node->id() . '/edit');
68 // Try to open the previewed paragraph.
69 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit');
73 * Tests the reordering of previewed paragraphs.
75 public function testParagraphsIEFChangeOrder() {
76 // Create article content type with a paragraphs field.
77 $this->addParagraphedContentType('article', 'field_paragraphs');
78 $this->loginAsAdmin(['create article content', 'edit any article content']);
80 // Create the paragraphs type simple.
81 $this->addParagraphsType('simple');
82 $this->addParagraphsType('text');
85 // Create a reference to an article.
86 $this->fieldUIAddNewField('admin/structure/paragraphs_type/simple', 'article', 'Article', 'field_ui:entity_reference:node', [
87 'settings[target_type]' => 'node',
88 'cardinality' => 'number',
89 'cardinality_number' => '1',
92 'settings[handler_settings][target_bundles][article]' => TRUE
95 // Set cardinality explicit to -1.
96 $this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_paragraphs/storage');
98 'settings[target_type]' => 'paragraph',
99 'cardinality' => '-1',
101 $this->drupalPostForm(NULL, $edit, t('Save field settings'));
103 // Enable IEF simple widget.
104 $this->drupalGet('admin/structure/paragraphs_type/simple/form-display');
106 'fields[field_article][type]' => 'inline_entity_form_simple',
108 $this->drupalPostForm(NULL, $edit, t('Save'));
110 // Set the paragraphs widget mode to preview.
111 $this->setParagraphsWidgetMode('article', 'field_paragraphs', 'preview');
113 // Create node with one paragraph.
114 $this->drupalGet('node/add/article');
115 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_simple_add_more');
117 // Set the values and save.
119 'title[0][value]' => 'Article 1',
120 'field_paragraphs[0][subform][field_article][0][inline_entity_form][title][0][value]' => 'Basic page 1',
123 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
125 // Go back into edit page.
126 $node = $this->getNodeByTitle('Article 1');
127 $this->drupalGet('node/' . $node->id() . '/edit');
129 // Create second paragraph.
130 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_simple_add_more');
132 // Set the values of second paragraph and change the order.
134 'field_paragraphs[1][subform][field_article][0][inline_entity_form][title][0][value]' => 'Basic 2',
135 'field_paragraphs[0][_weight]' => -1,
136 'field_paragraphs[1][_weight]' => -2,
138 $this->drupalPostForm(NULL, $edit, t('Save and keep published'));