You are here

public function AliasManagerTest::testCacheClear in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Path/AliasManagerTest.php \Drupal\Tests\Core\Path\AliasManagerTest::testCacheClear()

@covers ::cacheClear

File

core/tests/Drupal/Tests/Core/Path/AliasManagerTest.php, line 450
Contains \Drupal\Tests\Core\Path\AliasManagerTest.

Class

AliasManagerTest
@coversDefaultClass \Drupal\Core\Path\AliasManager @group Path

Namespace

Drupal\Tests\Core\Path

Code

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');
}