function AliasManagerTest::testCacheClear

Same name and namespace in other branches
  1. 11.x core/modules/path_alias/tests/src/Unit/AliasManagerTest.php \Drupal\Tests\path_alias\Unit\AliasManagerTest::testCacheClear()
  2. 10 core/modules/path_alias/tests/src/Unit/AliasManagerTest.php \Drupal\Tests\path_alias\Unit\AliasManagerTest::testCacheClear()
  3. 9 core/modules/path_alias/tests/src/Unit/AliasManagerTest.php \Drupal\Tests\path_alias\Unit\AliasManagerTest::testCacheClear()
  4. 8.9.x core/modules/path_alias/tests/src/Unit/AliasManagerTest.php \Drupal\Tests\path_alias\Unit\AliasManagerTest::testCacheClear()

Tests cache clear.

File

core/modules/path_alias/tests/src/Unit/AliasManagerTest.php, line 264

Class

AliasManagerTest
Tests Drupal\path_alias\AliasManager.

Namespace

Drupal\Tests\path_alias\Unit

Code

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.