Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / contextual / tests / src / FunctionalJavascript / EditModeTest.php
1 <?php
2
3 namespace Drupal\Tests\contextual\FunctionalJavascript;
4
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
6
7 /**
8  * Tests edit mode.
9  *
10  * @group contextual
11  */
12 class EditModeTest extends JavascriptTestBase {
13
14   /**
15    * CSS selector for Drupal's announce element.
16    */
17   const ANNOUNCE_SELECTOR = '#drupal-live-announce';
18
19   /**
20    * {@inheritdoc}
21    */
22   public static $modules = [
23     'node',
24     'block',
25     'user',
26     'system',
27     'breakpoint',
28     'toolbar',
29     'contextual',
30   ];
31
32   /**
33    * {@inheritdoc}
34    */
35   protected function setUp() {
36     parent::setUp();
37
38     $this->drupalLogin($this->createUser([
39       'administer blocks',
40       'access contextual links',
41       'access toolbar',
42     ]));
43     $this->placeBlock('system_powered_by_block', ['id' => 'powered']);
44   }
45
46   /**
47    * Tests that Drupal.announce messages appear.
48    */
49   public function testAnnounceEditMode() {
50     $web_assert = $this->assertSession();
51     $this->drupalGet('user');
52
53     // After the page loaded we need to additionally wait until the settings
54     // tray Ajax activity is done.
55     $web_assert->assertWaitOnAjaxRequest();
56
57     // Enable edit mode.
58     $this->pressToolbarEditButton();
59     $this->assertAnnounceEditMode();
60     // Disable edit mode.
61     $this->pressToolbarEditButton();
62     $this->assertAnnounceLeaveEditMode();
63     // Enable edit mode again.
64     $this->pressToolbarEditButton();
65     // Finally assert that the 'edit mode enabled' announcement is still correct
66     // after toggling the edit mode at least once.
67     $this->assertAnnounceEditMode();
68   }
69
70   /**
71    * Presses the toolbar edit mode.
72    */
73   protected function pressToolbarEditButton() {
74     $edit_button = $this->getSession()->getPage()->find('css', '#toolbar-bar div.contextual-toolbar-tab button');
75     $edit_button->press();
76   }
77
78   /**
79    * Asserts that the correct message was announced when entering edit mode.
80    */
81   protected function assertAnnounceEditMode() {
82     $web_assert = $this->assertSession();
83     // Wait for contextual trigger button.
84     $web_assert->waitForElementVisible('css', '.contextual trigger');
85     $web_assert->elementContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is constrained to a set of');
86     $web_assert->elementNotContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is no longer constrained by the Contextual module.');
87   }
88
89   /**
90    * Assert that the correct message was announced when leaving edit mode.
91    */
92   protected function assertAnnounceLeaveEditMode() {
93     $web_assert = $this->assertSession();
94     $page = $this->getSession()->getPage();
95     // Wait till all the contextual links are hidden.
96     $page->waitFor(1, function () use ($page, $web_assert) {
97       return empty($page->find('css', '.contextual .trigger.visually-hidden'));
98     });
99     $web_assert->elementContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is no longer constrained by the Contextual module.');
100     $web_assert->elementNotContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is constrained to a set of');
101   }
102
103 }