You are here

public function LayoutBuilderTest::testConfigurableLayoutSections in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderTest::testConfigurableLayoutSections()

Tests configurable layouts.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php, line 263

Class

LayoutBuilderTest
Tests the Layout Builder UI.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testConfigurableLayoutSections() {
  $layout_url = 'node/1/layout';
  \Drupal::entityTypeManager()
    ->getStorage('entity_view_display')
    ->create([
    'targetEntityType' => 'node',
    'bundle' => 'bundle_with_section_field',
    'mode' => 'full',
  ])
    ->enable()
    ->setThirdPartySetting('layout_builder', 'enabled', TRUE)
    ->setThirdPartySetting('layout_builder', 'allow_custom', TRUE)
    ->save();
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->drupalGet($layout_url);
  $this
    ->markCurrentPage();
  $assert_session
    ->linkExists('Add section');
  $this
    ->clickLink('Add section');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->elementExists('css', '#drupal-off-canvas');
  $assert_session
    ->linkExists('One column');
  $this
    ->clickLink('One column');
  $assert_session
    ->assertWaitOnAjaxRequest();

  // Add another section.
  $assert_session
    ->linkExists('Add section');
  $this
    ->clickLink('Add section');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->elementExists('css', '#drupal-off-canvas');
  $assert_session
    ->linkExists('Layout plugin (with settings)');
  $this
    ->clickLink('Layout plugin (with settings)');
  $this
    ->assertOffCanvasFormAfterWait('layout_builder_configure_section');
  $assert_session
    ->fieldExists('layout_settings[setting_1]');
  $page
    ->pressButton('Add section');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->assertNoElementAfterWait('css', '#drupal-off-canvas');
  $assert_session
    ->pageTextContains('Default');
  $assert_session
    ->linkExists('Add block');

  // Configure the existing section.
  $assert_session
    ->linkExists('Configure Section 1');
  $this
    ->clickLink('Configure Section 1');
  $this
    ->assertOffCanvasFormAfterWait('layout_builder_configure_section');
  $page
    ->fillField('layout_settings[setting_1]', 'Test setting value');
  $page
    ->pressButton('Update');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->assertNoElementAfterWait('css', '#drupal-off-canvas');
  $assert_session
    ->pageTextContains('Test setting value');
  $this
    ->assertPageNotReloaded();
}