function AliasManagerTest::testCacheClear

Same name and namespace in other branches
  1. 9 core/modules/path_alias/tests/src/Unit/AliasManagerTest.php \Drupal\Tests\path_alias\Unit\AliasManagerTest::testCacheClear()
  2. 8.9.x core/modules/path_alias/tests/src/Unit/AliasManagerTest.php \Drupal\Tests\path_alias\Unit\AliasManagerTest::testCacheClear()
  3. 10 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 465

Class

AliasManagerTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21path_alias%21src%21AliasManager.php/class/AliasManager/11.x" title="The default alias manager implementation." class="local">\Drupal\path_alias\AliasManager</a> @group path_alias

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.