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