AjaxBlockTest.php in Drupal 9
File
core/modules/layout_builder/tests/src/FunctionalJavascript/AjaxBlockTest.php
View source
<?php
namespace Drupal\Tests\layout_builder\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class AjaxBlockTest extends WebDriverTestBase {
protected static $modules = [
'block',
'node',
'datetime',
'layout_builder',
'user',
'layout_builder_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',
]);
}
public function testAddAjaxBlock() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$node = $this
->createNode([
'type' => 'bundle_with_section_field',
'body' => [
[
'value' => 'The node body',
],
],
]);
$node
->save();
$this
->drupalGet('node/1');
$assert_session
->pageTextContains('The node body');
$assert_session
->pageTextNotContains('Every word is like an unnecessary stain on silence and nothingness.');
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this
->drupalGet("{$field_ui_prefix}/display/default");
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$assert_session
->linkExists('Manage layout');
$this
->clickLink('Manage layout');
$assert_session
->addressEquals("{$field_ui_prefix}/display/default/layout");
$assert_session
->elementExists('css', '.field--name-body');
$assert_session
->linkExists('Add block');
$this
->clickLink('Add block');
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->linkExists('TestAjax');
$this
->clickLink('TestAjax');
$assert_session
->assertWaitOnAjaxRequest();
$name = 'settings[ajax_test]';
$radios = $this
->assertSession()
->fieldExists($name);
foreach ([
1,
2,
] as $rounds) {
foreach ($radios as $radio) {
$radio
->click();
$assert_session
->assertWaitOnAjaxRequest();
}
}
$assert_session
->waitForElementVisible('named', [
'button',
'Add block',
])
->press();
$assert_session
->assertWaitOnAjaxRequest();
$block_elements = $this
->cssSelect('.block-layout-builder-test-testajax');
$this
->assertCount(1, $block_elements);
$assert_session
->pageTextContains('Every word is like an unnecessary stain on silence and nothingness.');
}
}