function LinkAccessConstraintValidatorTest::providerValidate

Same name in other branches
  1. 8.9.x core/modules/link/tests/src/Unit/Plugin/Validation/Constraint/LinkAccessConstraintValidatorTest.php \Drupal\Tests\link\Unit\Plugin\Validation\Constraint\LinkAccessConstraintValidatorTest::providerValidate()
  2. 10 core/modules/link/tests/src/Unit/Plugin/Validation/Constraint/LinkAccessConstraintValidatorTest.php \Drupal\Tests\link\Unit\Plugin\Validation\Constraint\LinkAccessConstraintValidatorTest::providerValidate()
  3. 11.x core/modules/link/tests/src/Unit/Plugin/Validation/Constraint/LinkAccessConstraintValidatorTest.php \Drupal\Tests\link\Unit\Plugin\Validation\Constraint\LinkAccessConstraintValidatorTest::providerValidate()

Data provider for LinkAccessConstraintValidator::validate().

Return value

array An array of tests, matching the parameter inputs for testValidate.

See also

\Drupal\Tests\link\LinkAccessConstraintValidatorTest::validate()

File

core/modules/link/tests/src/Unit/Plugin/Validation/Constraint/LinkAccessConstraintValidatorTest.php, line 58

Class

LinkAccessConstraintValidatorTest
Tests the LinkAccessConstraintValidator validator.

Namespace

Drupal\Tests\link\Unit\Plugin\Validation\Constraint

Code

public function providerValidate() {
    $data = [];
    $cases = [
        [
            'may_link_any_page' => TRUE,
            'url_access' => TRUE,
            'valid' => TRUE,
        ],
        [
            'may_link_any_page' => TRUE,
            'url_access' => FALSE,
            'valid' => TRUE,
        ],
        [
            'may_link_any_page' => FALSE,
            'url_access' => TRUE,
            'valid' => TRUE,
        ],
        [
            'may_link_any_page' => FALSE,
            'url_access' => FALSE,
            'valid' => FALSE,
        ],
    ];
    foreach ($cases as $case) {
        // Mock a Url object that returns a boolean indicating user access.
        $url = $this->getMockBuilder('Drupal\\Core\\Url')
            ->disableOriginalConstructor()
            ->getMock();
        $url->expects($this->once())
            ->method('access')
            ->willReturn($case['url_access']);
        // Mock a link object that returns the URL object.
        $link = $this->createMock('Drupal\\link\\LinkItemInterface');
        $link->expects($this->any())
            ->method('getUrl')
            ->willReturn($url);
        // Mock a user object that returns a boolean indicating user access to all
        // links.
        $user = $this->createMock('Drupal\\Core\\Session\\AccountProxyInterface');
        $user->expects($this->any())
            ->method('hasPermission')
            ->with($this->equalTo('link to any page'))
            ->willReturn($case['may_link_any_page']);
        $data[] = [
            $link,
            $user,
            $case['valid'],
        ];
    }
    return $data;
}

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