Upgraded drupal core with security updates
[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         'value' => $this->randomMachineName(),
79         'format' => 'basic_html'
80       ]],
81       $this->termFieldName => [['target_id' => $this->term->id()]],
82       'langcode' => $this->baseLangcode,
83     ]);
84     $node->save();
85     $node->addTranslation($this->translateToLangcode, $node->toArray());
86     $node->save();
87     $this->node = $node;
88   }
89
90   /**
91    * Creates a test subject term, with translation.
92    */
93   protected function setUpTerm() {
94     $this->term = $this->createTerm($this->vocabulary, [
95       'name' => $this->baseTagName,
96       'langcode' => $this->baseLangcode,
97     ]);
98
99     $this->term->addTranslation($this->translateToLangcode, [
100       'name' => $this->translatedTagName,
101     ]);
102     $this->term->save();
103   }
104
105 }