function LayoutBuilderViewModeTest::testNonDefaultViewMode

Same name in other branches
  1. 11.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderViewModeTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderViewModeTest::testNonDefaultViewMode()

Tests that a non-default view mode works as expected.

File

core/modules/layout_builder/tests/src/Functional/LayoutBuilderViewModeTest.php, line 23

Class

LayoutBuilderViewModeTest
Tests the Layout Builder UI with view modes.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testNonDefaultViewMode() : void {
    $assert_session = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    $this->drupalLogin($this->drupalCreateUser([
        'configure any layout',
        'administer node display',
    ]));
    $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
    // Allow overrides for the layout.
    $display = LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default');
    $this->enableLayoutBuilder($display);
    $this->drupalGet("{$field_ui_prefix}/display/default");
    $this->clickLink('Manage layout');
    // Confirm the body field only is shown once.
    $assert_session->elementsCount('css', '.field--name-body', 1);
    $page->pressButton('Discard changes');
    $page->pressButton('Confirm');
    $this->clickLink('Teaser');
    // Enabling Layout Builder for the default mode does not affect the teaser.
    $assert_session->addressEquals("{$field_ui_prefix}/display/teaser");
    $assert_session->elementNotExists('css', '#layout-builder__layout');
    $assert_session->checkboxNotChecked('layout[enabled]');
    $this->enableLayoutBuilderFromUi('bundle_with_section_field', 'teaser', FALSE);
    $assert_session->linkExists('Manage layout');
    $page->clickLink('Manage layout');
    // Confirm the body field only is shown once.
    $assert_session->elementsCount('css', '.field--name-body', 1);
    // Enable a disabled view mode.
    $page->pressButton('Discard changes');
    $page->pressButton('Confirm');
    $assert_session->addressEquals("{$field_ui_prefix}/display/teaser");
    $page->clickLink('Default');
    $assert_session->addressEquals("{$field_ui_prefix}/display");
    $assert_session->linkNotExists('Full content');
    $page->checkField('display_modes_custom[full]');
    $page->pressButton('Save');
    // Enable Layout Builder for the full view mode.
    $display = LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.full');
    $this->enableLayoutBuilder($display);
    $this->drupalGet("{$field_ui_prefix}/display/full");
    $assert_session->linkExists('Manage layout');
    $page->clickLink('Manage layout');
    // Confirm the body field only is shown once.
    $assert_session->elementsCount('css', '.field--name-body', 1);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.