You are here

protected function PathAliasTestTrait::createPathAlias in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Traits/Core/PathAliasTestTrait.php \Drupal\Tests\Traits\Core\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
AliasTest::testLookupBySystemPath in core/modules/path_alias/tests/src/Kernel/AliasTest.php
@covers ::lookupBySystemPath
AliasTest::testLookupPath in core/modules/path_alias/tests/src/Kernel/AliasTest.php
@covers \Drupal\path_alias\AliasManager::getPathByAlias @covers \Drupal\path_alias\AliasManager::getAliasByPath
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.

... See full list

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\Core

Code

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;
}