You are here

protected function ShortcutTranslationUITest::doTestBasicTranslation in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php \Drupal\Tests\shortcut\Functional\ShortcutTranslationUITest::doTestBasicTranslation()
  2. 9 core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php \Drupal\Tests\shortcut\Functional\ShortcutTranslationUITest::doTestBasicTranslation()

File

core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php, line 71

Class

ShortcutTranslationUITest
Tests the shortcut translation UI.

Namespace

Drupal\Tests\shortcut\Functional

Code

protected function doTestBasicTranslation() {
  parent::doTestBasicTranslation();
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage($this->entityTypeId);
  $storage
    ->resetCache([
    $this->entityId,
  ]);
  $entity = $storage
    ->load($this->entityId);
  foreach ($this->langcodes as $langcode) {
    if ($entity
      ->hasTranslation($langcode)) {
      $language = new Language([
        'id' => $langcode,
      ]);

      // Request the front page in this language and assert that the right
      // translation shows up in the shortcut list with the right path.
      $this
        ->drupalGet('<front>', [
        'language' => $language,
      ]);
      $expected_path = \Drupal::urlGenerator()
        ->generateFromRoute('user.page', [], [
        'language' => $language,
      ]);
      $label = $entity
        ->getTranslation($langcode)
        ->label();
      $this
        ->assertSession()
        ->elementExists('xpath', "//nav[contains(@class, 'toolbar-lining')]/ul[@class='toolbar-menu']/li/a[contains(@href, '{$expected_path}') and normalize-space(text())='{$label}']");
    }
  }
}