3 namespace Drupal\Tests\taxonomy\Functional;
5 use Drupal\node\Entity\Node;
8 * Tests the translation of taxonomy terms field on nodes.
12 class TermTranslationFieldViewTest extends TaxonomyTestBase {
14 use TaxonomyTranslationTestTrait;
17 * The term that should be translated.
19 * @var \Drupal\taxonomy\Entity\Term
24 * The tag in the source language.
28 protected $baseTagName = 'OriginalTagName';
31 * The translated value for the tag.
35 protected $translatedTagName = 'TranslatedTagName';
42 public static $modules = ['language', 'content_translation', 'taxonomy'];
44 protected function setUp() {
46 $this->setupLanguages();
47 $this->vocabulary = $this->createVocabulary();
48 $this->enableTranslation();
50 $this->setUpTermReferenceField();
55 * Tests if the translated taxonomy term is displayed.
57 public function testTranslatedTaxonomyTermReferenceDisplay() {
58 $path = 'node/' . $this->node->id();
59 $translation_path = $this->translateToLangcode . '/' . $path;
61 $this->drupalGet($path);
62 $this->assertNoText($this->translatedTagName);
63 $this->assertText($this->baseTagName);
64 $this->drupalGet($translation_path);
65 $this->assertText($this->translatedTagName);
66 $this->assertNoText($this->baseTagName);
70 * Creates a test subject node, with translation.
72 protected function setUpNode() {
73 /** @var \Drupal\node\Entity\Node $node */
74 $node = Node::create([
75 'title' => $this->randomMachineName(),
78 'value' => $this->randomMachineName(),
79 'format' => 'basic_html'
81 $this->termFieldName => [['target_id' => $this->term->id()]],
82 'langcode' => $this->baseLangcode,
85 $node->addTranslation($this->translateToLangcode, $node->toArray());
91 * Creates a test subject term, with translation.
93 protected function setUpTerm() {
94 $this->term = $this->createTerm($this->vocabulary, [
95 'name' => $this->baseTagName,
96 'langcode' => $this->baseLangcode,
99 $this->term->addTranslation($this->translateToLangcode, [
100 'name' => $this->translatedTagName,