You are here

public function AccessManagerTest::testCheckNamedRoute in Zircon Profile 8

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

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