View source
<?php
namespace Drupal\Tests\layout_builder\Functional;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use Drupal\Tests\BrowserTestBase;
class LayoutBuilderPrepareLayoutTest extends BrowserTestBase {
protected static $modules = [
'field_ui',
'layout_builder',
'node',
'layout_builder_element_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->createContentType([
'type' => 'bundle_with_section_field',
]);
LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
->enableLayoutBuilder()
->setOverridable()
->save();
$this
->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The first node title',
'body' => [
[
'value' => 'The first node body',
],
],
]);
$this
->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The second node title',
'body' => [
[
'value' => 'The second node body',
],
],
]);
$this
->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The third node title',
'body' => [
[
'value' => 'The third node body',
],
],
]);
}
public function testAlterPrepareLayout() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this
->drupalCreateUser([
'access content',
'administer blocks',
'configure any layout',
'administer node display',
'configure all bundle_with_section_field node layout overrides',
]));
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$page
->clickLink('Manage layout');
$page
->clickLink('Add block');
$page
->clickLink('Powered by Drupal');
$page
->fillField('settings[label]', 'Default block title');
$page
->checkField('settings[label_display]');
$page
->pressButton('Add block');
$page
->pressButton('Save layout');
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('Default block title');
$this
->drupalGet('node/1/layout');
$assert_session
->pageTextContains('Test static block title');
$assert_session
->pageTextNotContains('Default block title');
$assert_session
->pageTextContains('Test second static block title');
$this
->drupalGet('node/2/layout');
$assert_session
->pageTextContains('Test static block title');
$assert_session
->pageTextNotContains('Default block title');
$assert_session
->pageTextNotContains('Test second static block title');
$this
->drupalGet('node/3/layout');
$assert_session
->pageTextNotContains('Test static block title');
$assert_session
->pageTextContains('Default block title');
$assert_session
->pageTextContains('Test second static block title');
}
}