You are here

protected function LayoutBuilderTest::clickContextualLink in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderTest::clickContextualLink()

@todo Remove this in https://www.drupal.org/project/drupal/issues/2918718.

Overrides ContextualLinkClickTrait::clickContextualLink

1 call to LayoutBuilderTest::clickContextualLink()
LayoutBuilderTest::testLayoutBuilderUi in core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php
Tests the Layout Builder UI.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php, line 401

Class

LayoutBuilderTest
Tests the Layout Builder UI.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

protected function clickContextualLink($selector, $link_locator, $force_visible = TRUE) {

  /** @var \Drupal\FunctionalJavascriptTests\JSWebAssert $assert_session */
  $assert_session = $this
    ->assertSession();

  /** @var \Behat\Mink\Element\DocumentElement $page */
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->waitFor(10, function () use ($page, $selector) {
    return $page
      ->find('css', "{$selector} .contextual-links");
  });
  if (count($page
    ->findAll('css', "{$selector} .contextual-links")) > 1) {
    throw new \Exception('More than one contextual links found by selector');
  }
  if ($force_visible && $page
    ->find('css', "{$selector} .contextual .trigger.visually-hidden")) {
    $this
      ->toggleContextualTriggerVisibility($selector);
  }
  $link = $assert_session
    ->elementExists('css', $selector)
    ->findLink($link_locator);
  $this
    ->assertNotEmpty($link);
  if (!$link
    ->isVisible()) {
    $button = $assert_session
      ->waitForElementVisible('css', "{$selector} .contextual button");
    $this
      ->assertNotEmpty($button);
    $button
      ->press();
    $link = $page
      ->waitFor(10, function () use ($link) {
      return $link
        ->isVisible() ? $link : FALSE;
    });
  }
  $link
    ->click();
  if ($force_visible) {
    $this
      ->toggleContextualTriggerVisibility($selector);
  }
}