You are here

protected function CommentPagerTest::clickLinkWithXPath in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/comment/src/Tests/CommentPagerTest.php \Drupal\comment\Tests\CommentPagerTest::clickLinkWithXPath()

Follows a link found at a give xpath query.

Will click the first link found with the given xpath query by default, or a later one if an index is given.

If the link is discovered and clicked, the test passes. Fail otherwise.

Parameters

string $xpath: Xpath query that targets an anchor tag, or set of anchor tags.

array $arguments: An array of arguments with keys in the form ':name' matching the placeholders in the query. The values may be either strings or numeric values.

int $index: Link position counting from zero.

Return value

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

See also

WebTestBase::clickLink()

1 call to CommentPagerTest::clickLinkWithXPath()
CommentPagerTest::testTwoPagers in core/modules/comment/src/Tests/CommentPagerTest.php
Confirms comment paging works correctly with two pagers.

File

core/modules/comment/src/Tests/CommentPagerTest.php, line 380
Contains \Drupal\comment\Tests\CommentPagerTest.

Class

CommentPagerTest
Tests paging of comments and their settings.

Namespace

Drupal\comment\Tests

Code

protected function clickLinkWithXPath($xpath, $arguments = array(), $index = 0) {
  $url_before = $this
    ->getUrl();
  $urls = $this
    ->xpath($xpath, $arguments);
  if (isset($urls[$index])) {
    $url_target = $this
      ->getAbsoluteUrl($urls[$index]['href']);
    $this
      ->pass(SafeMarkup::format('Clicked link %label (@url_target) from @url_before', array(
      '%label' => $xpath,
      '@url_target' => $url_target,
      '@url_before' => $url_before,
    )), 'Browser');
    return $this
      ->drupalGet($url_target);
  }
  $this
    ->fail(SafeMarkup::format('Link %label does not exist on @url_before', array(
    '%label' => $xpath,
    '@url_before' => $url_before,
  )), 'Browser');
  return FALSE;
}