Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / taxonomy / tests / src / Functional / TermTranslationFieldViewTest.php
1 <?php
2
3 namespace Drupal\Tests\taxonomy\Functional;
4
5 use Drupal\node\Entity\Node;
6
7 /**
8  * Tests the translation of taxonomy terms field on nodes.
9  *
10  * @group taxonomy
11  */
12 class TermTranslationFieldViewTest extends TaxonomyTestBase {
13
14   use TaxonomyTranslationTestTrait;
15
16   /**
17    * The term that should be translated.
18    *
19    * @var \Drupal\taxonomy\Entity\Term
20    */
21   protected $term;
22
23   /**
24    * The tag in the source language.
25    *
26    * @var string
27    */
28   protected $baseTagName = 'OriginalTagName';
29
30   /**
31    * The translated value for the tag.
32    *
33    * @var string
34    */
35   protected $translatedTagName = 'TranslatedTagName';
36
37   /**
38    * Modules to enable.
39    *
40    * @var array
41    */
42   public static $modules = ['language', 'content_translation', 'taxonomy'];
43
44   protected function setUp() {
45     parent::setUp();
46     $this->setupLanguages();
47     $this->vocabulary = $this->createVocabulary();
48     $this->enableTranslation();
49     $this->setUpTerm();
50     $this->setUpTermReferenceField();
51     $this->setUpNode();
52   }
53
54   /**
55    * Tests if the translated taxonomy term is displayed.
56    */
57   public function testTranslatedTaxonomyTermReferenceDisplay() {
58     $path = 'node/' . $this->node->id();
59     $translation_path = $this->translateToLangcode . '/' . $path;
60
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);
67   }
68
69   /**
70    * Creates a test subject node, with translation.
71    */
72   protected function setUpNode() {
73     /** @var \Drupal\node\Entity\Node $node */
74     $node = Node::create([
75       'title' => $this->randomMachineName(),
76       'type' => 'article',
77       'description' => [
78         [
79           'value' => $this->randomMachineName(),
80           'format' => 'basic_html',
81         ],
82       ],
83       $this->termFieldName => [['target_id' => $this->term->id()]],
84       'langcode' => $this->baseLangcode,
85     ]);
86     $node->save();
87     $node->addTranslation($this->translateToLangcode, $node->toArray());
88     $node->save();
89     $this->node = $node;
90   }
91
92   /**
93    * Creates a test subject term, with translation.
94    */
95   protected function setUpTerm() {
96     $this->term = $this->createTerm($this->vocabulary, [
97       'name' => $this->baseTagName,
98       'langcode' => $this->baseLangcode,
99     ]);
100
101     $this->term->addTranslation($this->translateToLangcode, [
102       'name' => $this->translatedTagName,
103     ]);
104     $this->term->save();
105   }
106
107 }