function PathAliasTestTrait::createPathAlias
Creates a new path alias.
Parameters
string $path: The system path.
string $alias: The alias for the system path.
string $langcode: (optional) A language code for the path alias. Defaults to \Drupal\Core\Language\LanguageInterface::LANGCODE_NOT_SPECIFIED.
Return value
\Drupal\path_alias\PathAliasInterface A path alias entity.
17 calls to PathAliasTestTrait::createPathAlias()
- AliasTest::testLookupByAlias in core/modules/ path_alias/ tests/ src/ Kernel/ AliasTest.php 
- @covers ::lookupByAlias[[api-linebreak]]
- AliasTest::testLookupBySystemPath in core/modules/ path_alias/ tests/ src/ Kernel/ AliasTest.php 
- @covers ::lookupBySystemPath[[api-linebreak]]
- AliasTest::testLookupPath in core/modules/ path_alias/ tests/ src/ Kernel/ AliasTest.php 
- @covers \Drupal\path_alias\AliasManager::getPathByAlias[[api-linebreak]] @covers \Drupal\path_alias\AliasManager::getAliasByPath[[api-linebreak]]
- AliasTest::testWhitelist in core/modules/ path_alias/ tests/ src/ Kernel/ AliasTest.php 
- Tests the alias whitelist.
- AliasTest::testWhitelistCacheDeletionMidRequest in core/modules/ path_alias/ tests/ src/ Kernel/ AliasTest.php 
- Tests situation where the whitelist cache is deleted mid-request.
File
- 
              core/tests/ Drupal/ Tests/ Traits/ Core/ PathAliasTestTrait.php, line 28 
Class
- PathAliasTestTrait
- Provides methods to create and assert path_alias entities.
Namespace
Drupal\Tests\Traits\CoreCode
protected function createPathAlias($path, $alias, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED) {
  /** @var \Drupal\path_alias\PathAliasInterface $path_alias */
  $path_alias = \Drupal::entityTypeManager()->getStorage('path_alias')
    ->create([
    'path' => $path,
    'alias' => $alias,
    'langcode' => $langcode,
  ]);
  $path_alias->save();
  return $path_alias;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
