3 namespace Drupal\Tests\paragraphs\FunctionalJavascript;
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
7 use Drupal\Core\Entity\Entity\EntityFormDisplay;
8 use Drupal\Core\Entity\Entity\EntityViewDisplay;
9 use Drupal\field\Entity\FieldConfig;
10 use Drupal\field\Entity\FieldStorageConfig;
11 use Drupal\field_ui\Tests\FieldUiTestTrait;
12 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
13 use Drupal\node\Entity\NodeType;
14 use Drupal\paragraphs\Entity\ParagraphsType;
15 use Drupal\paragraphs\Tests\Classic\ParagraphsCoreVersionUiTestTrait;
16 use Drupal\Tests\paragraphs\FunctionalJavascript\LoginAdminTrait;
19 * Test paragraphs user interface.
23 class ParagraphsExperimentalAddWidgetTest extends JavascriptTestBase {
27 use ParagraphsTestBaseTrait;
28 use ParagraphsCoreVersionUiTestTrait;
35 public static $modules = [
48 protected function setUp()
51 // Place the breadcrumb, tested in fieldUIAddNewField().
52 $this->drupalPlaceBlock('system_breadcrumb_block');
53 $this->drupalPlaceBlock('local_tasks_block');
54 $this->drupalPlaceBlock('local_actions_block');
55 $this->drupalPlaceBlock('page_title_block');
60 * Tests the add widget button with modal form.
62 public function testAddWidgetButton() {
63 $this->addParagraphedContentType('paragraphed_test');
65 'administer content types',
66 'administer node form display',
67 'edit any paragraphed_test content',
68 'create paragraphed_test content',
70 // Set the add mode on the content type to modal form widget.
71 $this->drupalGet('admin/structure/types/manage/paragraphed_test/form-display');
72 $page = $this->getSession()->getPage();
73 $page->pressButton('field_paragraphs_settings_edit');
74 $this->assertSession()->assertWaitOnAjaxRequest();
76 'fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'closed',
77 'fields[field_paragraphs][settings_edit_form][settings][add_mode]' => 'modal'
79 $this->drupalPostForm(NULL, $edit, 'Update');
80 $this->assertSession()->assertWaitOnAjaxRequest();
82 $this->drupalPostForm(NULL, [], t('Save'));
84 // Add a Paragraph type.
85 $paragraph_type = 'text_paragraph';
86 $this->addParagraphsType($paragraph_type);
87 $this->addParagraphsType('text');
89 // Add icons to the paragraphs types.
90 $icon_one = $this->addParagraphsTypeIcon($paragraph_type);
91 $icon_two = $this->addParagraphsTypeIcon('text');
93 // Add a text field to the text_paragraph type.
94 static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
96 // Create paragraph type Nested test.
97 $this->addParagraphsType('nested_test');
99 static::fieldUIAddNewField('admin/structure/paragraphs_type/nested_test', 'paragraphs', 'Paragraphs', 'entity_reference_revisions', [
100 'settings[target_type]' => 'paragraph',
101 'cardinality' => '-1',
104 // Set the settings for the field in the nested paragraph.
106 'type' => 'paragraphs',
107 'region' => 'content',
109 'edit_mode' => 'closed',
110 'add_mode' => 'modal',
111 'form_display_mode' => 'default',
114 EntityFormDisplay::load('paragraph.nested_test.default')->setComponent('field_paragraphs', $component)->save();
116 // Add a paragraphed test.
117 $this->drupalGet('node/add/paragraphed_test');
119 // Add a nested paragraph with the add widget.
120 $page->pressButton('Add Paragraph');
121 $this->assertSession()->assertWaitOnAjaxRequest();
122 $this->assertSession()->elementTextContains('css', '.ui-dialog-title', 'Add Paragraph');
123 $page->pressButton('nested_test');
124 $this->assertSession()->assertWaitOnAjaxRequest();
126 // Verify that the paragraphs type icons are being displayed.
127 $button_one = $this->assertSession()->buttonExists($paragraph_type);
128 $button_two = $this->assertSession()->buttonExists('text');
129 $this->assertContains($icon_one->getFilename(), $button_one->getAttribute('style'));
130 $this->assertContains($icon_two->getFilename(), $button_two->getAttribute('style'));
132 // Find the add button in the nested paragraph with xpath.
133 $element = $this->xpath('//div[contains(@class, "form-wrapper")]/div[contains(@class, "paragraph-type-add-modal")]/input');
134 $element[0]->click();
135 $this->assertSession()->assertWaitOnAjaxRequest();
137 // Add a text inside the nested paragraph.
138 $page = $this->getSession()->getPage();
139 $dialog = $page->find('xpath', '//div[contains(@class, "ui-dialog")]');
140 $dialog->pressButton('text');
141 $this->assertSession()->assertWaitOnAjaxRequest();
143 'title[0][value]' => 'Example title',
145 $this->drupalPostForm(NULL, $edit, t('Save'));
148 // Check the created paragraphed test.
149 $this->assertText('paragraphed_test Example title has been created.');
150 $this->assertRaw('paragraph--type--nested-test');
151 $this->assertRaw('paragraph--type--text');
153 // Add a paragraphs field with another paragraphs widget title to the
154 // paragraphed_test content type.
155 $this->addParagraphsField('paragraphed_test', 'field_paragraphs_two', 'node');
157 'title' => 'Renamed paragraph',
158 'title_plural' => 'Renamed paragraphs',
159 'add_mode' => 'modal',
161 $this->setParagraphsWidgetSettings('paragraphed_test', 'field_paragraphs_two', $settings);
163 // Check that the "add" buttons and modal form windows are labeled
165 $this->drupalGet('node/add/paragraphed_test');
166 $page->pressButton('Add Paragraph');
167 $this->assertSession()->assertWaitOnAjaxRequest();
168 $this->assertSession()->elementTextContains('css', '.ui-dialog-title', 'Add Paragraph');
169 $this->assertSession()->elementTextNotContains('css', '.ui-dialog-title', 'Add Renamed paragraph');
170 $this->assertSession()->elementExists('css', '.ui-dialog-titlebar-close')->press();
171 $page->pressButton('Add Renamed paragraph');
172 $this->assertSession()->assertWaitOnAjaxRequest();
173 $this->assertSession()->elementTextContains('css', '.ui-dialog-title', 'Add Renamed paragraph');
174 $this->assertSession()->elementTextNotContains('css', '.ui-dialog-title', 'Add Paragraph');