protected function AccessManagerTest::setUp in Drupal 8
Same name and namespace in other branches
- 9 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 - Contains \Drupal\Tests\Core\Access\AccessManagerTest.
Class
- AccessManagerTest
- @coversDefaultClass \Drupal\Core\Access\AccessManager @group Access
Namespace
Drupal\Tests\Core\AccessCode
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);
}