public function AliasManagerTest::testCacheClear in Drupal 9
Same name and namespace in other branches
- 8 core/modules/path_alias/tests/src/Unit/AliasManagerTest.php \Drupal\Tests\path_alias\Unit\AliasManagerTest::testCacheClear()
@covers ::cacheClear
File
- core/
modules/ path_alias/ tests/ src/ Unit/ AliasManagerTest.php, line 445
Class
- AliasManagerTest
- @coversDefaultClass \Drupal\path_alias\AliasManager @group path_alias
Namespace
Drupal\Tests\path_alias\UnitCode
public function testCacheClear() {
$path = '/path';
$alias = '/alias';
$language = $this
->setUpCurrentLanguage();
$this->aliasRepository
->expects($this
->exactly(2))
->method('lookupBySystemPath')
->with($path, $language
->getId())
->willReturn([
'alias' => $alias,
]);
$this->aliasWhitelist
->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');
}