You are here

public function DefaultAccessCheckTest::testAccess in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Access/DefaultAccessCheckTest.php \Drupal\Tests\Core\Access\DefaultAccessCheckTest::testAccess()

Tests the access method.

File

core/tests/Drupal/Tests/Core/Access/DefaultAccessCheckTest.php, line 44

Class

DefaultAccessCheckTest
@coversDefaultClass \Drupal\Core\Access\DefaultAccessCheck @group Access

Namespace

Drupal\Tests\Core\Access

Code

public function testAccess() {
  $request = new Request([]);
  $route = new Route('/test-route', [], [
    '_access' => 'NULL',
  ]);
  $this
    ->assertEquals(AccessResult::neutral(), $this->accessChecker
    ->access($route, $request, $this->account));
  $route = new Route('/test-route', [], [
    '_access' => 'FALSE',
  ]);
  $this
    ->assertEquals(AccessResult::forbidden(), $this->accessChecker
    ->access($route, $request, $this->account));
  $route = new Route('/test-route', [], [
    '_access' => 'TRUE',
  ]);
  $this
    ->assertEquals(AccessResult::allowed(), $this->accessChecker
    ->access($route, $request, $this->account));
}