function AccessResultTest::testAccessForbiddenReason

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testAccessForbiddenReason()
  2. 10 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testAccessForbiddenReason()
  3. 11.x core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testAccessForbiddenReason()

@covers ::forbidden

File

core/tests/Drupal/Tests/Core/Access/AccessResultTest.php, line 121

Class

AccessResultTest
@coversDefaultClass \Drupal\Core\Access\AccessResult @group Access

Namespace

Drupal\Tests\Core\Access

Code

public function testAccessForbiddenReason() {
    $verify = function (AccessResult $access, $reason) {
        $this->assertInstanceOf(AccessResultReasonInterface::class, $access);
        $this->assertSame($reason, $access->getReason());
    };
    $b = AccessResult::forbidden();
    $verify($b, NULL);
    $reason = $this->getRandomGenerator()
        ->string();
    $b = AccessResult::forbidden($reason);
    $verify($b, $reason);
    $b = AccessResult::forbiddenIf(TRUE, $reason);
    $verify($b, $reason);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.