function ShortcutTranslationUITest::doTestBasicTranslation

Same name in other branches
  1. 9 core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php \Drupal\Tests\shortcut\Functional\ShortcutTranslationUITest::doTestBasicTranslation()
  2. 10 core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php \Drupal\Tests\shortcut\Functional\ShortcutTranslationUITest::doTestBasicTranslation()
  3. 11.x core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php \Drupal\Tests\shortcut\Functional\ShortcutTranslationUITest::doTestBasicTranslation()

Overrides ContentTranslationUITestBase::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();
            $elements = $this->xpath('//nav[contains(@class, "toolbar-lining")]/ul[@class="toolbar-menu"]/li/a[contains(@href, :href) and normalize-space(text())=:label]', [
                ':href' => $expected_path,
                ':label' => $label,
            ]);
            $this->assertTrue(!empty($elements), new FormattableMarkup('Translated @language shortcut link @label found.', [
                '@label' => $label,
                '@language' => $language->getName(),
            ]));
        }
    }
}

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