You are here

protected function FacetsTest::clickLinkHelper in Search API Solr 8

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/FacetsTest.php \Drupal\Tests\search_api_solr\Functional\FacetsTest::clickLinkHelper()
  2. 8.2 tests/src/Functional/FacetsTest.php \Drupal\Tests\search_api_solr\Functional\FacetsTest::clickLinkHelper()
  3. 4.x tests/src/Functional/FacetsTest.php \Drupal\Tests\search_api_solr\Functional\FacetsTest::clickLinkHelper()

Provides a helper for ::clickLink() and ::clickLinkPartialName().

Parameters

string|\Drupal\Component\Render\MarkupInterface $label: Text between the anchor tags, uses starts-with().

int $index: Link position counting from zero.

string $pattern: A pattern to use for the XPath.

Return value

bool|string Page contents on success, or FALSE on failure.

1 call to FacetsTest::clickLinkHelper()
FacetsTest::clickLinkPartialName in tests/src/Functional/FacetsTest.php
Follows a link by partial name.

File

tests/src/Functional/FacetsTest.php, line 135

Class

FacetsTest
Tests the facets functionality using the Solr backend.

Namespace

Drupal\Tests\search_api_solr\Functional

Code

protected function clickLinkHelper($label, $index, $pattern) {

  // Cast MarkupInterface objects to string.
  $label = (string) $label;
  $url_before = $this
    ->getUrl();
  $urls = $this
    ->xpath($pattern, array(
    ':label' => $label,
  ));
  if (isset($urls[$index])) {

    /** @var \Behat\Mink\Element\NodeElement $url */
    $url = $urls[$index];
    $url_target = $this
      ->getAbsoluteUrl($url
      ->getAttribute('href'));
    $this
      ->assertTrue(TRUE, new FormattableMarkup('Clicked link %label (@url_target) from @url_before', array(
      '%label' => $label,
      '@url_target' => $url_target,
      '@url_before' => $url_before,
    )));
    return $this
      ->drupalGet($url_target);
  }
  $this
    ->assertTrue(FALSE, new FormattableMarkup('Link %label does not exist on @url_before', array(
    '%label' => $label,
    '@url_before' => $url_before,
  )));
  return FALSE;
}