3 namespace Drupal\Tests\layout_builder\FunctionalJavascript;
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
10 * @group layout_builder
12 class AjaxBlockTest extends WebDriverTestBase {
17 public static $modules = [
23 'layout_builder_test',
29 protected function setUp() {
31 $user = $this->drupalCreateUser([
32 'configure any layout',
33 'administer node display',
34 'administer node fields',
37 $this->drupalLogin($user);
38 $this->createContentType(['type' => 'bundle_with_section_field']);
42 * Tests configuring a field block for a user field.
44 public function testAddAjaxBlock() {
45 $assert_session = $this->assertSession();
46 $page = $this->getSession()->getPage();
47 // Start by creating a node.
48 $node = $this->createNode([
49 'type' => 'bundle_with_section_field',
52 'value' => 'The node body',
57 $this->drupalGet('node/1');
58 $assert_session->pageTextContains('The node body');
59 $assert_session->pageTextNotContains('Every word is like an unnecessary stain on silence and nothingness.');
60 $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
62 // From the manage display page, go to manage the layout.
63 $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[enabled]' => TRUE], 'Save');
64 $assert_session->linkExists('Manage layout');
65 $this->clickLink('Manage layout');
66 $assert_session->addressEquals("$field_ui_prefix/display-layout/default");
67 // The body field is present.
68 $assert_session->elementExists('css', '.field--name-body');
71 $assert_session->linkExists('Add Block');
72 $this->clickLink('Add Block');
73 $assert_session->assertWaitOnAjaxRequest();
74 $assert_session->linkExists('TestAjax');
75 $this->clickLink('TestAjax');
76 $assert_session->assertWaitOnAjaxRequest();
77 // Find the radio buttons.
78 $name = 'settings[ajax_test]';
79 /** @var \Behat\Mink\Element\NodeElement[] $radios */
80 $radios = $this->cssSelect('input[name="' . $name . '"]');
81 // Click them both a couple of times.
82 foreach ([1, 2] as $rounds) {
83 foreach ($radios as $radio) {
85 $assert_session->assertWaitOnAjaxRequest();
88 // Then add the block.
89 $page->pressButton('Add Block');
90 $assert_session->assertWaitOnAjaxRequest();
91 $block_elements = $this->cssSelect('.block-layout-builder-test-testajax');
92 // Should be exactly one of these in there.
93 $this->assertEquals(1, count($block_elements));
94 $assert_session->pageTextContains('Every word is like an unnecessary stain on silence and nothingness.');