$request_stack = \Drupal::
requestStack();
// Test request with subdirectory on homepage.
$server =
[ 'SCRIPT_NAME' => '/subdir/index.php',
'SCRIPT_FILENAME' =>
$this->root . '/subdir/index.php',
'SERVER_NAME' => 'http://localhost',
];
$request = Request::
create('/subdir/', 'GET',
[],
[],
[],
$server);
$request->server->
add($server);
$request_stack->
push($request);
$bubbleable_metadata =
new BubbleableMetadata();
$this->container->
get('router.request_context'
)->
setCompleteBaseUrl('http://localhost/subdir'
);
$this->
assertEquals('http://localhost/subdir',
$this->tokenService->
replace('[site:base-url]',
[],
['langcode' =>
$this->interfaceLanguage->
getId()],
$bubbleable_metadata));
$this->
assertEquals((new BubbleableMetadata())->
addCacheContexts(['url.site'
]),
$bubbleable_metadata);
$bubbleable_metadata =
new BubbleableMetadata();
$this->
assertEquals('/subdir',
$this->tokenService->
replace('[site:base-path]',
[],
['langcode' =>
$this->interfaceLanguage->
getId()],
$bubbleable_metadata));
$this->
assertEquals((new BubbleableMetadata())->
addCacheContexts(['url.site'
]),
$bubbleable_metadata);
} /**
* Tests the generation of all system date tokens.
*/
public function testSystemDateTokenReplacement() {