You are here

public function AccessManagerTest::testCheckNamedRouteWithNonExistingRoute in Drupal 9

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

Tests checkNamedRoute given an invalid/non existing route name.

File

core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php, line 453
Contains \Drupal\Tests\Core\Access\AccessManagerTest.

Class

AccessManagerTest
@coversDefaultClass \Drupal\Core\Access\AccessManager @group Access

Namespace

Drupal\Tests\Core\Access

Code

public function testCheckNamedRouteWithNonExistingRoute() {
  $this->routeProvider
    ->expects($this
    ->any())
    ->method('getRouteByName')
    ->will($this
    ->throwException(new RouteNotFoundException()));
  $this
    ->setupAccessChecker();
  $this
    ->assertEquals(FALSE, $this->accessManager
    ->checkNamedRoute('test_route_1', [], $this->account), 'A non existing route lead to access.');
  $this
    ->assertEquals(AccessResult::forbidden()
    ->addCacheTags([
    'config:core.extension',
  ]), $this->accessManager
    ->checkNamedRoute('test_route_1', [], $this->account, TRUE), 'A non existing route lead to access.');
}