function LayoutBuilderOptInTest::testDefaultValues

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

Tests the expected default values for enabling Layout Builder.

File

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

Class

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

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testDefaultValues() : void {
    $assert_session = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    // Both the content type created before and after Layout Builder was
    // installed is still using the Field UI.
    $this->drupalGet('admin/structure/types/manage/before/display/default');
    $assert_session->checkboxNotChecked('layout[enabled]');
    $field_ui_prefix = 'admin/structure/types/manage/after/display/default';
    $this->drupalGet($field_ui_prefix);
    $assert_session->checkboxNotChecked('layout[enabled]');
    $page->checkField('layout[enabled]');
    $page->pressButton('Save');
    $layout_builder_ui = $this->getPathForFieldBlock('node', 'after', 'default', 'body');
    $assert_session->linkExists('Manage layout');
    $this->clickLink('Manage layout');
    // Ensure the body appears once and only once.
    $assert_session->elementsCount('css', '.field--name-body', 1);
    // Change the body formatter to Trimmed.
    $this->drupalGet($layout_builder_ui);
    $assert_session->fieldValueEquals('settings[formatter][type]', 'text_default');
    $page->selectFieldOption('settings[formatter][type]', 'text_trimmed');
    $assert_session->assertWaitOnAjaxRequest();
    $page->pressButton('Update');
    $page->pressButton('Save layout');
    $this->drupalGet($layout_builder_ui);
    $assert_session->fieldValueEquals('settings[formatter][type]', 'text_trimmed');
    // Disable Layout Builder.
    $this->drupalGet($field_ui_prefix);
    $this->submitForm([
        'layout[enabled]' => FALSE,
    ], 'Save');
    $page->pressButton('Confirm');
    // The Layout Builder UI is no longer accessible.
    $this->drupalGet($layout_builder_ui);
    $assert_session->pageTextContains('You are not authorized to access this page.');
    // The original body formatter is reflected in Field UI.
    $this->drupalGet($field_ui_prefix);
    $assert_session->fieldValueEquals('fields[body][type]', 'text_default');
    // Change the body formatter to Summary.
    $page->selectFieldOption('fields[body][type]', 'text_summary_or_trimmed');
    $assert_session->assertWaitOnAjaxRequest();
    $page->pressButton('Save');
    $assert_session->fieldValueEquals('fields[body][type]', 'text_summary_or_trimmed');
    // Reactivate Layout Builder.
    $this->drupalGet($field_ui_prefix);
    $this->submitForm([
        'layout[enabled]' => TRUE,
    ], 'Save');
    $assert_session->linkExists('Manage layout');
    $this->clickLink('Manage layout');
    // Ensure the body appears once and only once.
    $assert_session->elementsCount('css', '.field--name-body', 1);
    // The changed body formatter is reflected in Layout Builder UI.
    $this->drupalGet($this->getPathForFieldBlock('node', 'after', 'default', 'body'));
    $assert_session->fieldValueEquals('settings[formatter][type]', 'text_summary_or_trimmed');
}

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