function PathAliasTestTrait::assertPathAliasExists

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Traits/Core/PathAliasTestTrait.php \Drupal\Tests\Traits\Core\PathAliasTestTrait::assertPathAliasExists()
  2. 10 core/tests/Drupal/Tests/Traits/Core/PathAliasTestTrait.php \Drupal\Tests\Traits\Core\PathAliasTestTrait::assertPathAliasExists()
  3. 11.x core/tests/Drupal/Tests/Traits/Core/PathAliasTestTrait.php \Drupal\Tests\Traits\Core\PathAliasTestTrait::assertPathAliasExists()

Asserts that a path alias exists in the storage.

Parameters

string $alias: The path alias.

string|null $langcode: (optional) The language code of the path alias.

string|null $path: (optional) The system path of the path alias.

string|null $message: (optional) A message to display with the assertion.

1 call to PathAliasTestTrait::assertPathAliasExists()
PathLanguageTest::testAliasTranslation in core/modules/path/tests/src/Functional/PathLanguageTest.php
Tests alias functionality through the admin interfaces.

File

core/tests/Drupal/Tests/Traits/Core/PathAliasTestTrait.php, line 72

Class

PathAliasTestTrait
Provides methods to create and assert path_alias entities.

Namespace

Drupal\Tests\Traits\Core

Code

protected function assertPathAliasExists($alias, $langcode = NULL, $path = NULL, $message = '') {
    $query = \Drupal::entityTypeManager()->getStorage('path_alias')
        ->getQuery()
        ->accessCheck(FALSE);
    $query->condition('alias', $alias, '=');
    if ($langcode) {
        $query->condition('langcode', $langcode, '=');
    }
    if ($path) {
        $query->condition('path', $path, '=');
    }
    $query->count();
    $this->assertTrue((bool) $query->execute(), $message);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.