public function DependentAccessTest::testMergeNonGroup in Drupal 10
Same name and namespace in other branches
- 8 core/modules/block_content/tests/src/Unit/Access/DependentAccessTest.php \Drupal\Tests\block_content\Unit\Access\DependentAccessTest::testMergeNonGroup()
- 9 core/modules/block_content/tests/src/Unit/Access/DependentAccessTest.php \Drupal\Tests\block_content\Unit\Access\DependentAccessTest::testMergeNonGroup()
Tests merging a new dependency with existing non-group access dependency.
@dataProvider providerTestSetFirst
File
- core/
modules/ block_content/ tests/ src/ Unit/ Access/ DependentAccessTest.php, line 78
Class
- DependentAccessTest
- @coversDefaultClass \Drupal\block_content\Access\RefinableDependentAccessTrait
Namespace
Drupal\Tests\block_content\Unit\AccessCode
public function testMergeNonGroup($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());
$testRefinable
->addAccessDependency($this->neutral);
/** @var \Drupal\block_content\Access\AccessGroupAnd $dependency */
$dependency = $testRefinable
->getAccessDependency();
// Ensure the new dependency create a new AND group when merged.
$this
->assertInstanceOf(AccessGroupAnd::class, $dependency);
$dependencies = $dependency
->getDependencies();
$accessResultForbidden = $dependencies[0]
->access('view', $this->account, TRUE);
$this
->assertTrue($accessResultForbidden
->isForbidden());
$this
->assertEquals('Because I said so', $accessResultForbidden
->getReason());
$accessResultNeutral = $dependencies[1]
->access('view', $this->account, TRUE);
$this
->assertTrue($accessResultNeutral
->isNeutral());
$this
->assertEquals('I have no opinion', $accessResultNeutral
->getReason());
}