Commit b56c5f87 authored by alexpott's avatar alexpott

Issue #2281167 by jhedstrom, blueminds: AliasManager strange cacheClear logic

parent 17c25003
......@@ -253,7 +253,7 @@ public function getAliasByPath($path, $langcode = NULL) {
public function cacheClear($source = NULL) {
if ($source) {
foreach (array_keys($this->lookupMap) as $lang) {
$this->lookupMap[$lang][$source];
unset($this->lookupMap[$lang][$source]);
}
}
else {
......
......@@ -7,14 +7,10 @@
namespace Drupal\Tests\Core\Path;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Path\AliasManager;
use Drupal\Core\Url;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
/**
* @coversDefaultClass \Drupal\Core\Path\AliasManager
......@@ -455,6 +451,43 @@ public function testGetAliasByPathUncachedMissNoAlias() {
$this->aliasManager->writeCache();
}
/**
* @covers ::cacheClear
*/
public function testCacheClear() {
$path = 'path';
$alias = 'alias';
$language = $this->setUpCurrentLanguage();
$this->aliasStorage->expects($this->exactly(2))
->method('lookupPathAlias')
->with($path, $language->getId())
->willReturn($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.
$original_storage = clone $this->aliasStorage;
$this->aliasStorage->expects($this->never())
->method('lookupPathSource');
$this->assertEquals($path, $this->aliasManager->getPathByAlias($alias, $language->getId()));
// Clear specific source.
$this->cache->expects($this->exactly(2))
->method('delete');
$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');
}
/**
* Tests the getAliasByPath cache with an unpreloaded path with alias.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment