function AliasTest::testPreloadPathAlias
Same name in other branches
- 11.x core/modules/path_alias/tests/src/Kernel/AliasTest.php \Drupal\Tests\path_alias\Kernel\AliasTest::testPreloadPathAlias()
@covers ::preloadPathAlias
File
-
core/
modules/ path_alias/ tests/ src/ Kernel/ AliasTest.php, line 47
Class
- AliasTest
- Tests path alias CRUD and lookup functionality.
Namespace
Drupal\Tests\path_alias\KernelCode
public function testPreloadPathAlias() : void {
$path_alias_repository = $this->container
->get('path_alias.repository');
// Every interesting language combination:
// Just unspecified.
$this->createPathAlias('/und/src', '/und/alias', LanguageInterface::LANGCODE_NOT_SPECIFIED);
// Just a single language.
$this->createPathAlias('/en/src', '/en/alias', 'en');
// A single language, plus unspecified.
$this->createPathAlias('/en-und/src', '/en-und/und', LanguageInterface::LANGCODE_NOT_SPECIFIED);
$this->createPathAlias('/en-und/src', '/en-und/en', 'en');
// Multiple languages.
$this->createPathAlias('/en-xx-lolspeak/src', '/en-xx-lolspeak/en', 'en');
$this->createPathAlias('/en-xx-lolspeak/src', '/en-xx-lolspeak/xx-lolspeak', 'xx-lolspeak');
// A duplicate alias for the same path. This is later, so should be
// preferred.
$this->createPathAlias('/en-xx-lolspeak/src', '/en-xx-lolspeak/en-dup', 'en');
// Multiple languages, plus unspecified.
$this->createPathAlias('/en-xx-lolspeak-und/src', '/en-xx-lolspeak-und/und', LanguageInterface::LANGCODE_NOT_SPECIFIED);
$this->createPathAlias('/en-xx-lolspeak-und/src', '/en-xx-lolspeak-und/en', 'en');
$this->createPathAlias('/en-xx-lolspeak-und/src', '/en-xx-lolspeak-und/xx-lolspeak', 'xx-lolspeak');
// Queries for unspecified language aliases.
// Ask for an empty array, get all results.
$this->assertEquals([
'/und/src' => '/und/alias',
'/en-und/src' => '/en-und/und',
'/en-xx-lolspeak-und/src' => '/en-xx-lolspeak-und/und',
], $path_alias_repository->preloadPathAlias([], LanguageInterface::LANGCODE_NOT_SPECIFIED));
// Ask for nonexistent source.
$this->assertEquals([], $path_alias_repository->preloadPathAlias([
'/nonexistent',
], LanguageInterface::LANGCODE_NOT_SPECIFIED));
// Ask for each saved source, individually.
$this->assertEquals([
'/und/src' => '/und/alias',
], $path_alias_repository->preloadPathAlias([
'/und/src',
], LanguageInterface::LANGCODE_NOT_SPECIFIED));
$this->assertEquals([], $path_alias_repository->preloadPathAlias([
'/en/src',
], LanguageInterface::LANGCODE_NOT_SPECIFIED));
$this->assertEquals([
'/en-und/src' => '/en-und/und',
], $path_alias_repository->preloadPathAlias([
'/en-und/src',
], LanguageInterface::LANGCODE_NOT_SPECIFIED));
$this->assertEquals([], $path_alias_repository->preloadPathAlias([
'/en-xx-lolspeak/src',
], LanguageInterface::LANGCODE_NOT_SPECIFIED));
$this->assertEquals([
'/en-xx-lolspeak-und/src' => '/en-xx-lolspeak-und/und',
], $path_alias_repository->preloadPathAlias([
'/en-xx-lolspeak-und/src',
], LanguageInterface::LANGCODE_NOT_SPECIFIED));
// Ask for multiple sources, all that are known.
$this->assertEquals([
'/und/src' => '/und/alias',
'/en-und/src' => '/en-und/und',
'/en-xx-lolspeak-und/src' => '/en-xx-lolspeak-und/und',
], $path_alias_repository->preloadPathAlias([
'/nonexistent',
'/und/src',
'/en/src',
'/en-und/src',
'/en-xx-lolspeak/src',
'/en-xx-lolspeak-und/src',
], LanguageInterface::LANGCODE_NOT_SPECIFIED));
// Ask for multiple sources, just a subset.
$this->assertEquals([
'/und/src' => '/und/alias',
'/en-xx-lolspeak-und/src' => '/en-xx-lolspeak-und/und',
], $path_alias_repository->preloadPathAlias([
'/und/src',
'/en-xx-lolspeak/src',
'/en-xx-lolspeak-und/src',
], LanguageInterface::LANGCODE_NOT_SPECIFIED));
// Queries for English aliases.
// Ask for an empty array, get all results.
$this->assertEquals([
'/und/src' => '/und/alias',
'/en/src' => '/en/alias',
'/en-und/src' => '/en-und/en',
'/en-xx-lolspeak/src' => '/en-xx-lolspeak/en-dup',
'/en-xx-lolspeak-und/src' => '/en-xx-lolspeak-und/en',
], $path_alias_repository->preloadPathAlias([], 'en'));
// Ask for nonexistent source.
$this->assertEquals([], $path_alias_repository->preloadPathAlias([
'/nonexistent',
], 'en'));
// Ask for each saved source, individually.
$this->assertEquals([
'/und/src' => '/und/alias',
], $path_alias_repository->preloadPathAlias([
'/und/src',
], 'en'));
$this->assertEquals([
'/en/src' => '/en/alias',
], $path_alias_repository->preloadPathAlias([
'/en/src',
], 'en'));
$this->assertEquals([
'/en-und/src' => '/en-und/en',
], $path_alias_repository->preloadPathAlias([
'/en-und/src',
], 'en'));
$this->assertEquals([
'/en-xx-lolspeak/src' => '/en-xx-lolspeak/en-dup',
], $path_alias_repository->preloadPathAlias([
'/en-xx-lolspeak/src',
], 'en'));
$this->assertEquals([
'/en-xx-lolspeak-und/src' => '/en-xx-lolspeak-und/en',
], $path_alias_repository->preloadPathAlias([
'/en-xx-lolspeak-und/src',
], 'en'));
// Ask for multiple sources, all that are known.
$this->assertEquals([
'/und/src' => '/und/alias',
'/en/src' => '/en/alias',
'/en-und/src' => '/en-und/en',
'/en-xx-lolspeak/src' => '/en-xx-lolspeak/en-dup',
'/en-xx-lolspeak-und/src' => '/en-xx-lolspeak-und/en',
], $path_alias_repository->preloadPathAlias([
'/nonexistent',
'/und/src',
'/en/src',
'/en-und/src',
'/en-xx-lolspeak/src',
'/en-xx-lolspeak-und/src',
], 'en'));
// Ask for multiple sources, just a subset.
$this->assertEquals([
'/und/src' => '/und/alias',
'/en-xx-lolspeak/src' => '/en-xx-lolspeak/en-dup',
'/en-xx-lolspeak-und/src' => '/en-xx-lolspeak-und/en',
], $path_alias_repository->preloadPathAlias([
'/und/src',
'/en-xx-lolspeak/src',
'/en-xx-lolspeak-und/src',
], 'en'));
// Queries for xx-lolspeak aliases.
// Ask for an empty array, get all results.
$this->assertEquals([
'/und/src' => '/und/alias',
'/en-und/src' => '/en-und/und',
'/en-xx-lolspeak/src' => '/en-xx-lolspeak/xx-lolspeak',
'/en-xx-lolspeak-und/src' => '/en-xx-lolspeak-und/xx-lolspeak',
], $path_alias_repository->preloadPathAlias([], 'xx-lolspeak'));
// Ask for nonexistent source.
$this->assertEquals([], $path_alias_repository->preloadPathAlias([
'/nonexistent',
], 'xx-lolspeak'));
// Ask for each saved source, individually.
$this->assertEquals([
'/und/src' => '/und/alias',
], $path_alias_repository->preloadPathAlias([
'/und/src',
], 'xx-lolspeak'));
$this->assertEquals([], $path_alias_repository->preloadPathAlias([
'/en/src',
], 'xx-lolspeak'));
$this->assertEquals([
'/en-und/src' => '/en-und/und',
], $path_alias_repository->preloadPathAlias([
'/en-und/src',
], 'xx-lolspeak'));
$this->assertEquals([
'/en-xx-lolspeak/src' => '/en-xx-lolspeak/xx-lolspeak',
], $path_alias_repository->preloadPathAlias([
'/en-xx-lolspeak/src',
], 'xx-lolspeak'));
$this->assertEquals([
'/en-xx-lolspeak-und/src' => '/en-xx-lolspeak-und/xx-lolspeak',
], $path_alias_repository->preloadPathAlias([
'/en-xx-lolspeak-und/src',
], 'xx-lolspeak'));
// Ask for multiple sources, all that are known.
$this->assertEquals([
'/und/src' => '/und/alias',
'/en-und/src' => '/en-und/und',
'/en-xx-lolspeak/src' => '/en-xx-lolspeak/xx-lolspeak',
'/en-xx-lolspeak-und/src' => '/en-xx-lolspeak-und/xx-lolspeak',
], $path_alias_repository->preloadPathAlias([
'/nonexistent',
'/und/src',
'/en/src',
'/en-und/src',
'/en-xx-lolspeak/src',
'/en-xx-lolspeak-und/src',
], 'xx-lolspeak'));
// Ask for multiple sources, just a subset.
$this->assertEquals([
'/und/src' => '/und/alias',
'/en-xx-lolspeak/src' => '/en-xx-lolspeak/xx-lolspeak',
'/en-xx-lolspeak-und/src' => '/en-xx-lolspeak-und/xx-lolspeak',
], $path_alias_repository->preloadPathAlias([
'/und/src',
'/en-xx-lolspeak/src',
'/en-xx-lolspeak-und/src',
], 'xx-lolspeak'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.