public function LinkAccessConstraintValidatorTest::providerValidate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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 63 - Contains \Drupal\Tests\link\Unit\Plugin\Validation\Constraint\LinkAccessConstraintValidatorTest.
Class
- LinkAccessConstraintValidatorTest
- Tests the LinkAccessConstraintValidator validator.
Namespace
Drupal\Tests\link\Unit\Plugin\Validation\ConstraintCode
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
->getMock('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
->getMock('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;
}