You are here

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

Tests the checkNamedRoute method.

See also

\Drupal\Core\Access\AccessManager::checkNamedRoute()

File

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

Class

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

Namespace

Drupal\Tests\Core\Access

Code

public function testCheckNamedRoute() {
  $this
    ->setupAccessChecker();
  $this->checkProvider
    ->setChecks($this->routeCollection);
  $this
    ->setupAccessArgumentsResolverFactory();
  $this->paramConverter
    ->expects($this
    ->exactly(4))
    ->method('convert')
    ->willReturnMap([
    [
      [
        RouteObjectInterface::ROUTE_NAME => 'test_route_2',
        RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection
          ->get('test_route_2'),
      ],
      [],
    ],
    [
      [
        'value' => 'example',
        RouteObjectInterface::ROUTE_NAME => 'test_route_4',
        RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection
          ->get('test_route_4'),
      ],
      [
        'value' => 'example',
      ],
    ],
  ]);

  // Tests the access with routes with parameters without given request.
  $this
    ->assertEquals(TRUE, $this->accessManager
    ->checkNamedRoute('test_route_2', [], $this->account));
  $this
    ->assertEquals(AccessResult::allowed(), $this->accessManager
    ->checkNamedRoute('test_route_2', [], $this->account, TRUE));
  $this
    ->assertEquals(TRUE, $this->accessManager
    ->checkNamedRoute('test_route_4', [
    'value' => 'example',
  ], $this->account));
  $this
    ->assertEquals(AccessResult::allowed(), $this->accessManager
    ->checkNamedRoute('test_route_4', [
    'value' => 'example',
  ], $this->account, TRUE));
}