You are here

public function AccessResultTest::testAccessConditionallyForbidden 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::testAccessConditionallyForbidden()
  2. 9 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testAccessConditionallyForbidden()

@covers ::forbiddenIf @covers ::isAllowed @covers ::isForbidden @covers ::isNeutral

File

core/tests/Drupal/Tests/Core/Access/AccessResultTest.php, line 165
Contains \Drupal\Tests\Core\Access\AccessResultTest.

Class

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

Namespace

Drupal\Tests\Core\Access

Code

public function testAccessConditionallyForbidden() {
  $verify = function (AccessResult $access, $forbidden) {
    $this
      ->assertFalse($access
      ->isAllowed());
    $this
      ->assertSame($forbidden, $access
      ->isForbidden());
    $this
      ->assertSame(!$forbidden, $access
      ->isNeutral());
    $this
      ->assertDefaultCacheability($access);
  };
  $b1 = AccessResult::forbiddenIf(TRUE);
  $verify($b1, TRUE);
  $b2 = AccessResult::forbiddenIf(FALSE);
  $verify($b2, FALSE);
}