function 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 90

Class

WebTestBaseTest
@requires extension curl @coversDefaultClass <a href="/api/drupal/core%21modules%21simpletest%21src%21WebTestBase.php/class/WebTestBase/8.9.x" title="Test case for typical Drupal tests." class="local">\Drupal\simpletest\WebTestBase</a> @group simpletest @group WebTestBase

Namespace

Drupal\Tests\simpletest\Unit

Code

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

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