function AccessManagerTest::setUp

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php \Drupal\Tests\Core\Access\AccessManagerTest::setUp()
  2. 10 core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php \Drupal\Tests\Core\Access\AccessManagerTest::setUp()
  3. 11.x 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 94

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', [], [
        '_access' => 'TRUE',
    ]));
    $this->routeCollection
        ->add('test_route_3', new Route('/test-route-3', [], [
        '_access' => 'FALSE',
    ]));
    $this->routeCollection
        ->add('test_route_4', new Route('/test-route-4/{value}', [], [
        '_access' => 'TRUE',
    ]));
    $this->routeProvider = $this->createMock('Drupal\\Core\\Routing\\RouteProviderInterface');
    $map = [];
    foreach ($this->routeCollection
        ->all() as $name => $route) {
        $map[] = [
            $name,
            $route,
        ];
    }
    $map[] = [
        'test_route_4',
        $this->routeCollection
            ->get('test_route_4'),
    ];
    $this->routeProvider
        ->expects($this->any())
        ->method('getRouteByName')
        ->will($this->returnValueMap($map));
    $map = [];
    $map[] = [
        'test_route_1',
        [],
        '/test-route-1',
    ];
    $map[] = [
        'test_route_2',
        [],
        '/test-route-2',
    ];
    $map[] = [
        'test_route_3',
        [],
        '/test-route-3',
    ];
    $map[] = [
        'test_route_4',
        [
            'value' => 'example',
        ],
        '/test-route-4/example',
    ];
    $this->paramConverter = $this->createMock('Drupal\\Core\\ParamConverter\\ParamConverterManagerInterface');
    $this->account = $this->createMock('Drupal\\Core\\Session\\AccountInterface');
    $this->currentUser = $this->createMock('Drupal\\Core\\Session\\AccountInterface');
    $this->argumentsResolverFactory = $this->createMock('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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.