3 namespace Drupal\Tests\paragraphs\FunctionalJavascript;
5 use Drupal\Core\Entity\Entity\EntityFormDisplay;
6 use Drupal\field\Entity\FieldConfig;
7 use Drupal\field\Entity\FieldStorageConfig;
8 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
11 * Test paragraphs user interface.
15 class ParagraphsExperimentalEditPerspectivesUiTest extends JavascriptTestBase {
18 use ParagraphsTestBaseTrait;
25 public static $modules = [
39 protected function setUp() {
44 * Test paragraphs user interface.
46 public function testEditPerspectives() {
49 'access content overview',
50 'edit behavior plugin settings'
53 $page = $this->getSession()->getPage();
54 $this->drupalGet('admin/structure/paragraphs_type/add');
56 'label' => 'TestPlugin',
58 'behavior_plugins[test_text_color][enabled]' => TRUE,
60 $this->drupalPostForm(NULL, $edit, t('Save and manage fields'));
61 $this->drupalGet('admin/structure/types/add');
63 'name' => 'TestContent',
64 'type' => 'testcontent',
66 $this->drupalPostForm(NULL, $edit, t('Save and manage fields'));
67 $this->drupalGet('admin/structure/types/manage/testcontent/fields/add-field');
69 'new_storage_type' => 'field_ui:entity_reference_revisions:paragraph',
70 'label' => 'testparagraphfield',
71 'field_name' => 'testparagraphfield',
73 $this->drupalPostForm(NULL, $edit, t('Save and continue'));
75 'settings[target_type]' => 'paragraph',
77 $this->drupalPostForm(NULL, $edit, t('Save field settings'));
79 'settings[handler_settings][target_bundles_drag_drop][testplugin][enabled]' => TRUE,
81 $this->drupalPostForm(NULL, $edit, t('Save settings'));
82 $this->drupalGet('admin/structure/types/manage/testcontent/form-display');
83 $page->selectFieldOption('fields[field_testparagraphfield][type]', 'paragraphs');
84 $this->assertSession()->assertWaitOnAjaxRequest();
85 $this->drupalPostForm(NULL, [], t('Save'));
86 $this->drupalGet('node/add/testcontent');
87 $this->clickLink('Behavior');
88 $style_selector = $page->find('css', '.form-item-field-testparagraphfield-0-behavior-plugins-test-text-color-text-color');
89 $this->assertTrue($style_selector->isVisible());
90 $this->clickLink('Content');
91 $this->assertFalse($style_selector->isVisible());
95 * Test if tabs are visible with no behavior elements.
97 public function testTabsVisibility() {
99 'access content overview',
102 $page = $this->getSession()->getPage();
103 $this->drupalGet('admin/structure/paragraphs_type/add');
105 'label' => 'TestPlugin',
106 'id' => 'testplugin',
108 $this->drupalPostForm(NULL, $edit, t('Save and manage fields'));
109 $this->drupalGet('admin/structure/types/add');
111 'name' => 'TestContent',
112 'type' => 'testcontent',
114 $this->drupalPostForm(NULL, $edit, t('Save and manage fields'));
115 $this->drupalGet('admin/structure/types/manage/testcontent/fields/add-field');
117 'new_storage_type' => 'field_ui:entity_reference_revisions:paragraph',
118 'label' => 'testparagraphfield',
119 'field_name' => 'testparagraphfield',
121 $this->drupalPostForm(NULL, $edit, t('Save and continue'));
123 'settings[target_type]' => 'paragraph',
125 $this->drupalPostForm(NULL, $edit, t('Save field settings'));
126 $this->drupalPostForm(NULL, NULL, t('Save settings'));
127 $this->drupalGet('admin/structure/types/manage/testcontent/form-display');
128 $page->selectFieldOption('fields[field_testparagraphfield][type]', 'paragraphs');
129 $this->assertSession()->assertWaitOnAjaxRequest();
130 $this->drupalPostForm(NULL, [], t('Save'));
131 $this->drupalGet('node/add/testcontent');
132 $style_selector = $page->find('css', '.paragraphs-tabs');
133 $this->assertFalse($style_selector->isVisible());
137 * Test edit perspectives works fine with multiple fields.
139 public function testPerspectivesWithMultipleFields() {
140 $this->loginAsAdmin([
141 'edit behavior plugin settings'
144 // Add a nested Paragraph type.
145 $paragraph_type = 'nested_paragraph';
146 $this->addParagraphsType($paragraph_type);
147 $this->addParagraphsField('nested_paragraph', 'paragraphs', 'paragraph');
149 'behavior_plugins[test_bold_text][enabled]' => TRUE,
151 $this->drupalPostForm('admin/structure/paragraphs_type/' . $paragraph_type, $edit, t('Save'));
153 $this->addParagraphedContentType('testcontent');
154 $this->addParagraphsField('testcontent', 'field_paragraphs2', 'node');
156 // Disable the default paragraph on both the node and the nested paragraph
157 // to explicitly test with no paragraph and avoid a loop.
158 EntityFormDisplay::load('node.testcontent.default')
159 ->setComponent('field_paragraphs', ['type' => 'paragraphs', 'settings' => ['default_paragraph_type' => '_none']])
160 ->setComponent('field_paragraphs2', ['type' => 'paragraphs', 'settings' => ['default_paragraph_type' => '_none']])
162 EntityFormDisplay::load('paragraph' . '.' . $paragraph_type . '.default')
163 ->setComponent('paragraphs', ['type' => 'paragraphs', 'settings' => ['default_paragraph_type' => '_none']])
166 $assert_session = $this->assertSession();
168 $this->drupalGet('node/add/testcontent');
169 $assert_session->elementNotExists('css', '.paragraphs-nested');
171 // Add a nested paragraph to the first field.
172 $button = $this->getSession()->getPage()->findButton('Add nested_paragraph');
175 $assert_session->assertWaitOnAjaxRequest();
176 $assert_session->elementExists('css', '.paragraphs-nested');
178 // Add a paragraph to the second field.
179 $region_field2 = $this->getSession()->getPage()->find('css', '.field--name-field-paragraphs2');
180 $button_field2 = $region_field2->findButton('Add nested_paragraph');
181 $button_field2->press();
182 $assert_session->assertWaitOnAjaxRequest();
184 // Ge the style checkboxes from each field, make sure they are not visible
186 $page = $this->getSession()->getPage();
187 $style_selector = $page->findField('field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]');
188 $this->assertFalse($style_selector->isVisible());
189 $style_selector2 = $page->findField('field_paragraphs2[0][behavior_plugins][test_bold_text][bold_text]');
190 $this->assertFalse($style_selector2->isVisible());
192 // Switch to Behavior on the first field, then the second, make sure
193 // the visibility of the checkboxes is correct after each change.
194 $this->clickLink('Behavior', 0);
195 $this->assertTrue($style_selector->isVisible());
196 $this->assertFalse($style_selector2->isVisible());
197 $this->clickLink('Behavior', 1);
198 $this->assertTrue($style_selector->isVisible());
199 $this->assertTrue($style_selector2->isVisible());
201 // Switch the second field back to Content, verify visibility again.
202 $this->clickLink('Content', 1);
203 $this->assertTrue($style_selector->isVisible());
204 $this->assertFalse($style_selector2->isVisible());