function AliasManagerTest::testGetPathByAliasNoMatch

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

Class

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

Namespace

Drupal\Tests\path_alias\Unit

Code

public function testGetPathByAliasNoMatch() : void {
    $alias = '/' . $this->randomMachineName();
    $language = new Language([
        'id' => 'en',
    ]);
    $this->languageManager
        ->expects($this->any())
        ->method('getCurrentLanguage')
        ->with(LanguageInterface::TYPE_URL)
        ->willReturn($language);
    $this->aliasRepository
        ->expects($this->once())
        ->method('lookupByAlias')
        ->with($alias, $language->getId())
        ->willReturn(NULL);
    $this->assertEquals($alias, $this->aliasManager
        ->getPathByAlias($alias));
    // Call it twice to test the static cache.
    $this->assertEquals($alias, $this->aliasManager
        ->getPathByAlias($alias));
}

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