public function LayoutBuilderOptInTest::testDefaultValues in Drupal 9
Same name and namespace in other branches
- 8 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 92
Class
- LayoutBuilderOptInTest
- Tests the ability for opting in and out of Layout Builder.
Namespace
Drupal\Tests\layout_builder\FunctionalJavascriptCode
public function testDefaultValues() {
$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');
}