You are here

protected function ShortcutTranslationUITest::doTestBasicTranslation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php \Drupal\shortcut\Tests\ShortcutTranslationUITest::doTestBasicTranslation()

Tests the basic translation workflow.

Overrides ContentTranslationUITestBase::doTestBasicTranslation

File

core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php, line 70
Contains \Drupal\shortcut\Tests\ShortcutTranslationUITest.

Class

ShortcutTranslationUITest
Tests the shortcut translation UI.

Namespace

Drupal\shortcut\Tests

Code

protected function doTestBasicTranslation() {
  parent::doTestBasicTranslation();
  $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
  foreach ($this->langcodes as $langcode) {
    if ($entity
      ->hasTranslation($langcode)) {
      $language = new Language(array(
        '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>', array(
        'language' => $language,
      ));
      $expected_path = \Drupal::urlGenerator()
        ->generateFromRoute('user.page', array(), array(
        '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]', array(
        ':href' => $expected_path,
        ':label' => $label,
      ));
      $this
        ->assertTrue(!empty($elements), format_string('Translated @language shortcut link @label found.', array(
        '@label' => $label,
        '@language' => $language
          ->getName(),
      )));
    }
  }
}