function DefaultAccessCheckTest::testAccess

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

Test 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));
}

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