LayoutLibraryTest.php in Layout builder library 8
File
tests/src/Functional/LayoutLibraryTest.php
View source
<?php
namespace Drupal\Tests\layout_library\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
class LayoutLibraryTest extends BrowserTestBase {
use ContentTypeCreationTrait;
protected $defaultTheme = 'stark';
protected static $modules = [
'layout_library',
'block',
'node',
'options',
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_actions_block');
$this
->drupalPlaceBlock('local_tasks_block');
$this
->createContentType([
'type' => 'dogs',
]);
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'create dogs content',
'edit own dogs content',
'administer node display',
]));
}
public function testUseLayout() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$node = $this
->createNode([
'type' => 'dogs',
]);
$this
->drupalGet('admin/structure/layouts');
$this
->clickLink('Add layout');
$page
->fillField('label', 'Slim Pug');
$page
->fillField('id', 'slim_pug');
$page
->selectFieldOption('_entity_type', 'node:dogs');
$page
->pressButton('Save');
$assert_session
->pageTextContains('Edit layout for Slim Pug');
$page
->clickLink('Add section');
$page
->clickLink('One column');
$page
->fillField('layout_settings[label]', 'Slim Pug Section');
$page
->pressButton('Add section');
$page
->clickLink('Add block');
$page
->clickLink('Powered by Drupal');
$page
->fillField('settings[label]', 'This is from the library');
$page
->checkField('settings[label_display]');
$page
->pressButton('Add block');
$page
->clickLink('Add block');
$page
->clickLink('Authored by');
$page
->pressButton('Add block');
$this
->assertSession()
->statusCodeEquals(200);
$page
->pressButton('Save layout');
$this
->drupalGet('admin/structure/types/manage/dogs/display');
$page
->checkField('layout[enabled]');
$page
->checkField('layout[library]');
$page
->pressButton('Save');
$page
->checkField('layout[allow_custom]');
$page
->pressButton('Save');
$page
->clickLink('Manage layout');
$page
->clickLink('Add section');
$page
->clickLink('One column');
$page
->fillField('layout_settings[label]', 'Slim Pug Section');
$page
->pressButton('Add section');
$page
->clickLink('Add block');
$page
->clickLink('Powered by Drupal');
$page
->fillField('settings[label]', 'This is from defaults');
$page
->checkField('settings[label_display]');
$page
->pressButton('Add block');
$page
->pressButton('Save layout');
$this
->drupalGet($node
->toUrl());
$assert_session
->pageTextContains('This is from defaults');
$assert_session
->pageTextNotContains('This is from the library');
$assert_session
->pageTextNotContains('This is from overrides');
$page
->clickLink('Edit');
$page
->selectFieldOption('Layout', 'slim_pug');
$page
->pressButton('Save');
$assert_session
->pageTextNotContains('This is from defaults');
$assert_session
->pageTextContains('This is from the library');
$assert_session
->pageTextNotContains('This is from overrides');
$page
->clickLink('Layout');
$page
->clickLink('Remove Slim Pug Section');
$page
->pressButton('Remove');
$page
->clickLink('Add section');
$page
->clickLink('One column');
$page
->fillField('layout_settings[label]', 'Slim Pug Section');
$page
->pressButton('Add section');
$page
->clickLink('Add block');
$page
->clickLink('Powered by Drupal');
$page
->fillField('settings[label]', 'This is from overrides');
$page
->checkField('settings[label_display]');
$page
->pressButton('Add block');
$page
->pressButton('Save layout');
$assert_session
->pageTextNotContains('This is from defaults');
$assert_session
->pageTextNotContains('This is from the library');
$assert_session
->pageTextContains('This is from overrides');
}
}