You are here

public function AccessManagerTest::testCheckNamedRoute in Drupal 8

Same name and namespace in other branches
  1. 9 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 331
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
    ->at(0))
    ->method('convert')
    ->with([
    RouteObjectInterface::ROUTE_NAME => 'test_route_2',
    RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection
      ->get('test_route_2'),
  ])
    ->will($this
    ->returnValue([]));
  $this->paramConverter
    ->expects($this
    ->at(1))
    ->method('convert')
    ->with([
    RouteObjectInterface::ROUTE_NAME => 'test_route_2',
    RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection
      ->get('test_route_2'),
  ])
    ->will($this
    ->returnValue([]));
  $this->paramConverter
    ->expects($this
    ->at(2))
    ->method('convert')
    ->with([
    'value' => 'example',
    RouteObjectInterface::ROUTE_NAME => 'test_route_4',
    RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection
      ->get('test_route_4'),
  ])
    ->will($this
    ->returnValue([
    'value' => 'example',
  ]));
  $this->paramConverter
    ->expects($this
    ->at(3))
    ->method('convert')
    ->with([
    'value' => 'example',
    RouteObjectInterface::ROUTE_NAME => 'test_route_4',
    RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection
      ->get('test_route_4'),
  ])
    ->will($this
    ->returnValue([
    '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));
}