public function LayoutBuilderTest::testExtraFields in Drupal 9
Same name and namespace in other branches
- 8 core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testExtraFields()
- 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 905
Class
- LayoutBuilderTest
- Tests the Layout Builder UI.
Namespace
Drupal\Tests\layout_builder\FunctionalCode
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
->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.');
}