92b48a7762ae5d9de2c68133e86b6902c0e04442
[yaffs-website] / FunctionalJavascript / ItemLayoutFieldBlockTest.php
1 <?php
2
3 namespace Drupal\Tests\layout_builder\FunctionalJavascript;
4
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6
7 /**
8  * Field blocks tests for the override layout.
9  *
10  * @group layout_builder
11  */
12 class ItemLayoutFieldBlockTest extends WebDriverTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected static $modules = [
18     'node',
19     'layout_builder',
20   ];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     parent::setUp();
27
28     $this->drupalLogin($this->drupalCreateUser([
29       'configure any layout',
30       'administer node display',
31       'administer node fields',
32     ]));
33
34     // We need more then one content type for this test.
35     $this->createContentType(['type' => 'bundle_with_layout_overrides']);
36     $this->createContentType(['type' => 'filler_bundle']);
37   }
38
39   /**
40    * Tests configuring a field block for a user field.
41    */
42   public function testAddAjaxBlock() {
43     $assert_session = $this->assertSession();
44     $page = $this->getSession()->getPage();
45
46     // Allow overrides for the layout.
47     $this->drupalGet('admin/structure/types/manage/bundle_with_layout_overrides/display/default');
48     $page->checkField('layout[enabled]');
49     $page->checkField('layout[allow_custom]');
50     $page->pressButton('Save');
51
52     // Start by creating a node of type with layout overrides.
53     $node = $this->createNode([
54       'type' => 'bundle_with_layout_overrides',
55       'body' => [
56         [
57           'value' => 'The node body',
58         ],
59       ],
60     ]);
61     $node->save();
62
63     // Open single item layout page.
64     $this->drupalGet('node/1/layout');
65
66     // Add a new block.
67     $this->clickLink('Add Block');
68     $assert_session->assertWaitOnAjaxRequest();
69
70     // Validate that only field blocks for layouted bundle are present.
71     $valid_links = $page->findAll('css', 'a[href$="field_block%3Anode%3Abundle_with_layout_overrides%3Abody"]');
72     $this->assertCount(1, $valid_links);
73     $invalid_links = $page->findAll('css', 'a[href$="field_block%3Anode%3Afiller_bundle%3Abody"]');
74     $this->assertCount(0, $invalid_links);
75   }
76
77 }