function CommentPagerTest::clickLinkWithXPath

Same name in other branches
  1. 9 core/modules/comment/tests/src/Functional/CommentPagerTest.php \Drupal\Tests\comment\Functional\CommentPagerTest::clickLinkWithXPath()
  2. 10 core/modules/comment/tests/src/Functional/CommentPagerTest.php \Drupal\Tests\comment\Functional\CommentPagerTest::clickLinkWithXPath()
  3. 11.x core/modules/comment/tests/src/Functional/CommentPagerTest.php \Drupal\Tests\comment\Functional\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/tests/src/Functional/CommentPagerTest.php
Confirms comment paging works correctly with two pagers.

File

core/modules/comment/tests/src/Functional/CommentPagerTest.php, line 427

Class

CommentPagerTest
Tests paging of comments and their settings.

Namespace

Drupal\Tests\comment\Functional

Code

protected function clickLinkWithXPath($xpath, $arguments = [], $index = 0) {
    $url_before = $this->getUrl();
    $urls = $this->xpath($xpath, $arguments);
    if (isset($urls[$index])) {
        $url_target = $this->getAbsoluteUrl($urls[$index]->getAttribute('href'));
        return $this->drupalGet($url_target);
    }
    $this->fail(new FormattableMarkup('Link %label does not exist on @url_before', [
        '%label' => $xpath,
        '@url_before' => $url_before,
    ]), 'Browser');
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.