You are here

public function LayoutBuilderTest::testOverridesFormAlter in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testOverridesFormAlter()

Tests a custom alter of the overrides form.

File

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

Class

LayoutBuilderTest
Tests the Layout Builder UI.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testOverridesFormAlter() {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'configure any layout',
    'administer node display',
    'administer nodes',
  ]));
  $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';

  // Enable overrides.
  $this
    ->drupalGet("{$field_ui_prefix}/display/default");
  $this
    ->submitForm([
    'layout[enabled]' => TRUE,
  ], 'Save');
  $this
    ->drupalGet("{$field_ui_prefix}/display/default");
  $this
    ->submitForm([
    'layout[allow_custom]' => TRUE,
  ], 'Save');
  $this
    ->drupalGet('node/1');

  // The status checkbox should be checked by default.
  $page
    ->clickLink('Layout');
  $assert_session
    ->checkboxChecked('status[value]');
  $page
    ->pressButton('Save layout');
  $assert_session
    ->pageTextContains('The layout override has been saved.');

  // Unchecking the status checkbox will unpublish the entity.
  $page
    ->clickLink('Layout');
  $page
    ->uncheckField('status[value]');
  $page
    ->pressButton('Save layout');
  $assert_session
    ->statusCodeEquals(403);
  $assert_session
    ->pageTextContains('The layout override has been saved.');
}