public function DependentAccessTest::testSetAccessDependency in Drupal 8
Same name and namespace in other branches
- 9 core/modules/block_content/tests/src/Unit/Access/DependentAccessTest.php \Drupal\Tests\block_content\Unit\Access\DependentAccessTest::testSetAccessDependency()
- 10 core/modules/block_content/tests/src/Unit/Access/DependentAccessTest.php \Drupal\Tests\block_content\Unit\Access\DependentAccessTest::testSetAccessDependency()
Test that the previous dependency is replaced when using set.
@covers ::setAccessDependency
@dataProvider providerTestSetFirst
File
- core/
modules/ block_content/ tests/ src/ Unit/ Access/ DependentAccessTest.php, line 51
Class
- DependentAccessTest
- @coversDefaultClass \Drupal\block_content\Access\RefinableDependentAccessTrait
Namespace
Drupal\Tests\block_content\Unit\AccessCode
public function testSetAccessDependency($use_set_first) {
$testRefinable = new RefinableDependentAccessTraitTestClass();
if ($use_set_first) {
$testRefinable
->setAccessDependency($this->forbidden);
}
else {
$testRefinable
->addAccessDependency($this->forbidden);
}
$accessResult = $testRefinable
->getAccessDependency()
->access('view', $this->account, TRUE);
$this
->assertTrue($accessResult
->isForbidden());
$this
->assertEquals('Because I said so', $accessResult
->getReason());
// Calling setAccessDependency() replaces the existing dependency.
$testRefinable
->setAccessDependency($this->neutral);
$dependency = $testRefinable
->getAccessDependency();
$this
->assertNotInstanceOf(AccessGroupAnd::class, $dependency);
$accessResult = $dependency
->access('view', $this->account, TRUE);
$this
->assertTrue($accessResult
->isNeutral());
$this
->assertEquals('I have no opinion', $accessResult
->getReason());
}