Skip to content
Snippets Groups Projects
Select Git revision
  • 5c31080600caed818e646d42b0b68b3ac17e34e2
  • 11.x default protected
  • 11.2.x protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

ContextualLinkClickTrait.php

  • Lee Rowlands's avatar
    Issue #2821724 by tedbow, tim.plunkett: Create Javascript Tests for Contextual Links
    Lee Rowlands authored
    5c310806
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ContextualLinkClickTrait.php 1.40 KiB
    <?php
    
    namespace Drupal\Tests\contextual\FunctionalJavascript;
    
    /**
     * Functions for testing contextual links.
     */
    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) {
        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');");
      }
    
    }