You are here

protected function ContentTranslationUITestBase::doTestTranslationOverview in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestTranslationOverview()
  2. 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 217

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,
      ]);

      // Test that label is correctly shown for translation.
      $view_url = $entity
        ->toUrl('canonical', [
        'language' => $language,
      ])
        ->toString();
      $this
        ->assertSession()
        ->elementTextEquals('xpath', "//table//a[@href='{$view_url}']", $entity
        ->getTranslation($langcode)
        ->label() ?? $entity
        ->getTranslation($langcode)
        ->id());

      // Test that edit link is correct for translation.
      $edit_path = $entity
        ->toUrl('edit-form', [
        'language' => $language,
      ])
        ->toString();
      $this
        ->assertSession()
        ->elementTextEquals('xpath', "//table//ul[@class='dropbutton']/li/a[@href='{$edit_path}']", 'Edit');
    }
  }
}