Chris@0: drupalLogin($this->createUser([ Chris@0: 'administer blocks', Chris@0: 'access contextual links', Chris@0: 'access toolbar', Chris@0: ])); Chris@0: $this->placeBlock('system_powered_by_block', ['id' => 'powered']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that Drupal.announce messages appear. Chris@0: */ Chris@0: public function testAnnounceEditMode() { Chris@0: $web_assert = $this->assertSession(); Chris@0: $this->drupalGet('user'); Chris@0: Chris@0: // After the page loaded we need to additionally wait until the settings Chris@0: // tray Ajax activity is done. Chris@0: $web_assert->assertWaitOnAjaxRequest(); Chris@0: Chris@0: // Enable edit mode. Chris@0: $this->pressToolbarEditButton(); Chris@0: $this->assertAnnounceEditMode(); Chris@0: // Disable edit mode. Chris@0: $this->pressToolbarEditButton(); Chris@0: $this->assertAnnounceLeaveEditMode(); Chris@0: // Enable edit mode again. Chris@0: $this->pressToolbarEditButton(); Chris@0: // Finally assert that the 'edit mode enabled' announcement is still correct Chris@0: // after toggling the edit mode at least once. Chris@0: $this->assertAnnounceEditMode(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Presses the toolbar edit mode. Chris@0: */ Chris@0: protected function pressToolbarEditButton() { Chris@0: $edit_button = $this->getSession()->getPage()->find('css', '#toolbar-bar div.contextual-toolbar-tab button'); Chris@0: $edit_button->press(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Asserts that the correct message was announced when entering edit mode. Chris@0: */ Chris@0: protected function assertAnnounceEditMode() { Chris@0: $web_assert = $this->assertSession(); Chris@0: // Wait for contextual trigger button. Chris@0: $web_assert->waitForElementVisible('css', '.contextual trigger'); Chris@0: $web_assert->elementContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is constrained to a set of'); Chris@0: $web_assert->elementNotContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is no longer constrained by the Contextual module.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Assert that the correct message was announced when leaving edit mode. Chris@0: */ Chris@0: protected function assertAnnounceLeaveEditMode() { Chris@0: $web_assert = $this->assertSession(); Chris@0: $page = $this->getSession()->getPage(); Chris@0: // Wait till all the contextual links are hidden. Chris@0: $page->waitFor(1, function () use ($page, $web_assert) { Chris@0: return empty($page->find('css', '.contextual .trigger.visually-hidden')); Chris@0: }); Chris@0: $web_assert->elementContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is no longer constrained by the Contextual module.'); Chris@0: $web_assert->elementNotContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is constrained to a set of'); Chris@0: } Chris@0: Chris@0: }