function LayoutBuilderTest::testExtraFields

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

Tests that extra fields work before and after enabling Layout Builder.

File

core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php, line 463

Class

LayoutBuilderTest
Tests the Layout Builder UI.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testExtraFields() : void {
    $assert_session = $this->assertSession();
    $this->drupalLogin($this->drupalCreateUser([
        'configure any layout',
        'administer node display',
    ]));
    $this->drupalGet('node');
    $assert_session->linkExists('Read more');
    $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
    $this->submitForm([
        'layout[enabled]' => TRUE,
    ], 'Save');
    // Extra fields display under "Content fields".
    $this->drupalGet("admin/structure/types/manage/bundle_with_section_field/display/default/layout");
    $this->clickLink('Add block');
    $assert_session->elementTextContains('xpath', '//details/summary[contains(text(),"Content fields")]/parent::details', 'Extra label');
    $this->drupalGet('node');
    $assert_session->linkExists('Read more');
    // Consider an extra field hidden by default. Make sure it's not displayed.
    $this->drupalGet('node/1');
    $assert_session->pageTextNotContains('Extra Field 2 is hidden by default.');
    // View the layout and add the extra field that is not visible by default.
    $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout');
    $assert_session->pageTextNotContains('Extra Field 2');
    $page = $this->getSession()
        ->getPage();
    $page->clickLink('Add block');
    $page->clickLink('Extra Field 2');
    $page->pressButton('Add block');
    $assert_session->pageTextContains('Extra Field 2');
    $page->pressButton('Save layout');
    // Confirm that the newly added extra field is visible.
    $this->drupalGet('node/1');
    $assert_session->pageTextContains('Extra Field 2 is hidden by default.');
}

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