View source
<?php
namespace Drupal\Tests\layout_builder_restrictions_by_region\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\layout_library\Entity\Layout;
use Drupal\Tests\layout_builder_restrictions\Traits\MoveBlockHelperTrait;
class MoveBlockCategoryRestrictionTest extends WebDriverTestBase {
use ContentTypeCreationTrait;
use MoveBlockHelperTrait;
const FIELD_UI_PREFIX = 'admin/structure/types/manage/bundle_with_section_field';
protected static $modules = [
'block',
'contextual',
'node',
'layout_builder',
'layout_library',
'layout_builder_restrictions',
'layout_builder_restrictions_by_region',
];
protected $defaultTheme = 'classy';
protected function setUp() {
parent::setUp();
$this
->createContentType([
'type' => 'bundle_with_section_field',
]);
$this
->drupalLogin($this
->drupalCreateUser([
'access administration pages',
'configure any layout',
'administer blocks',
'administer node display',
'administer node fields',
'access contextual links',
]));
$layout = Layout::create([
'id' => 'alpha',
'label' => 'Alpha',
'targetEntityType' => 'node',
'targetBundle' => 'bundle_with_section_field',
]);
$layout
->save();
$this
->drupalPostForm(static::FIELD_UI_PREFIX . '/display/default', [
'layout[enabled]' => TRUE,
], 'Save');
$this
->getSession()
->resizeWindow(1200, 4000);
$layout_builder_restrictions_plugins = [
'entity_view_mode_restriction' => [
'weight' => 1,
'enabled' => FALSE,
],
'entity_view_mode_restriction_by_region' => [
'weight' => 0,
'enabled' => TRUE,
],
];
$config = \Drupal::service('config.factory')
->getEditable('layout_builder_restrictions.plugins');
$config
->set('plugin_config', $layout_builder_restrictions_plugins)
->save();
}
public function testMovePluginBlock() {
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$page
->clickLink('Manage layout');
$assert_session
->addressEquals(static::FIELD_UI_PREFIX . '/display/default/layout');
$expected_block_order = [
'.block-extra-field-blocknodebundle-with-section-fieldlinks',
'.block-field-blocknodebundle-with-section-fieldbody',
];
$this
->assertRegionBlocksOrder(0, 'content', $expected_block_order);
$page
->clickLink('Add section');
$assert_session
->waitForElementVisible('css', '#drupal-off-canvas');
$assert_session
->assertWaitOnAjaxRequest();
$page
->clickLink('Two column');
$assert_session
->assertWaitOnAjaxRequest();
$this
->assertNotEmpty($assert_session
->waitForElementVisible('css', 'input[value="Add section"]'));
$page
->pressButton('Add section');
$this
->assertRegionBlocksOrder(1, 'content', $expected_block_order);
$first_region_block_locator = '[data-layout-delta="0"].layout--twocol-section [data-region="first"] [data-layout-block-uuid]';
$assert_session
->elementNotExists('css', $first_region_block_locator);
$assert_session
->elementExists('css', '[data-layout-delta="0"].layout--twocol-section [data-region="first"] .layout-builder__add-block')
->click();
$this
->assertNotEmpty($assert_session
->waitForElementVisible('css', '#drupal-off-canvas a:contains("Powered by Drupal")'));
$assert_session
->assertWaitOnAjaxRequest();
$page
->clickLink('Powered by Drupal');
$this
->assertNotEmpty($assert_session
->waitForElementVisible('css', 'input[value="Add block"]'));
$assert_session
->assertWaitOnAjaxRequest();
$page
->pressButton('Add block');
$this
->assertNotEmpty($assert_session
->waitForElementVisible('css', $first_region_block_locator));
$this
->waitForNoElement('#drupal-off-canvas');
$assert_session
->assertWaitOnAjaxRequest();
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$this
->drupalGet(static::FIELD_UI_PREFIX . "/display/default");
$assert_session
->linkExists('Manage layout');
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-layouts"]/summary');
$element
->click();
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-layouts-layout-restriction-restricted"]');
$element
->click();
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-layouts-layouts-layout-onecol"]');
$element
->click();
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-layouts-layouts-layout-twocol-section"]');
$element
->click();
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-by-layout-layout-onecol"]/summary');
$element
->click();
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-by-layout-layout-onecol-table"]/tbody/tr[@data-region="all_regions"]//a');
$element
->click();
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->checkboxChecked('Allow all existing & new Content fields blocks.');
$assert_session
->checkboxNotChecked('Allow specific Content fields blocks:');
$element = $page
->find('xpath', '//*[starts-with(@id,"edit-allowed-blocks-content-fields-restriction-restrict-all--")]');
$element
->click();
$element = $page
->find('xpath', '//*[starts-with(@id,"edit-submit--")]');
$element
->click();
$assert_session
->assertWaitOnAjaxRequest();
$page
->pressButton('Save');
$page
->clickLink('Manage layout');
$expected_block_order_1 = [
'.block-extra-field-blocknodebundle-with-section-fieldlinks',
'.block-field-blocknodebundle-with-section-fieldbody',
];
$this
->assertRegionBlocksOrder(1, 'content', $expected_block_order_1);
$assert_session
->addressEquals(static::FIELD_UI_PREFIX . '/display/default/layout');
$this
->openMoveForm(1, 'content', 'block-field-blocknodebundle-with-section-fieldbody', [
'Links',
'Body (current)',
]);
$this
->moveBlockWithKeyboard('up', 'Body (current)', [
'Body (current)*',
'Links',
]);
$page
->pressButton('Move');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$modal = $page
->find('css', '#drupal-off-canvas p');
$this
->assertSame("There is a restriction on Body placement in the layout_onecol all_regions region for bundle_with_section_field content.", trim($modal
->getText()));
}
}