You are here

public function AccessResultTest::testAccessForbiddenReason in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testAccessForbiddenReason()
  2. 9 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 122
Contains \Drupal\Tests\Core\Access\AccessResultTest.

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, '');
  $reason = $this
    ->getRandomGenerator()
    ->string();
  $b = AccessResult::forbidden($reason);
  $verify($b, $reason);
  $b = AccessResult::forbiddenIf(TRUE, $reason);
  $verify($b, $reason);
}