annotate core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinkClickTrait.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents c2387f117808
children
rev   line source
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@16 21 $page = $this->getSession()->getPage();
Chris@16 22 $page->waitFor(10, function () use ($page, $selector) {
Chris@16 23 return $page->find('css', "$selector .contextual-links");
Chris@16 24 });
Chris@16 25
Chris@0 26 if ($force_visible) {
Chris@0 27 $this->toggleContextualTriggerVisibility($selector);
Chris@0 28 }
Chris@0 29
Chris@0 30 $element = $this->getSession()->getPage()->find('css', $selector);
Chris@0 31 $element->find('css', '.contextual button')->press();
Chris@0 32 $element->findLink($link_locator)->click();
Chris@0 33
Chris@0 34 if ($force_visible) {
Chris@0 35 $this->toggleContextualTriggerVisibility($selector);
Chris@0 36 }
Chris@0 37 }
Chris@0 38
Chris@0 39 /**
Chris@0 40 * Toggles the visibility of a contextual trigger.
Chris@0 41 *
Chris@0 42 * @param string $selector
Chris@0 43 * The selector for the element that contains the contextual link.
Chris@0 44 */
Chris@0 45 protected function toggleContextualTriggerVisibility($selector) {
Chris@0 46 // Hovering over the element itself with should be enough, but does not
Chris@0 47 // work. Manually remove the visually-hidden class.
Chris@0 48 $this->getSession()->executeScript("jQuery('{$selector} .contextual .trigger').toggleClass('visually-hidden');");
Chris@0 49 }
Chris@0 50
Chris@0 51 }