function AliasManagerTest::testGetAliasByPathNoMatch

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

Tests the getAliasByPath method for a path that has no matching alias.

@covers ::getAliasByPath

File

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

Class

AliasManagerTest
@coversDefaultClass \Drupal\path_alias\AliasManager @group path_alias

Namespace

Drupal\Tests\path_alias\Unit

Code

public function testGetAliasByPathNoMatch() {
    $path_part1 = $this->randomMachineName();
    $path_part2 = $this->randomMachineName();
    $path = '/' . $path_part1 . '/' . $path_part2;
    $language = $this->setUpCurrentLanguage();
    $this->aliasManager
        ->setCacheKey($this->path);
    $this->aliasWhitelist
        ->expects($this->any())
        ->method('get')
        ->with($path_part1)
        ->willReturn(TRUE);
    $this->aliasRepository
        ->expects($this->once())
        ->method('lookupBySystemPath')
        ->with($path, $language->getId())
        ->willReturn(NULL);
    $this->assertEquals($path, $this->aliasManager
        ->getAliasByPath($path));
    // Call it twice to test the static cache.
    $this->assertEquals($path, $this->aliasManager
        ->getAliasByPath($path));
    // This needs to write out the cache.
    $this->cache
        ->expects($this->once())
        ->method('set')
        ->with($this->cacheKey, [
        $language->getId() => [
            $path,
        ],
    ], (int) $_SERVER['REQUEST_TIME'] + 60 * 60 * 24);
    $this->aliasManager
        ->writeCache();
}

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