File
- drupal/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php, line 82
- Contains Drupal\system\Tests\Path\AliasTest.
Class
- AliasTest
- Tests path alias CRUD and lookup functionality.
Namespace
Drupal\system\Tests\Path
Code
function testLookupPath() {
$connection = Database::getConnection();
$this->fixtures
->createTables($connection);
$whitelist = new AliasWhitelist('path_alias_whitelist', 'cache', $this->container
->get('keyvalue'), $connection);
$aliasManager = new AliasManager($connection, $whitelist, $this->container
->get('language_manager'));
$pathObject = new Path($connection, $aliasManager);
$path = array(
'source' => "user/1",
'alias' => 'foo',
);
$pathObject
->save($path['source'], $path['alias']);
$this
->assertEqual($aliasManager
->getPathAlias($path['source']), $path['alias'], 'Basic alias lookup works.');
$this
->assertEqual($aliasManager
->getSystemPath($path['alias']), $path['source'], 'Basic source lookup works.');
$path = array(
'source' => "user/1",
'alias' => "users/Dries",
'langcode' => 'en',
);
$pathObject
->save($path['source'], $path['alias'], $path['langcode']);
$this
->assertEqual($aliasManager
->getPathAlias($path['source']), $path['alias'], 'English alias overrides language-neutral alias.');
$this
->assertEqual($aliasManager
->getSystemPath($path['alias']), $path['source'], 'English source overrides language-neutral source.');
$path = array(
'source' => "user/1",
'alias' => 'bar',
);
$pathObject
->save($path['source'], $path['alias']);
$this
->assertEqual($aliasManager
->getPathAlias($path['source']), "users/Dries", 'English alias still returned after entering a language-neutral alias.');
$path = array(
'source' => "user/1",
'alias' => 'LOL',
'langcode' => 'xx-lolspeak',
);
$pathObject
->save($path['source'], $path['alias'], $path['langcode']);
$this
->assertEqual($aliasManager
->getPathAlias($path['source']), "users/Dries", 'English alias still returned after entering a LOLspeak alias.');
$this
->assertEqual($aliasManager
->getPathAlias($path['source'], 'xx-lolspeak'), 'LOL', 'LOLspeak alias returned if we specify xx-lolspeak to the alias manager.');
$path = array(
'source' => "user/1",
'alias' => 'users/my-new-path',
'langcode' => 'en',
);
$pathObject
->save($path['source'], $path['alias'], $path['langcode']);
$this
->assertEqual($aliasManager
->getPathAlias($path['source']), $path['alias'], 'Recently created English alias returned.');
$this
->assertEqual($aliasManager
->getSystemPath($path['alias']), $path['source'], 'Recently created English source returned.');
$pathObject
->delete(array(
'langcode' => 'en',
));
$this
->assertEqual($aliasManager
->getPathAlias($path['source']), 'bar', 'Path lookup falls back to recently created language-neutral alias.');
$pathObject
->save('user/2', 'bar');
$this
->assertEqual($aliasManager
->getSystemPath('bar'), 'user/2', 'Newer alias record is returned when comparing two Language::LANGCODE_NOT_SPECIFIED paths with the same alias.');
}