You are here

protected function AccessManagerTest::setUp in Zircon Profile 8.0

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

Overrides UnitTestCase::setUp

File

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

Class

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

Namespace

Drupal\Tests\Core\Access

Code

protected function setUp() {
  parent::setUp();
  $this->container = new ContainerBuilder();
  $cache_contexts_manager = $this
    ->prophesize(CacheContextsManager::class)
    ->reveal();
  $this->container
    ->set('cache_contexts_manager', $cache_contexts_manager);
  \Drupal::setContainer($this->container);
  $this->routeCollection = new RouteCollection();
  $this->routeCollection
    ->add('test_route_1', new Route('/test-route-1'));
  $this->routeCollection
    ->add('test_route_2', new Route('/test-route-2', array(), array(
    '_access' => 'TRUE',
  )));
  $this->routeCollection
    ->add('test_route_3', new Route('/test-route-3', array(), array(
    '_access' => 'FALSE',
  )));
  $this->routeCollection
    ->add('test_route_4', new Route('/test-route-4/{value}', array(), array(
    '_access' => 'TRUE',
  )));
  $this->routeProvider = $this
    ->getMock('Drupal\\Core\\Routing\\RouteProviderInterface');
  $map = array();
  foreach ($this->routeCollection
    ->all() as $name => $route) {
    $map[] = array(
      $name,
      array(),
      $route,
    );
  }
  $map[] = array(
    'test_route_4',
    array(
      'value' => 'example',
    ),
    $this->routeCollection
      ->get('test_route_4'),
  );
  $this->routeProvider
    ->expects($this
    ->any())
    ->method('getRouteByName')
    ->will($this
    ->returnValueMap($map));
  $map = array();
  $map[] = array(
    'test_route_1',
    array(),
    '/test-route-1',
  );
  $map[] = array(
    'test_route_2',
    array(),
    '/test-route-2',
  );
  $map[] = array(
    'test_route_3',
    array(),
    '/test-route-3',
  );
  $map[] = array(
    'test_route_4',
    array(
      'value' => 'example',
    ),
    '/test-route-4/example',
  );
  $this->paramConverter = $this
    ->getMock('Drupal\\Core\\ParamConverter\\ParamConverterManagerInterface');
  $this->account = $this
    ->getMock('Drupal\\Core\\Session\\AccountInterface');
  $this->currentUser = $this
    ->getMock('Drupal\\Core\\Session\\AccountInterface');
  $this->argumentsResolverFactory = $this
    ->getMock('Drupal\\Core\\Access\\AccessArgumentsResolverFactoryInterface');
  $this->checkProvider = new CheckProvider();
  $this->checkProvider
    ->setContainer($this->container);
  $this->accessManager = new AccessManager($this->routeProvider, $this->paramConverter, $this->argumentsResolverFactory, $this->currentUser, $this->checkProvider);
}