You are here

protected function WebTestBase::clickLinkHelper in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/simpletest/src/WebTestBase.php \Drupal\simpletest\WebTestBase::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.

2 calls to WebTestBase::clickLinkHelper()
WebTestBase::clickLink in core/modules/simpletest/src/WebTestBase.php
Follows a link by complete name.
WebTestBase::clickLinkPartialName in core/modules/simpletest/src/WebTestBase.php
Follows a link by partial name.

File

core/modules/simpletest/src/WebTestBase.php, line 2476
Contains \Drupal\simpletest\WebTestBase.

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

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])) {
    $url_target = $this
      ->getAbsoluteUrl($urls[$index]['href']);
    $this
      ->pass(SafeMarkup::format('Clicked link %label (@url_target) from @url_before', array(
      '%label' => $label,
      '@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' => $label,
    '@url_before' => $url_before,
  )), 'Browser');
  return FALSE;
}