function TermLanguageTest::testTermTranslatedOnOverviewPage

Same name in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php \Drupal\Tests\taxonomy\Functional\TermLanguageTest::testTermTranslatedOnOverviewPage()
  2. 8.9.x core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php \Drupal\Tests\taxonomy\Functional\TermLanguageTest::testTermTranslatedOnOverviewPage()
  3. 11.x 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 133

Class

TermLanguageTest
Tests the language functionality for the taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Functional

Code

public function testTermTranslatedOnOverviewPage() : void {
    // 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>|');
}

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