function AliasManagerTest::testCacheClear
Tests cache clear.
@legacy-covers ::cacheClear
File
-
core/
modules/ path_alias/ tests/ src/ Unit/ AliasManagerTest.php, line 282
Class
Namespace
Drupal\Tests\path_alias\UnitCode
public function testCacheClear() : void {
$path = '/path';
$alias = '/alias';
$language = $this->setUpCurrentLanguage();
$this->aliasRepository
->expects($this->exactly(2))
->method('preloadPathAlias')
->with([
$path => $path,
], $language->getId())
->willReturn([
$path => $alias,
]);
$this->aliasPrefixList
->expects($this->any())
->method('get')
->willReturn(TRUE);
// Populate the lookup map.
$this->assertEquals($alias, $this->aliasManager
->getAliasByPath($path, $language->getId()));
// Check that the cache is populated.
$this->aliasRepository
->expects($this->never())
->method('lookupByAlias');
$this->assertEquals($path, $this->aliasManager
->getPathByAlias($alias, $language->getId()));
// Clear specific source.
$this->aliasManager
->cacheClear($path);
// Ensure cache has been cleared (this will be the 2nd call to
// `lookupPathAlias` if cache is cleared).
$this->assertEquals($alias, $this->aliasManager
->getAliasByPath($path, $language->getId()));
// Clear non-existent source.
$this->aliasManager
->cacheClear('non-existent');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.