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. 10 core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testExtraFields()
  3. 11.x 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 867

Class

LayoutBuilderTest
Tests the Layout Builder UI.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testExtraFields() {
    $assert_session = $this->assertSession();
    $this->drupalLogin($this->drupalCreateUser([
        'configure any layout',
        'administer node display',
    ]));
    $this->drupalGet('node');
    $assert_session->linkExists('Read more');
    $this->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display/default', [
        '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');
    $page = $this->getSession()
        ->getPage();
    $content_fields_category = $page->find('xpath', '//details/summary[contains(text(),"Content fields")]/parent::details');
    $extra_field = strpos($content_fields_category->getText(), 'Extra label');
    $this->assertTrue($extra_field !== FALSE);
    $this->drupalGet('node');
    $assert_session->linkExists('Read more');
}

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