protected function WebTestBase::clickLink

Follows a link by name.

Will click the first link found with this link text by default, or a later one if an index is given. Match is case sensitive with normalized space. The label is translated label. There is an assert for successful click.

Parameters

$label: Text between the anchor tags.

$index: Link position counting from zero.

Return value

Page on success, or FALSE on failure.

50 calls to WebTestBase::clickLink()
AggregatorTestBase::updateFeedItems in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php
Updates the feed items.
AnalyzeTest::testAnalyzeBasic in drupal/core/modules/views_ui/lib/Drupal/views_ui/Tests/AnalyzeTest.php
Tests that analyze works in general.
BareMinimalUpgradePathTest::finishUpgradeSession in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php
Asserts that the session was kept during update. Also, log out.
BareStandardUpgradePathTest::testBasicStandardUpgrade in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareStandardUpgradePathTest.php
Tests a successful major version release upgrade.
BlockLanguageCacheTest::testBlockLinks in drupal/core/modules/block/lib/Drupal/block/Tests/BlockLanguageCacheTest.php
Creates a block in a language, check blocks page in all languages.

... See full list

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php, line 2064
Definition of Drupal\simpletest\WebTestBase.

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

protected function clickLink($label, $index = 0) {
  $url_before = $this
    ->getUrl();
  $urls = $this
    ->xpath('//a[normalize-space(text())=:label]', array(
    ':label' => $label,
  ));
  if (isset($urls[$index])) {
    $url_target = $this
      ->getAbsoluteUrl($urls[$index]['href']);
  }
  $this
    ->assertTrue(isset($urls[$index]), t('Clicked link %label (@url_target) from @url_before', array(
    '%label' => $label,
    '@url_target' => $url_target,
    '@url_before' => $url_before,
  )), t('Browser'));
  if (isset($url_target)) {
    return $this
      ->drupalGet($url_target);
  }
  return FALSE;
}