You are here

public function LayoutBuilderOptInTest::testCheckboxLogic in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderOptInTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderOptInTest::testCheckboxLogic()
  2. 10 core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderOptInTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderOptInTest::testCheckboxLogic()

Tests the interaction between the two layout checkboxes.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderOptInTest.php, line 49

Class

LayoutBuilderOptInTest
Tests the ability for opting in and out of Layout Builder.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testCheckboxLogic() {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->drupalGet('admin/structure/types/manage/before/display/default');

  // Both fields are unchecked and allow_custom is disabled and hidden.
  $assert_session
    ->checkboxNotChecked('layout[enabled]');
  $assert_session
    ->checkboxNotChecked('layout[allow_custom]');
  $assert_session
    ->fieldDisabled('layout[allow_custom]');
  $this
    ->assertFalse($page
    ->findField('layout[allow_custom]')
    ->isVisible());

  // Checking is_enable will show allow_custom.
  $page
    ->checkField('layout[enabled]');
  $assert_session
    ->checkboxNotChecked('layout[allow_custom]');
  $this
    ->assertTrue($page
    ->findField('layout[allow_custom]')
    ->isVisible());
  $page
    ->pressButton('Save');
  $assert_session
    ->checkboxChecked('layout[enabled]');
  $assert_session
    ->checkboxNotChecked('layout[allow_custom]');

  // Check and submit allow_custom.
  $page
    ->checkField('layout[allow_custom]');
  $page
    ->pressButton('Save');
  $assert_session
    ->checkboxChecked('layout[enabled]');
  $assert_session
    ->checkboxChecked('layout[allow_custom]');

  // Reset the checkboxes.
  $page
    ->uncheckField('layout[enabled]');
  $page
    ->pressButton('Save');
  $page
    ->pressButton('Confirm');
  $assert_session
    ->checkboxNotChecked('layout[enabled]');
  $assert_session
    ->checkboxNotChecked('layout[allow_custom]');

  // Check both at the same time.
  $page
    ->checkField('layout[enabled]');
  $page
    ->checkField('layout[allow_custom]');
  $page
    ->pressButton('Save');
  $assert_session
    ->checkboxChecked('layout[enabled]');
  $assert_session
    ->checkboxChecked('layout[allow_custom]');
}