function ContentTranslationUITestBase::doTestTranslationOverview

Same name in this branch
  1. 8.9.x core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php \Drupal\content_translation\Tests\ContentTranslationUITestBase::doTestTranslationOverview()
Same name and namespace in other branches
  1. 11.x core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestTranslationOverview()
  2. 10 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestTranslationOverview()
  3. 9 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestTranslationOverview()

Tests that the translation overview shows the correct values.

File

core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php, line 213

Class

ContentTranslationUITestBase
Tests the Content Translation UI.

Namespace

Drupal\Tests\content_translation\Functional

Code

protected function doTestTranslationOverview() {
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage($this->entityTypeId);
  $storage->resetCache([
    $this->entityId,
  ]);
  $entity = $storage->load($this->entityId);
  $translate_url = $entity->toUrl('drupal:content-translation-overview');
  $this->drupalGet($translate_url);
  $translate_url->setAbsolute(FALSE);
  foreach ($this->langcodes as $langcode) {
    if ($entity->hasTranslation($langcode)) {
      $language = new Language([
        'id' => $langcode,
      ]);
      $view_url = $entity->toUrl('canonical', [
        'language' => $language,
      ])
        ->toString();
      $elements = $this->xpath('//table//a[@href=:href]', [
        ':href' => $view_url,
      ]);
      $this->assertEqual($elements[0]->getText(), $entity->getTranslation($langcode)
        ->label(), new FormattableMarkup('Label correctly shown for %language translation.', [
        '%language' => $langcode,
      ]));
      $edit_path = $entity->toUrl('edit-form', [
        'language' => $language,
      ])
        ->toString();
      $elements = $this->xpath('//table//ul[@class="dropbutton"]/li/a[@href=:href]', [
        ':href' => $edit_path,
      ]);
      $this->assertEqual($elements[0]->getText(), t('Edit'), new FormattableMarkup('Edit link correct for %language translation.', [
        '%language' => $langcode,
      ]));
    }
  }
}

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