function UrlTest::setUp
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::setUp()
- 8.9.x core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::setUp()
- 10 core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::setUp()
Overrides UnitTestCase::setUp
File
-
core/
tests/ Drupal/ Tests/ Core/ UrlTest.php, line 70
Class
- UrlTest
- @coversDefaultClass \Drupal\Core\Url @group UrlTest
Namespace
Drupal\Tests\CoreCode
protected function setUp() : void {
parent::setUp();
$map = [];
$map[] = [
'view.frontpage.page_1',
[],
[],
FALSE,
'/node',
];
$map[] = [
'node_view',
[
'node' => '1',
],
[],
FALSE,
'/node/1',
];
$map[] = [
'node_edit',
[
'node' => '2',
],
[],
FALSE,
'/node/2/edit',
];
$this->map = $map;
$alias_map = [
// Set up one proper alias that can be resolved to a system path.
[
'node-alias-test',
NULL,
FALSE,
'node',
],
// Passing in anything else should return the same string.
[
'node',
NULL,
FALSE,
'node',
],
[
'node/1',
NULL,
FALSE,
'node/1',
],
[
'node/2/edit',
NULL,
FALSE,
'node/2/edit',
],
[
'non-existent',
NULL,
FALSE,
'non-existent',
],
];
// $this->map has $collect_bubbleable_metadata = FALSE; also generate the
// $collect_bubbleable_metadata = TRUE case for ::generateFromRoute().
$generate_from_route_map = [];
foreach ($this->map as $values) {
$generate_from_route_map[] = $values;
$generate_from_route_map[] = [
$values[0],
$values[1],
$values[2],
TRUE,
(new GeneratedUrl())->setGeneratedUrl($values[4]),
];
}
$this->urlGenerator = $this->createMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
$this->urlGenerator
->expects($this->any())
->method('generateFromRoute')
->willReturnMap($generate_from_route_map);
$this->pathAliasManager = $this->createMock('Drupal\\path_alias\\AliasManagerInterface');
$this->pathAliasManager
->expects($this->any())
->method('getPathByAlias')
->willReturnMap($alias_map);
$this->router = $this->createMock('Drupal\\Tests\\Core\\Routing\\TestRouterInterface');
$this->pathValidator = $this->createMock('Drupal\\Core\\Path\\PathValidatorInterface');
$this->container = new ContainerBuilder();
$this->container
->set('router.no_access_checks', $this->router);
$this->container
->set('url_generator', $this->urlGenerator);
$this->container
->set('path_alias.manager', $this->pathAliasManager);
$this->container
->set('path.validator', $this->pathValidator);
\Drupal::setContainer($this->container);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.