function AliasManagerTest::testGetAliasByPathUncachedMissNoAlias
Same name in other branches
- 9 core/modules/path_alias/tests/src/Unit/AliasManagerTest.php \Drupal\Tests\path_alias\Unit\AliasManagerTest::testGetAliasByPathUncachedMissNoAlias()
- 8.9.x core/modules/path_alias/tests/src/Unit/AliasManagerTest.php \Drupal\Tests\path_alias\Unit\AliasManagerTest::testGetAliasByPathUncachedMissNoAlias()
- 10 core/modules/path_alias/tests/src/Unit/AliasManagerTest.php \Drupal\Tests\path_alias\Unit\AliasManagerTest::testGetAliasByPathUncachedMissNoAlias()
Tests the getAliasByPath cache with an un-preloaded path without alias.
@covers ::getAliasByPath @covers ::writeCache
File
-
core/
modules/ path_alias/ tests/ src/ Unit/ AliasManagerTest.php, line 418
Class
- AliasManagerTest
- @coversDefaultClass \Drupal\path_alias\AliasManager @group path_alias
Namespace
Drupal\Tests\path_alias\UnitCode
public function testGetAliasByPathUncachedMissNoAlias() : void {
$path_part1 = $this->randomMachineName();
$path_part2 = $this->randomMachineName();
$path = '/' . $path_part1 . '/' . $path_part2;
$cached_path = $this->randomMachineName();
$cached_alias = $this->randomMachineName();
$language = $this->setUpCurrentLanguage();
$cached_paths = [
$language->getId() => [
$cached_path,
],
];
$this->cache
->expects($this->once())
->method('get')
->with($this->cacheKey)
->willReturn((object) [
'data' => $cached_paths,
]);
// Simulate a request so that the preloaded paths are fetched.
$this->aliasManager
->setCacheKey($this->path);
$this->aliasPrefixList
->expects($this->any())
->method('get')
->with($path_part1)
->willReturn(TRUE);
$this->aliasRepository
->expects($this->once())
->method('preloadPathAlias')
->with($cached_paths[$language->getId()], $language->getId())
->willReturn([
$cached_path => $cached_alias,
]);
$this->aliasRepository
->expects($this->once())
->method('lookupBySystemPath')
->with($path, $language->getId())
->willReturn(NULL);
$this->assertEquals($path, $this->aliasManager
->getAliasByPath($path));
// Call it twice to test the static cache.
$this->assertEquals($path, $this->aliasManager
->getAliasByPath($path));
// There is already a cache entry, so this should not write out to the
// cache.
$this->cache
->expects($this->never())
->method('set');
$this->aliasManager
->writeCache();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.