653185fe8964a24c9f0c4f40a6b7b88b7be43412
[yaffs-website] / web / core / modules / layout_builder / tests / src / FunctionalJavascript / AjaxBlockTest.php
1 <?php
2
3 namespace Drupal\Tests\layout_builder\FunctionalJavascript;
4
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6
7 /**
8  * Ajax blocks tests.
9  *
10  * @group layout_builder
11  */
12 class AjaxBlockTest extends WebDriverTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = [
18     'block',
19     'node',
20     'datetime',
21     'layout_builder',
22     'user',
23     'layout_builder_test',
24   ];
25
26   /**
27    * {@inheritdoc}
28    */
29   protected function setUp() {
30     parent::setUp();
31     $user = $this->drupalCreateUser([
32       'configure any layout',
33       'administer node display',
34       'administer node fields',
35     ]);
36     $user->save();
37     $this->drupalLogin($user);
38     $this->createContentType(['type' => 'bundle_with_section_field']);
39   }
40
41   /**
42    * Tests configuring a field block for a user field.
43    */
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',
50       'body' => [
51         [
52           'value' => 'The node body',
53         ],
54       ],
55     ]);
56     $node->save();
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';
61
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');
69
70     // Add a new block.
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) {
84         $radio->click();
85         $assert_session->assertWaitOnAjaxRequest();
86       }
87     }
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.');
95   }
96
97 }