function DependentAccessTest::testMergeGroup
Same name in other branches
- 8.9.x core/modules/block_content/tests/src/Unit/Access/DependentAccessTest.php \Drupal\Tests\block_content\Unit\Access\DependentAccessTest::testMergeGroup()
- 10 core/modules/block_content/tests/src/Unit/Access/DependentAccessTest.php \Drupal\Tests\block_content\Unit\Access\DependentAccessTest::testMergeGroup()
- 11.x core/modules/block_content/tests/src/Unit/Access/DependentAccessTest.php \Drupal\Tests\block_content\Unit\Access\DependentAccessTest::testMergeGroup()
Tests merging a new dependency with an existing access group dependency.
@dataProvider providerTestSetFirst
File
-
core/
modules/ block_content/ tests/ src/ Unit/ Access/ DependentAccessTest.php, line 110
Class
- DependentAccessTest
- @coversDefaultClass \Drupal\block_content\Access\RefinableDependentAccessTrait
Namespace
Drupal\Tests\block_content\Unit\AccessCode
public function testMergeGroup($use_set_first) {
$andGroup = new AccessGroupAnd();
$andGroup->addDependency($this->forbidden);
$testRefinable = new RefinableDependentAccessTraitTestClass();
if ($use_set_first) {
$testRefinable->setAccessDependency($andGroup);
}
else {
$testRefinable->addAccessDependency($andGroup);
}
$testRefinable->addAccessDependency($this->neutral);
/** @var \Drupal\block_content\Access\AccessGroupAnd $dependency */
$dependency = $testRefinable->getAccessDependency();
// Ensure the new dependency is merged with the existing group.
$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());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.