function EditModeTest::testEditModeEnableDisable
Same name in other branches
- 9 core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php \Drupal\Tests\contextual\FunctionalJavascript\EditModeTest::testEditModeEnableDisable()
- 8.9.x core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php \Drupal\Tests\contextual\FunctionalJavascript\EditModeTest::testEditModeEnableDisable()
- 11.x core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php \Drupal\Tests\contextual\FunctionalJavascript\EditModeTest::testEditModeEnableDisable()
Tests enabling and disabling edit mode.
File
-
core/
modules/ contextual/ tests/ src/ FunctionalJavascript/ EditModeTest.php, line 70
Class
- EditModeTest
- Tests edit mode.
Namespace
Drupal\Tests\contextual\FunctionalJavascriptCode
public function testEditModeEnableDisable() : void {
$web_assert = $this->assertSession();
$page = $this->getSession()
->getPage();
// Get the page twice to ensure edit mode remains enabled after a new page
// request.
for ($page_get_count = 0; $page_get_count < 2; $page_get_count++) {
$this->drupalGet('user');
$expected_restricted_tab_count = 1 + count($page->findAll('css', '[data-contextual-id]'));
// After the page loaded we need to additionally wait until the settings
// tray Ajax activity is done.
if ($page_get_count === 0) {
$web_assert->assertWaitOnAjaxRequest();
}
if ($page_get_count == 0) {
$unrestricted_tab_count = $this->getTabbableElementsCount();
$this->assertGreaterThan($expected_restricted_tab_count, $unrestricted_tab_count);
// Enable edit mode.
// After the first page load the page will be in edit mode when loaded.
$this->pressToolbarEditButton();
}
$this->assertAnnounceEditMode();
$this->assertSame($expected_restricted_tab_count, $this->getTabbableElementsCount());
// Disable edit mode.
$this->pressToolbarEditButton();
$this->assertAnnounceLeaveEditMode();
$this->assertSame($unrestricted_tab_count, $this->getTabbableElementsCount());
// Enable edit mode again.
$this->pressToolbarEditButton();
// Finally assert that the 'edit mode enabled' announcement is still
// correct after toggling the edit mode at least once.
$this->assertAnnounceEditMode();
$this->assertSame($expected_restricted_tab_count, $this->getTabbableElementsCount());
// Test while Edit Mode is enabled it doesn't interfere with pages with
// no contextual links.
$this->drupalGet('admin/structure/block');
$web_assert->elementContains('css', 'h1.page-title', 'Block layout');
$this->assertEquals(0, count($page->findAll('css', '[data-contextual-id]')));
$this->assertGreaterThan(0, $this->getTabbableElementsCount());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.