public function LayoutLibraryTest::testUseLayout in Layout builder library 8
Tests using the layout.
File
- tests/
src/ Functional/ LayoutLibraryTest.php, line 54
Class
- LayoutLibraryTest
- Tests using a layout from the library on an entity.
Namespace
Drupal\Tests\layout_library\FunctionalCode
public function testUseLayout() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$node = $this
->createNode([
'type' => 'dogs',
]);
// Add a layout to the library.
$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');
// Customize the library layout so we can tell it from the others.
$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');
// Add a field block to the layout to ensure that they can be rendered in
// library layouts without causing infinite recursion.
$page
->clickLink('Add block');
$page
->clickLink('Authored by');
$page
->pressButton('Add block');
$this
->assertSession()
->statusCodeEquals(200);
$page
->pressButton('Save layout');
// Enable defaults and overrides for the display.
$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');
// Customize the default layout so we can tell it from the others.
$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');
// Edit the layout to use the layout from the library.
$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');
// Customize the overridden layout so we can tell it from the others.
$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');
}