You are here

function DrupalTestCase::clickLink in SimpleTest 5

Same name and namespace in other branches
  1. 6 drupal_test_case.php \DrupalTestCase::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 insensitive with normalised space. Does make assertations if the click was sucessful or not and it does translate label. WARNING: Assertation fails on empty ("") output from the clicked link

Parameters

string $label Text between the anchor tags.: @param integer $index Link position counting from zero. @param boolean $reporting Assertions or not @return boolean/string Page on success.

@access public

1 call to DrupalTestCase::clickLink()
UserRegistrationTest::testUserRegistration in tests/user_registration_test.test

File

./drupal_test_case.php, line 129

Class

DrupalTestCase
Test case for typical Drupal tests. Extends WebTestCase for comfortable browser usage but also implements all UnitTestCase methods, I wish WebTestCase would do this.

Code

function clickLink($label, $index = 0) {
  $url_before = $this
    ->getUrl();
  $urls = $this->_browser->_page
    ->getUrlsByLabel($label);
  $url_target = 'unknown url';
  if (isset($urls[$index])) {
    $url_target = $urls[$index]
      ->asString();
  }
  $ret = parent::clickLink(t($label), $index);
  $this
    ->assertTrue($ret, str_replace('%', '%%', ' [browser] clicked link ' . t($label) . " ({$url_target}) from {$url_before}"));
  $this->_content = $this->_browser
    ->getContent();
  return $ret;
}