trait ContextualLinkClickTrait
Same name in other branches
- 9 core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinkClickTrait.php \Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait
- 8.9.x core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinkClickTrait.php \Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait
- 10 core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinkClickTrait.php \Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait
Functions for testing contextual links.
Hierarchy
- trait \Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait
11 files declare their use of ContextualLinkClickTrait
- BlockFormMessagesTest.php in core/
modules/ layout_builder/ tests/ src/ FunctionalJavascript/ BlockFormMessagesTest.php - ContentPreviewToggleTest.php in core/
modules/ layout_builder/ tests/ src/ FunctionalJavascript/ ContentPreviewToggleTest.php - ContextualLinksTest.php in core/
modules/ node/ tests/ src/ FunctionalJavascript/ ContextualLinksTest.php - InlineBlockTestBase.php in core/
modules/ layout_builder/ tests/ src/ FunctionalJavascript/ InlineBlockTestBase.php - LayoutBuilderDisableInteractionsTest.php in core/
modules/ layout_builder/ tests/ src/ FunctionalJavascript/ LayoutBuilderDisableInteractionsTest.php
File
-
core/
modules/ contextual/ tests/ src/ FunctionalJavascript/ ContextualLinkClickTrait.php, line 10
Namespace
Drupal\Tests\contextual\FunctionalJavascriptView source
trait ContextualLinkClickTrait {
/**
* Clicks a contextual link.
*
* @param string $selector
* The selector for the element that contains the contextual link.
* @param string $link_locator
* The link id, title, or text.
* @param bool $force_visible
* If true then the button will be forced to visible so it can be clicked.
*/
protected function clickContextualLink($selector, $link_locator, $force_visible = TRUE) {
$page = $this->getSession()
->getPage();
$page->waitFor(10, function () use ($page, $selector) {
return $page->find('css', "{$selector} .contextual-links");
});
if ($force_visible) {
$this->toggleContextualTriggerVisibility($selector);
}
$element = $this->getSession()
->getPage()
->find('css', $selector);
$element->find('css', '.contextual button')
->press();
$element->findLink($link_locator)
->click();
if ($force_visible) {
$this->toggleContextualTriggerVisibility($selector);
}
}
/**
* Toggles the visibility of a contextual trigger.
*
* @param string $selector
* The selector for the element that contains the contextual link.
*/
protected function toggleContextualTriggerVisibility($selector) {
// Hovering over the element itself with should be enough, but does not
// work. Manually remove the visually-hidden class.
$this->getSession()
->executeScript("jQuery('{$selector} .contextual .trigger').toggleClass('visually-hidden');");
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
ContextualLinkClickTrait::clickContextualLink | protected | function | Clicks a contextual link. | 1 |
ContextualLinkClickTrait::toggleContextualTriggerVisibility | protected | function | Toggles the visibility of a contextual trigger. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.