3 namespace Drupal\Tests\taxonomy\Functional;
5 use Drupal\node\Entity\Node;
6 use Drupal\taxonomy\Tests\TaxonomyTranslationTestTrait;
9 * Tests the translation of taxonomy terms field on nodes.
13 class TermTranslationFieldViewTest extends TaxonomyTestBase {
15 use TaxonomyTranslationTestTrait;
18 * The term that should be translated.
20 * @var \Drupal\taxonomy\Entity\Term
25 * The tag in the source language.
29 protected $baseTagName = 'OriginalTagName';
32 * The translated value for the tag.
36 protected $translatedTagName = 'TranslatedTagName';
43 public static $modules = ['language', 'content_translation', 'taxonomy'];
45 protected function setUp() {
47 $this->setupLanguages();
48 $this->vocabulary = $this->createVocabulary();
49 $this->enableTranslation();
51 $this->setUpTermReferenceField();
56 * Tests if the translated taxonomy term is displayed.
58 public function testTranslatedTaxonomyTermReferenceDisplay() {
59 $path = 'node/' . $this->node->id();
60 $translation_path = $this->translateToLangcode . '/' . $path;
62 $this->drupalGet($path);
63 $this->assertNoText($this->translatedTagName);
64 $this->assertText($this->baseTagName);
65 $this->drupalGet($translation_path);
66 $this->assertText($this->translatedTagName);
67 $this->assertNoText($this->baseTagName);
71 * Creates a test subject node, with translation.
73 protected function setUpNode() {
74 /** @var \Drupal\node\Entity\Node $node */
75 $node = Node::create([
76 'title' => $this->randomMachineName(),
79 'value' => $this->randomMachineName(),
80 'format' => 'basic_html'
82 $this->termFieldName => [['target_id' => $this->term->id()]],
83 'langcode' => $this->baseLangcode,
86 $node->addTranslation($this->translateToLangcode, $node->toArray());
92 * Creates a test subject term, with translation.
94 protected function setUpTerm() {
95 $this->term = $this->createTerm($this->vocabulary, [
96 'name' => $this->baseTagName,
97 'langcode' => $this->baseLangcode,
100 $this->term->addTranslation($this->translateToLangcode, [
101 'name' => $this->translatedTagName,