Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / contextual / tests / src / FunctionalJavascript / ContextualLinkClickTrait.php
1 <?php
2
3 namespace Drupal\Tests\contextual\FunctionalJavascript;
4
5 /**
6  * Functions for testing contextual links.
7  */
8 trait ContextualLinkClickTrait {
9
10   /**
11    * Clicks a contextual link.
12    *
13    * @param string $selector
14    *   The selector for the element that contains the contextual link.
15    * @param string $link_locator
16    *   The link id, title, or text.
17    * @param bool $force_visible
18    *   If true then the button will be forced to visible so it can be clicked.
19    */
20   protected function clickContextualLink($selector, $link_locator, $force_visible = TRUE) {
21     if ($force_visible) {
22       $this->toggleContextualTriggerVisibility($selector);
23     }
24
25     $element = $this->getSession()->getPage()->find('css', $selector);
26     $element->find('css', '.contextual button')->press();
27     $element->findLink($link_locator)->click();
28
29     if ($force_visible) {
30       $this->toggleContextualTriggerVisibility($selector);
31     }
32   }
33
34   /**
35    * Toggles the visibility of a contextual trigger.
36    *
37    * @param string $selector
38    *   The selector for the element that contains the contextual link.
39    */
40   protected function toggleContextualTriggerVisibility($selector) {
41     // Hovering over the element itself with should be enough, but does not
42     // work. Manually remove the visually-hidden class.
43     $this->getSession()->executeScript("jQuery('{$selector} .contextual .trigger').toggleClass('visually-hidden');");
44   }
45
46 }