You are here

public function AliasManagerTest::testGetPathByAliasNoMatch in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/path_alias/tests/src/Unit/AliasManagerTest.php \Drupal\Tests\path_alias\Unit\AliasManagerTest::testGetPathByAliasNoMatch()

Tests the getPathByAlias method for an alias that have no matching path.

@covers ::getPathByAlias

File

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

Class

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

Namespace

Drupal\Tests\path_alias\Unit

Code

public function testGetPathByAliasNoMatch() {
  $alias = '/' . $this
    ->randomMachineName();
  $language = new Language([
    'id' => 'en',
  ]);
  $this->languageManager
    ->expects($this
    ->any())
    ->method('getCurrentLanguage')
    ->with(LanguageInterface::TYPE_URL)
    ->will($this
    ->returnValue($language));
  $this->aliasRepository
    ->expects($this
    ->once())
    ->method('lookupByAlias')
    ->with($alias, $language
    ->getId())
    ->will($this
    ->returnValue(NULL));
  $this
    ->assertEquals($alias, $this->aliasManager
    ->getPathByAlias($alias));

  // Call it twice to test the static cache.
  $this
    ->assertEquals($alias, $this->aliasManager
    ->getPathByAlias($alias));
}