LayoutBuilderSectionTest.php in Block Style Plugins 8.2
File
tests/src/FunctionalJavascript/LayoutBuilderSectionTest.php
View source
<?php
namespace Drupal\Tests\block_style_plugins\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class LayoutBuilderSectionTest extends WebDriverTestBase {
protected static $modules = [
'node',
'layout_builder',
'block_style_plugins',
'block_style_plugins_test',
];
protected $defaultTheme = 'classy';
protected function setUp() : void {
parent::setUp();
$user = $this
->drupalCreateUser([
'configure any layout',
'administer node display',
'administer node fields',
]);
$user
->save();
$this
->drupalLogin($user);
$this
->createContentType([
'type' => 'bundle_with_section_field',
]);
$this
->drupalPlaceBlock('local_tasks_block');
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[enabled]' => TRUE,
'layout[allow_custom]' => TRUE,
], 'Save');
$node = $this
->createNode([
'type' => 'bundle_with_section_field',
'body' => [
[
'value' => 'The node body',
],
],
]);
$node
->save();
}
public function testLayoutBuilderSectionForm() {
$assert = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$section_css_locator = '.layout--onecol';
$this
->drupalGet('node/1/layout');
$assert
->pageTextContains('The node body');
$this
->clickLink('Configure Section 1');
$assert
->assertWaitOnAjaxRequest();
$assert
->pageTextContains('Section Styles');
$page
->fillField('third_party_settings[block_style_plugins][section_class][test_section_field]', 'section-class');
$page
->pressButton('Update');
$assert
->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert
->assertWaitOnAjaxRequest();
$section_element = $assert
->waitForElementVisible('css', $section_css_locator);
$section_element
->hasClass('section-class');
$this
->clickLink('Configure Section 1');
$assert
->assertWaitOnAjaxRequest();
$page
->fillField('third_party_settings[block_style_plugins][section_class][test_section_field]', 'edited-section-class');
$page
->pressButton('Update');
$assert
->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert
->assertWaitOnAjaxRequest();
$section_element = $assert
->waitForElementVisible('css', $section_css_locator);
$section_element
->hasClass('section-class2');
$page
->pressButton('Save layout');
$section_element = $assert
->waitForElementVisible('css', $section_css_locator);
$section_element
->hasClass('edited-section-class');
$this
->drupalGet('node/1/layout');
$this
->clickLink('Configure Section 1');
$assert
->assertWaitOnAjaxRequest();
$assert
->pageTextContains('Section Styles');
$page
->fillField('third_party_settings[block_style_plugins][section_class][test_section_field]', '');
$page
->pressButton('Update');
$assert
->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert
->assertWaitOnAjaxRequest();
$assert
->responseNotContains('edited-section-class');
$page
->pressButton('Save layout');
$assert
->responseContains('The layout override has been saved');
$assert
->responseNotContains('edited-section-class');
}
}