Pull merge.
[yaffs-website] / web / core / modules / layout_builder / tests / src / FunctionalJavascript / LayoutBuilderUiTest.php
1 <?php
2
3 namespace Drupal\Tests\layout_builder\FunctionalJavascript;
4
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6
7 /**
8  * Tests the Layout Builder UI.
9  *
10  * @group layout_builder
11  */
12 class LayoutBuilderUiTest extends WebDriverTestBase {
13
14   /**
15    * Path prefix for the field UI for the test bundle.
16    *
17    * @var string
18    */
19   const FIELD_UI_PREFIX = 'admin/structure/types/manage/bundle_with_section_field';
20
21   public static $modules = [
22     'layout_builder',
23     'block',
24     'node',
25   ];
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function setUp() {
31     parent::setUp();
32
33     // @todo The Layout Builder UI relies on local tasks; fix in
34     //   https://www.drupal.org/project/drupal/issues/2917777.
35     $this->drupalPlaceBlock('local_tasks_block');
36
37     $this->createContentType(['type' => 'bundle_with_section_field']);
38
39     $this->drupalLogin($this->drupalCreateUser([
40       'configure any layout',
41       'administer node display',
42       'administer node fields',
43     ]));
44   }
45
46   /**
47    * Tests the message indicating unsaved changes.
48    */
49   public function testUnsavedChangesMessage() {
50     $assert_session = $this->assertSession();
51     $page = $this->getSession()->getPage();
52
53     // Enable layout builder.
54     $this->drupalPostForm(
55       static::FIELD_UI_PREFIX . '/display/default',
56       ['layout[enabled]' => TRUE],
57       'Save'
58     );
59
60     // Make and then cancel changes.
61     $this->assertModifiedLayout(static::FIELD_UI_PREFIX . '/display-layout/default');
62     $page->clickLink('Cancel Layout');
63     $assert_session->pageTextNotContains('You have unsaved changes.');
64
65     // Make and then save changes.
66     $this->assertModifiedLayout(static::FIELD_UI_PREFIX . '/display-layout/default');
67     $page->clickLink('Save Layout');
68     $assert_session->pageTextNotContains('You have unsaved changes.');
69   }
70
71   /**
72    * Asserts that modifying a layout works as expected.
73    *
74    * @param string $path
75    *   The path to a Layout Builder UI page.
76    */
77   protected function assertModifiedLayout($path) {
78     $assert_session = $this->assertSession();
79     $page = $this->getSession()->getPage();
80
81     $this->drupalGet($path);
82     $page->clickLink('Add Section');
83     $assert_session->assertWaitOnAjaxRequest();
84     $assert_session->pageTextNotContains('You have unsaved changes.');
85     $page->clickLink('One column');
86     $assert_session->assertWaitOnAjaxRequest();
87     $assert_session->pageTextContainsOnce('You have unsaved changes.');
88
89     // Reload the page.
90     $this->drupalGet($path);
91     $assert_session->pageTextContainsOnce('You have unsaved changes.');
92   }
93
94 }