3 namespace Drupal\paragraphs\Tests\Classic;
6 * Tests the configuration of paragraphs in relation to ief.
10 class ParagraphsInlineEntityFormTest extends ParagraphsTestBase {
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', 'entity_reference_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'));
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() {
77 // Create article content type with a paragraphs field.
78 $this->addParagraphedContentType('article', 'field_paragraphs', 'entity_reference_paragraphs');
79 $this->loginAsAdmin(['create article content', 'edit any article content']);
81 // Create the paragraphs type simple.
82 $this->addParagraphsType('simple');
83 $this->addParagraphsType('text');
86 // Create a reference to an article.
87 $this->fieldUIAddNewField('admin/structure/paragraphs_type/simple', 'article', 'Article', 'field_ui:entity_reference:node', [
88 'settings[target_type]' => 'node',
89 'cardinality' => 'number',
90 'cardinality_number' => '1',
93 'settings[handler_settings][target_bundles][article]' => TRUE
96 // Set cardinality explicit to -1.
97 $this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_paragraphs/storage');
99 'settings[target_type]' => 'paragraph',
100 'cardinality' => '-1',
102 $this->drupalPostForm(NULL, $edit, t('Save field settings'));
104 // Enable IEF simple widget.
105 $this->drupalGet('admin/structure/paragraphs_type/simple/form-display');
107 'fields[field_article][type]' => 'inline_entity_form_simple',
109 $this->drupalPostForm(NULL, $edit, t('Save'));
111 // Set the paragraphs widget mode to preview.
112 $this->setParagraphsWidgetMode('article', 'field_paragraphs', 'preview');
114 // Create node with one paragraph.
115 $this->drupalGet('node/add/article');
116 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_simple_add_more');
118 // Set the values and save.
120 'title[0][value]' => 'Article 1',
121 'field_paragraphs[0][subform][field_article][0][inline_entity_form][title][0][value]' => 'Basic page 1',
124 $this->drupalPostForm(NULL, $edit, t('Save'));
126 // Go back into edit page.
127 $node = $this->getNodeByTitle('Article 1');
128 $this->drupalGet('node/' . $node->id() . '/edit');
130 // Create second paragraph.
131 $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_simple_add_more');
133 // Set the values of second paragraph and change the order.
135 'field_paragraphs[1][subform][field_article][0][inline_entity_form][title][0][value]' => 'Basic 2',
136 'field_paragraphs[0][_weight]' => -1,
137 'field_paragraphs[1][_weight]' => -2,
139 $this->drupalPostForm(NULL, $edit, t('Save'));