comparison core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
42 ])); 42 ]));
43 $this->placeBlock('system_powered_by_block', ['id' => 'powered']); 43 $this->placeBlock('system_powered_by_block', ['id' => 'powered']);
44 } 44 }
45 45
46 /** 46 /**
47 * Tests that Drupal.announce messages appear. 47 * Tests enabling and disabling edit mode.
48 */ 48 */
49 public function testAnnounceEditMode() { 49 public function testEditModeEnableDisalbe() {
50 $web_assert = $this->assertSession(); 50 $web_assert = $this->assertSession();
51 $this->drupalGet('user'); 51 $page = $this->getSession()->getPage();
52 // Get the page twice to ensure edit mode remains enabled after a new page
53 // request.
54 for ($page_get_count = 0; $page_get_count < 2; $page_get_count++) {
55 $this->drupalGet('user');
56 $expected_restricted_tab_count = 1 + count($page->findAll('css', '[data-contextual-id]'));
52 57
53 // After the page loaded we need to additionally wait until the settings 58 // After the page loaded we need to additionally wait until the settings
54 // tray Ajax activity is done. 59 // tray Ajax activity is done.
55 $web_assert->assertWaitOnAjaxRequest(); 60 $web_assert->assertWaitOnAjaxRequest();
56 61
57 // Enable edit mode. 62 if ($page_get_count == 0) {
58 $this->pressToolbarEditButton(); 63 $unrestricted_tab_count = $this->getTabbableElementsCount();
59 $this->assertAnnounceEditMode(); 64 $this->assertGreaterThan($expected_restricted_tab_count, $unrestricted_tab_count);
60 // Disable edit mode. 65
61 $this->pressToolbarEditButton(); 66 // Enable edit mode.
62 $this->assertAnnounceLeaveEditMode(); 67 // After the first page load the page will be in edit mode when loaded.
63 // Enable edit mode again. 68 $this->pressToolbarEditButton();
64 $this->pressToolbarEditButton(); 69 }
65 // Finally assert that the 'edit mode enabled' announcement is still correct 70
66 // after toggling the edit mode at least once. 71 $this->assertAnnounceEditMode();
67 $this->assertAnnounceEditMode(); 72 $this->assertSame($expected_restricted_tab_count, $this->getTabbableElementsCount());
73
74 // Disable edit mode.
75 $this->pressToolbarEditButton();
76 $this->assertAnnounceLeaveEditMode();
77 $this->assertSame($unrestricted_tab_count, $this->getTabbableElementsCount());
78 // Enable edit mode again.
79 $this->pressToolbarEditButton();
80 // Finally assert that the 'edit mode enabled' announcement is still
81 // correct after toggling the edit mode at least once.
82 $this->assertAnnounceEditMode();
83 $this->assertSame($expected_restricted_tab_count, $this->getTabbableElementsCount());
84 }
85
68 } 86 }
69 87
70 /** 88 /**
71 * Presses the toolbar edit mode. 89 * Presses the toolbar edit mode.
72 */ 90 */
98 }); 116 });
99 $web_assert->elementContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is no longer constrained by the Contextual module.'); 117 $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'); 118 $web_assert->elementNotContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is constrained to a set of');
101 } 119 }
102 120
121 /**
122 * Gets the number of elements that are tabbable.
123 *
124 * @return int
125 * The number of tabbable elements.
126 */
127 protected function getTabbableElementsCount() {
128 // Mark all tabbable elements.
129 $this->getSession()->executeScript("jQuery(':tabbable').attr('data-marked', '');");
130 // Count all marked elements.
131 $count = count($this->getSession()->getPage()->findAll('css', "[data-marked]"));
132 // Remove set attributes.
133 $this->getSession()->executeScript("jQuery('[data-marked]').removeAttr('data-marked');");
134 return $count;
135 }
136
103 } 137 }