You are here

public function AccessResultTest::testAccessConditionallyAllowed in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testAccessConditionallyAllowed()
  2. 10 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testAccessConditionallyAllowed()

@covers ::allowedIf @covers ::isAllowed @covers ::isForbidden @covers ::isNeutral

File

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

Class

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

Namespace

Drupal\Tests\Core\Access

Code

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