You are here

protected function TermTranslationTest::setUpTerms in Drupal 10

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

Setup translated terms in a hierarchy.

File

core/modules/taxonomy/tests/src/Functional/TermTranslationTest.php, line 123

Class

TermTranslationTest
Tests for proper breadcrumb translation.

Namespace

Drupal\Tests\taxonomy\Functional

Code

protected function setUpTerms() {
  $parent_vid = 0;
  foreach ($this->termTranslationMap as $name => $translation) {
    $term = $this
      ->createTerm($this->vocabulary, [
      'name' => $name,
      'langcode' => $this->baseLangcode,
      'parent' => $parent_vid,
    ]);
    $term
      ->addTranslation($this->translateToLangcode, [
      'name' => $translation,
    ]);
    $term
      ->save();

    // Each term is nested under the last.
    $parent_vid = $term
      ->id();
    $this->terms[] = $term;
  }
}