public function LayoutBuilderLockTest::testLock in Layout Builder Lock 8
Tests locking features on sections.
Throws
\Behat\Mink\Exception\ExpectationException
File
- tests/
src/ Functional/ LayoutBuilderLockTest.php, line 170
Class
- LayoutBuilderLockTest
- Tests Layout Builder Lock.
Namespace
Drupal\Tests\layout_builder_lock\FunctionalCode
public function testLock() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
// Create first node.
$node_1 = $this
->drupalCreateNode([
'type' => 'landing_page',
'title' => 'Homepage 1',
]);
// Check as editor.
$this
->drupalLogin($this->editor);
$this
->drupalGet('node/' . $node_1
->id() . '/layout');
// Get the block uuid from the body field.
$id = $assert_session
->elementExists('css', '.layout-builder__region > div:nth-child(3)');
$this->body_field_block_uuid = $id
->getAttribute('data-layout-block-uuid');
// Check links and access.
$this
->checkLinksAndAccess($assert_session, $node_1);
// Configure the section locks.
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/layout_builder/configure/section/defaults/node.landing_page.default/0');
$edit = [];
$edit['layout_builder_lock[' . LayoutBuilderLock::LOCKED_BLOCK_ADD . ']'] = TRUE;
$edit['layout_builder_lock[' . LayoutBuilderLock::LOCKED_BLOCK_MOVE . ']'] = TRUE;
$edit['layout_builder_lock[' . LayoutBuilderLock::LOCKED_BLOCK_UPDATE . ']'] = TRUE;
$edit['layout_builder_lock[' . LayoutBuilderLock::LOCKED_BLOCK_DELETE . ']'] = TRUE;
$edit['layout_builder_lock[' . LayoutBuilderLock::LOCKED_SECTION_BEFORE . ']'] = TRUE;
$edit['layout_builder_lock[' . LayoutBuilderLock::LOCKED_SECTION_BLOCK_MOVE . ']'] = TRUE;
$edit['layout_builder_lock[' . LayoutBuilderLock::LOCKED_SECTION_AFTER . ']'] = TRUE;
$edit['layout_builder_lock[' . LayoutBuilderLock::LOCKED_SECTION_CONFIGURE . ']'] = TRUE;
$this
->drupalPostForm(NULL, $edit, 'Update');
$page
->pressButton('Save layout');
// Create second node.
$node_2 = $this
->drupalCreateNode([
'type' => 'landing_page',
'title' => 'Homepage 2',
]);
// Check as editor.
$this
->drupalLogin($this->editor);
$this
->drupalGet('node/' . $node_2
->id() . '/layout');
$this
->checkLinksAndAccess($assert_session, $node_2, TRUE, 403);
// Links will still exist on node 1 as the overridden settings are used.
$this
->drupalGet('node/' . $node_1
->id() . '/layout');
$this
->checkLinksAndAccess($assert_session, $node_1);
// Override per entity is allowed for administrators.
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('layout_builder/configure/section/overrides/node.' . $node_2
->id() . '/0');
$assert_session
->statusCodeEquals(200);
$assert_session
->responseContains('Lock settings');
// Check if a user can manage override.
$this
->drupalLogin($this->editor);
$this
->drupalGet('node/' . $node_2
->id() . '/layout');
$assert_session
->responseNotContains('Configure section 1');
$this
->drupalGet('layout_builder/configure/section/overrides/node.' . $node_2
->id() . '/0');
$assert_session
->statusCodeEquals(403);
$this
->drupalLogin($this->editorOverride);
$this
->drupalGet('node/' . $node_2
->id() . '/layout');
$assert_session
->responseContains('Configure section 1');
$this
->drupalGet('layout_builder/configure/section/overrides/node.' . $node_2
->id() . '/0');
$assert_session
->statusCodeEquals(200);
// Override settings on override.
$node_3 = $this
->drupalCreateNode([
'type' => 'landing_page',
'title' => 'Homepage 3',
]);
$this
->drupalGet('node/' . $node_3
->id() . '/layout');
$assert_session
->statusCodeEquals(200);
$this
->drupalGet('layout_builder/configure/section/overrides/node.' . $node_3
->id() . '/0');
$assert_session
->statusCodeEquals(200);
$assert_session
->responseContains('Lock settings');
$edit = [];
$edit['layout_builder_lock[' . LayoutBuilderLock::LOCKED_SECTION_AFTER . ']'] = FALSE;
$this
->drupalPostForm(NULL, $edit, 'Update');
$page
->pressButton('Save layout');
$this
->drupalLogin($this->editor);
$this
->drupalGet('node/' . $node_3
->id() . '/layout');
$this
->checkLinksAndAccess($assert_session, $node_3, TRUE, 403, TRUE);
// Try to add a new section.
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('layout_builder/configure/section/defaults/node.landing_page.default/1/layout_onecol');
$assert_session
->statusCodeEquals(200);
$assert_session
->responseContains('Locks can be configured when the section has been added.');
$this
->drupalPostForm(NULL, [], 'Add section');
$assert_session
->statusCodeEquals(200);
// Test the 'bypass lock settings on layout overrides', in combination
// with 'manage lock settings on sections'. In this case, the user does not
// have the permission to do anything on the override.
$this
->drupalLogin($this->adminUserNoBypass);
$this
->drupalGet('/layout_builder/configure/section/defaults/node.landing_page.default/0');
$assert_session
->statusCodeEquals(200);
$assert_session
->responseContains('Lock settings');
$this
->drupalGet('node/' . $node_2
->id() . '/layout');
$this
->checkLinksAndAccess($assert_session, $node_2, TRUE, 403);
// Check custom inline block can be updated in a section that is configured
// to allow adding new blocks and not allowing updating default blocks.
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/layout_builder/configure/section/defaults/node.landing_page.default/0');
$edit = [];
$edit['layout_builder_lock[' . LayoutBuilderLock::LOCKED_BLOCK_ADD . ']'] = FALSE;
$this
->drupalPostForm(NULL, $edit, 'Update');
$this
->drupalGet('/layout_builder/add/block/defaults/node.landing_page.default/0/content/inline_block:basic');
$edit = [];
$edit['settings[label]'] = 'Default custom block title';
$edit['settings[block_form][body][0][value]'] = 'Default custom block content';
$this
->drupalPostForm(NULL, $edit, 'Add block');
// Get the block uuid from the custom block.
$id = $assert_session
->elementExists('css', '.layout-builder__region > div:nth-child(4)');
$this->custom_default_block_uuid = $id
->getAttribute('data-layout-block-uuid');
$page
->pressButton('Save layout');
$this
->drupalGet('/layout_builder/configure/section/defaults/node.landing_page.default/0');
$assert_session
->checkboxNotChecked('layout_builder_lock[4]');
$this
->drupalGet('/layout_builder/update/block/defaults/node.landing_page.default/0/content/' . $this->custom_default_block_uuid);
$assert_session
->statusCodeEquals(200);
$assert_session
->responseContains('Default custom block content');
// Check as editor.
$node_4 = $this
->drupalCreateNode([
'type' => 'landing_page',
'title' => 'Landing page 2',
]);
$this
->drupalLogin($this->editor);
$this
->drupalGet('node/' . $node_4
->id() . '/layout');
$assert_session
->responseContains('Default custom block content');
$assert_session
->linkExists('Add block');
$this
->drupalGet('/layout_builder/update/block/overrides/node.' . $node_4
->id() . '/0/content/' . $this->custom_default_block_uuid);
$assert_session
->statusCodeEquals(403);
// Add custom block as editor
$this
->drupalGet('/layout_builder/add/block/overrides/node.' . $node_4
->id() . '/0/content/inline_block:basic');
$edit = [];
$edit['settings[label]'] = 'Editor block title';
$edit['settings[block_form][body][0][value]'] = 'Editor block content';
$this
->drupalPostForm(NULL, $edit, 'Add block');
$id = $assert_session
->elementExists('css', '.layout-builder__region > div:nth-child(5)');
$this->custom_editor_block_uuid = $id
->getAttribute('data-layout-block-uuid');
$page
->pressButton('Save layout');
$assert_session
->responseContains('Editor block content');
$this
->drupalGet('/layout_builder/update/block/overrides/node.' . $node_4
->id() . '/0/content/' . $this->custom_editor_block_uuid);
$assert_session
->statusCodeEquals(200);
}