<?php
namespace Drupal\Tests\paragraphs\FunctionalJavascript;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\paragraphs\Entity\ParagraphsType;
use Drupal\Tests\paragraphs\Traits\ParagraphsCoreVersionUiTestTrait;
class ParagraphsStableEditPerspectivesUiTest extends WebDriverTestBase {
use LoginAdminTrait;
use ParagraphsTestBaseTrait;
use ParagraphsCoreVersionUiTestTrait;
protected static $modules = [
'node',
'paragraphs_test',
'paragraphs',
'field',
'field_ui',
'block',
'link',
'text',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->placeDefaultBlocks();
}
public function testEditPerspectives() {
$this
->loginAsAdmin([
'edit behavior plugin settings',
]);
$page = $this
->getSession()
->getPage();
$this
->drupalGet('admin/structure/paragraphs_type/add');
$page
->fillField('label', 'TestPlugin');
$this
->assertSession()
->waitForElementVisible('css', '#edit-name-machine-name-suffix .link');
$page
->pressButton('Edit');
$page
->fillField('id', 'testplugin');
$page
->checkField('behavior_plugins[test_text_color][enabled]');
$page
->pressButton('Save and manage fields');
$this
->addParagraphedContentType('testcontent', 'field_testparagraphfield');
$this
->addFieldtoParagraphType('testplugin', 'body', 'string_long');
$this
->drupalGet('node/add/testcontent');
$this
->clickLink('Behavior');
$style_selector = $page
->find('css', '.form-item-field-testparagraphfield-0-behavior-plugins-test-text-color-text-color');
$this
->assertTrue($style_selector
->isVisible());
$this
->clickLink('Content');
$this
->assertFalse($style_selector
->isVisible());
$this
->getSession()
->resizeWindow(800, 450);
$this
->drupalGet('node/add/testcontent');
$button = $this
->getSession()
->getPage()
->findButton('Add TestPlugin');
$button
->press();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$button
->press();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$button
->press();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->getSession()
->getPage()
->find('css', '.field--widget-paragraphs tbody > tr:nth-child(4)')
->mouseOver();
$this
->assertSession()
->assertVisibleInViewport('css', '.paragraphs-tabs');
$this
->getSession()
->getPage()
->find('css', '.field--widget-paragraphs tbody > tr:nth-child(2)')
->mouseOver();
$this
->getSession()
->evaluateScript('window.scrollBy(0, -10);');
$this
->assertSession()
->assertNotVisibleInViewport('css', '.field--widget-paragraphs tbody > tr:first-child');
$this
->assertSession()
->assertVisibleInViewport('css', '.field--widget-paragraphs tbody > tr:nth-child(2)');
$this
->assertSession()
->assertVisibleInViewport('css', '.field--widget-paragraphs tbody > tr:nth-child(3)');
$this
->assertSession()
->assertNotVisibleInViewport('css', '.field--widget-paragraphs tbody > tr:nth-child(4)');
$this
->assertSession()
->assertNotVisibleInViewport('css', '.field-add-more-submit');
$this
->clickLink('Behavior');
$this
->assertSession()
->assertVisibleInViewport('css', '.field--widget-paragraphs tbody > tr:nth-child(2)');
$this
->assertSession()
->assertVisibleInViewport('css', '.field--widget-paragraphs tbody > tr:nth-child(3)');
$this
->assertSession()
->assertVisibleInViewport('css', '.field--widget-paragraphs tbody > tr:nth-child(4)');
$this
->clickLink('Content');
$this
->assertSession()
->assertNotVisibleInViewport('css', '.field--widget-paragraphs tbody > tr:first-child');
$this
->assertSession()
->assertVisibleInViewport('css', '.field--widget-paragraphs tbody > tr:nth-child(2)');
$this
->assertSession()
->assertVisibleInViewport('css', '.field--widget-paragraphs tbody > tr:nth-child(3)');
$this
->assertSession()
->assertNotVisibleInViewport('css', '.field--widget-paragraphs tbody > tr:nth-child(4)');
$this
->assertSession()
->assertNotVisibleInViewport('css', '.field-add-more-submit');
}
public function testPerspectivesAddModesVisibility() {
$this
->loginAsAdmin([
'edit behavior plugin settings',
]);
$page = $this
->getSession()
->getPage();
$this
->drupalGet('admin/structure/paragraphs_type/add');
$page
->fillField('label', 'TestPlugin');
$this
->assertSession()
->waitForElementVisible('css', '#edit-name-machine-name-suffix .link');
$page
->pressButton('Edit');
$page
->fillField('id', 'testplugin');
$page
->checkField('behavior_plugins[test_text_color][enabled]');
$page
->pressButton('Save and manage fields');
$this
->addParagraphedContentType('testcontent', 'field_testparagraphfield');
$this
->addFieldtoParagraphType('testplugin', 'body', 'string_long');
$form_display = \Drupal::service('entity_display.repository')
->getFormDisplay('node', 'testcontent');
$component = $form_display
->getComponent('field_testparagraphfield');
$component['settings']['add_mode'] = 'button';
$form_display
->setComponent('field_testparagraphfield', $component)
->save();
$this
->drupalGet('node/add/testcontent');
$add_wrapper = $page
->find('css', '.paragraphs-add-wrapper');
$this
->assertTrue($add_wrapper
->isVisible());
$this
->clickLink('Behavior');
$this
->assertFalse($add_wrapper
->isVisible());
$component['settings']['add_mode'] = 'select';
$form_display
->setComponent('field_testparagraphfield', $component)
->save();
$this
->drupalGet('node/add/testcontent');
$add_wrapper = $page
->find('css', '.paragraphs-add-wrapper');
$this
->assertTrue($add_wrapper
->isVisible());
$this
->clickLink('Behavior');
$this
->assertFalse($add_wrapper
->isVisible());
$component['settings']['add_mode'] = 'modal';
$form_display
->setComponent('field_testparagraphfield', $component)
->save();
$this
->drupalGet('node/add/testcontent');
$add_wrapper = $page
->find('css', '.paragraphs-add-wrapper');
$this
->assertTrue($add_wrapper
->isVisible());
$this
->clickLink('Behavior');
$this
->assertFalse($add_wrapper
->isVisible());
$component['settings']['add_mode'] = 'dropdown';
$form_display
->setComponent('field_testparagraphfield', $component)
->save();
$this
->drupalGet('node/add/testcontent');
$add_wrapper = $page
->find('css', '.paragraphs-add-wrapper');
$this
->assertTrue($add_wrapper
->isVisible());
$this
->clickLink('Behavior');
$this
->assertFalse($add_wrapper
->isVisible());
}
public function testTabsVisibility() {
$this
->loginAsAdmin([
'access content overview',
]);
$page = $this
->getSession()
->getPage();
$this
->drupalGet('admin/structure/paragraphs_type/add');
$page
->fillField('label', 'TestPlugin');
$this
->assertSession()
->waitForElementVisible('css', '#edit-name-machine-name-suffix .link');
$page
->pressButton('Edit');
$page
->fillField('id', 'testplugin');
$page
->pressButton('Save and manage fields');
$this
->drupalGet('admin/structure/types/add');
$page
->fillField('name', 'TestContent');
$this
->assertSession()
->waitForElementVisible('css', '#edit-name-machine-name-suffix .link');
$page
->pressButton('Edit');
$page
->fillField('type', 'testcontent');
$page
->pressButton('Save and manage fields');
$this
->drupalGet('admin/structure/types/manage/testcontent/fields/add-field');
$page
->selectFieldOption('new_storage_type', 'field_ui:entity_reference_revisions:paragraph');
if ($this
->coreVersion('10.3')) {
$page
->pressButton('Continue');
}
$page
->fillField('label', 'testparagraphfield');
$this
->assertSession()
->waitForElementVisible('css', '#edit-name-machine-name-suffix .link');
$page
->pressButton('Edit');
$page
->fillField('field_name', 'testparagraphfield');
$page
->pressButton('Continue');
$edit = [
'field_storage[subform][settings][target_type]' => 'paragraph',
];
$this
->submitForm($edit, 'Save settings');
$this
->drupalGet('node/add/testcontent');
$style_selector = $page
->find('css', '.paragraphs-tabs');
$this
->assertFalse($style_selector
->isVisible());
}
public function testPerspectivesWithMultipleFields() {
$this
->loginAsAdmin([
'edit behavior plugin settings',
]);
$paragraph_type = 'nested_paragraph';
$this
->addParagraphsType($paragraph_type);
$this
->addParagraphsField('nested_paragraph', 'paragraphs', 'paragraph');
$edit = [
'behavior_plugins[test_bold_text][enabled]' => TRUE,
];
$this
->drupalGet('admin/structure/paragraphs_type/' . $paragraph_type);
$this
->submitForm($edit, 'Save');
$this
->addParagraphedContentType('testcontent');
$this
->addParagraphsField('testcontent', 'field_paragraphs2', 'node');
EntityFormDisplay::load('node.testcontent.default')
->setComponent('field_paragraphs', [
'type' => 'paragraphs',
'settings' => [
'default_paragraph_type' => '_none',
],
])
->setComponent('field_paragraphs2', [
'type' => 'paragraphs',
'settings' => [
'default_paragraph_type' => '_none',
],
])
->save();
EntityFormDisplay::load('paragraph' . '.' . $paragraph_type . '.default')
->setComponent('paragraphs', [
'type' => 'paragraphs',
'settings' => [
'default_paragraph_type' => '_none',
],
])
->save();
$assert_session = $this
->assertSession();
$this
->drupalGet('node/add/testcontent');
$assert_session
->elementNotExists('css', '.paragraphs-nested');
$button = $this
->getSession()
->getPage()
->findButton('Add nested_paragraph');
$button
->press();
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->elementExists('css', '.paragraphs-nested');
$region_field2 = $this
->getSession()
->getPage()
->find('css', '.field--name-field-paragraphs2');
$button_field2 = $region_field2
->findButton('Add nested_paragraph');
$button_field2
->press();
$assert_session
->assertWaitOnAjaxRequest();
$page = $this
->getSession()
->getPage();
$style_selector = $page
->findField('field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]');
$this
->assertFalse($style_selector
->isVisible());
$style_selector2 = $page
->findField('field_paragraphs2[0][behavior_plugins][test_bold_text][bold_text]');
$this
->assertFalse($style_selector2
->isVisible());
$this
->clickLink('Behavior', 0);
$this
->assertTrue($style_selector
->isVisible());
$this
->assertFalse($style_selector2
->isVisible());
$this
->clickLink('Behavior', 1);
$this
->assertTrue($style_selector
->isVisible());
$this
->assertTrue($style_selector2
->isVisible());
$this
->clickLink('Content', 1);
$this
->assertTrue($style_selector
->isVisible());
$this
->assertFalse($style_selector2
->isVisible());
}
}