You are here

public function WebTestBaseTest::providerTestClickLink in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/tests/src/Unit/WebTestBaseTest.php \Drupal\Tests\simpletest\Unit\WebTestBaseTest::providerTestClickLink()

Data provider for testClickLink().

In the test method, we mock drupalGet() to return a known string: 'This Text Returned By drupalGet()'. Since clickLink() can only return either the value of drupalGet() or FALSE, our expected return value is the same as this mocked return value when we expect a link to be found.

Return value

array Array of arrays of test data. Test data is structured as follows:

  • Expected return value of clickLink().
  • Parameter $label to clickLink().
  • Parameter $index to clickLink().
  • Test data to be returned by mocked xpath(). Return an empty array here to mock no link found on the page.

See also

https://www.drupal.org/node/1452896

File

core/modules/simpletest/tests/src/Unit/WebTestBaseTest.php, line 93
Contains \Drupal\Tests\simpletest\Unit\WebTestBaseTest.

Class

WebTestBaseTest
@coversDefaultClass \Drupal\simpletest\WebTestBase @group simpletest

Namespace

Drupal\Tests\simpletest\Unit

Code

public function providerTestClickLink() {
  return array(
    // Test for a non-existent label.
    array(
      FALSE,
      'does_not_exist',
      0,
      array(),
    ),
    // Test for an existing label.
    array(
      'This Text Returned By drupalGet()',
      'exists',
      0,
      array(
        0 => array(
          'href' => 'this_is_a_url',
        ),
      ),
    ),
    // Test for an existing label that isn't the first one.
    array(
      'This Text Returned By drupalGet()',
      'exists',
      1,
      array(
        0 => array(
          'href' => 'this_is_a_url',
        ),
        1 => array(
          'href' => 'this_is_another_url',
        ),
      ),
    ),
  );
}