You are here

public function TermLanguageTest::testTermTranslatedOnOverviewPage in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php \Drupal\Tests\taxonomy\Functional\TermLanguageTest::testTermTranslatedOnOverviewPage()

Tests that translated terms are displayed correctly on the term overview.

File

core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php, line 125

Class

TermLanguageTest
Tests the language functionality for the taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Functional

Code

public function testTermTranslatedOnOverviewPage() {

  // Configure the vocabulary to not hide the language selector.
  $edit = [
    'default_language[language_alterable]' => TRUE,
  ];
  $this
    ->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id());
  $this
    ->submitForm($edit, 'Save');

  // Add a term.
  $this
    ->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/add');

  // Submit the term.
  $edit = [
    'name[0][value]' => $this
      ->randomMachineName(),
    'langcode[0][value]' => 'aa',
  ];
  $this
    ->submitForm($edit, 'Save');
  $terms = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term')
    ->loadByProperties([
    'name' => $edit['name[0][value]'],
  ]);
  $term = reset($terms);

  // Add a translation for that term.
  $translated_title = $this
    ->randomMachineName();
  $term
    ->addTranslation('bb', [
    'name' => $translated_title,
  ]);
  $term
    ->save();

  // Overview page in the other language shows the translated term
  $this
    ->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/overview');
  $this
    ->assertSession()
    ->responseMatches('|<a[^>]*>' . $translated_title . '</a>|');
}