function LayoutBuilderTest::testConfigurableLayoutSections

Same name in other branches
  1. 8.9.x core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderTest::testConfigurableLayoutSections()
  2. 10 core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderTest::testConfigurableLayoutSections()
  3. 11.x 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 266

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();
    $this->waitForOffCanvasArea();
    $assert_session->linkExists('One column');
    $this->clickLink('One column');
    $assert_session->assertWaitOnAjaxRequest();
    $this->waitForOffCanvasArea();
    // Add another section.
    $assert_session->linkExists('Add section');
    $this->clickLink('Add section');
    $this->waitForOffCanvasArea();
    $assert_session->waitForElementVisible('named', [
        'link',
        'Layout plugin (with settings)',
    ]);
    $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->assertNoElementAfterWait('css', '#drupal-off-canvas');
    $assert_session->pageTextContains('Default');
    $assert_session->linkExists('Add block');
    // Ensure validation error is displayed for ConfigureSectionForm.
    $assert_session->linkExists('Add section');
    $this->clickLink('Add section');
    $this->waitForOffCanvasArea();
    $assert_session->waitForElementVisible('named', [
        'link',
        'Layout plugin (with settings)',
    ]);
    $this->clickLink('Layout plugin (with settings)');
    $this->assertOffCanvasFormAfterWait('layout_builder_configure_section');
    $page->fillField('layout_settings[setting_1]', 'Test Validation Error Message');
    $page->pressButton('Add section');
    $assert_session->waitForElement('css', '.messages--error');
    $assert_session->pageTextContains('Validation Error Message');
    $page->fillField('layout_settings[setting_1]', 'Setting 1 Value');
    $page->pressButton('Add section');
    $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
    $assert_session->pageTextContains('Setting 1 Value');
    // 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->assertNoElementAfterWait('css', '#drupal-off-canvas');
    $assert_session->pageTextContains('Test setting value');
    $this->assertPageNotReloaded();
}

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