You are here

protected function PathAliasTestTrait::createPathAlias in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Traits/Core/PathAliasTestTrait.php \Drupal\Tests\Traits\Core\PathAliasTestTrait::createPathAlias()
  2. 9 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.

5 calls to PathAliasTestTrait::createPathAlias()
ContentNegotiationRoutingTest::testContentRouting in core/tests/Drupal/KernelTests/Core/Routing/ContentNegotiationRoutingTest.php
Tests the content negotiation aspect of routing.
DbDumpTest::setUp in core/tests/Drupal/KernelTests/Core/Command/DbDumpTest.php
PathEncodedTest::testAliasToEncoded in core/tests/Drupal/FunctionalTests/Routing/PathEncodedTest.php
RouteCachingNonPathLanguageNegotiationTest::testAliases in core/tests/Drupal/FunctionalTests/Routing/RouteCachingNonPathLanguageNegotiationTest.php
Tests aliases when the negotiated language is not in the path.
RouteProviderTest::testRouteCaching in core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php
Tests that route caching works.

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