function LayoutDisplayTest::testMultipleViewModes

Same name in other branches
  1. 9 core/modules/layout_builder/tests/src/Functional/LayoutDisplayTest.php \Drupal\Tests\layout_builder\Functional\LayoutDisplayTest::testMultipleViewModes()
  2. 8.9.x core/modules/layout_builder/tests/src/Functional/LayoutDisplayTest.php \Drupal\Tests\layout_builder\Functional\LayoutDisplayTest::testMultipleViewModes()
  3. 10 core/modules/layout_builder/tests/src/Functional/LayoutDisplayTest.php \Drupal\Tests\layout_builder\Functional\LayoutDisplayTest::testMultipleViewModes()

Tests the interaction between multiple view modes.

File

core/modules/layout_builder/tests/src/Functional/LayoutDisplayTest.php, line 51

Class

LayoutDisplayTest
Tests functionality of the entity view display with regard to Layout Builder.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testMultipleViewModes() : void {
    $assert_session = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field/display';
    // Enable Layout Builder for the default view modes, and overrides.
    $display = LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default');
    $this->enableLayoutBuilder($display);
    $this->drupalGet('node/1');
    $assert_session->pageTextNotContains('Powered by Drupal');
    $this->drupalGet('node/1/layout');
    $assert_session->linkExists('Add block');
    $this->clickLink('Add block');
    $assert_session->linkExists('Powered by Drupal');
    $this->clickLink('Powered by Drupal');
    $page->pressButton('Add block');
    $page->pressButton('Save');
    $assert_session->pageTextContains('Powered by Drupal');
    // Add a new view mode.
    $this->drupalGet('admin/structure/display-modes/view/add/node');
    $page->fillField('label', 'New');
    $page->fillField('id', 'new');
    $page->pressButton('Save');
    // Enable the new view mode.
    $this->drupalGet("{$field_ui_prefix}/default");
    $page->checkField('display_modes_custom[new]');
    $page->pressButton('Save');
    // Enable and disable Layout Builder for the new view mode.
    $this->enableLayoutBuilderFromUi('bundle_with_section_field', 'new', FALSE);
    $this->disableLayoutBuilderFromUi('bundle_with_section_field', 'new');
    // The node using the default view mode still contains its overrides.
    $this->drupalGet('node/1');
    $assert_session->pageTextContains('Powered by Drupal');
}

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