function DependentAccessTest::testSetAccessDependency
Tests 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[[api-linebreak]]
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());
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
