You are here

function TaxonomyTest::testMultilingualTerms in Token 8

Test the multilingual terms.

File

tests/src/Kernel/TaxonomyTest.php, line 125

Class

TaxonomyTest
Tests taxonomy tokens.

Namespace

Drupal\Tests\token\Kernel

Code

function testMultilingualTerms() {

  // Add a second language.
  $language = ConfigurableLanguage::createFromLangcode('de');
  $language
    ->save();

  // Create an english parent term and add a german translation for it.
  $parent_term = $this
    ->addTerm($this->vocab, [
    'name' => 'english-parent-term',
    'langcode' => 'en',
  ]);
  $parent_term
    ->addTranslation('de', [
    'name' => 'german-parent-term',
  ])
    ->save();

  // Create a term related to the parent term.
  $child_term = $this
    ->addTerm($this->vocab, [
    'name' => 'english-child-term',
    'langcode' => 'en',
    'parent' => $parent_term
      ->id(),
  ]);
  $child_term
    ->addTranslation('de', [
    'name' => 'german-child-term',
  ])
    ->save();

  // Expect the parent term to be in the specified language.
  $this
    ->assertTokens('term', [
    'term' => $child_term,
  ], [
    'parents' => 'german-parent-term',
  ], [
    'langcode' => 'de',
  ]);
  $this
    ->assertTokens('term', [
    'term' => $child_term,
  ], [
    'root' => 'german-parent-term',
  ], [
    'langcode' => 'de',
  ]);
}