TermTranslationFieldViewTest.php in Zircon Profile 8
File
core/modules/taxonomy/src/Tests/TermTranslationFieldViewTest.php
View source
<?php
namespace Drupal\taxonomy\Tests;
class TermTranslationFieldViewTest extends TaxonomyTestBase {
use TaxonomyTranslationTestTrait;
protected $term;
protected $baseTagName = 'OriginalTagName';
protected $translatedTagName = 'TranslatedTagName';
public static $modules = array(
'language',
'content_translation',
'taxonomy',
);
protected function setUp() {
parent::setUp();
$this
->setupLanguages();
$this->vocabulary = $this
->createVocabulary();
$this
->enableTranslation();
$this
->setUpTerm();
$this
->setUpTermReferenceField();
$this
->setUpNode();
}
public function testTranslatedTaxonomyTermReferenceDisplay() {
$path = 'node/' . $this->node
->id();
$translation_path = $this->translateToLangcode . '/' . $path;
$this
->drupalGet($path);
$this
->assertNoText($this->translatedTagName);
$this
->assertText($this->baseTagName);
$this
->drupalGet($translation_path);
$this
->assertText($this->translatedTagName);
$this
->assertNoText($this->baseTagName);
}
protected function setUpNode() {
$node = entity_create('node', array(
'title' => $this
->randomMachineName(),
'type' => 'article',
'description' => array(
'value' => $this
->randomMachineName(),
'format' => 'basic_html',
),
$this->termFieldName => array(
array(
'target_id' => $this->term
->id(),
),
),
'langcode' => $this->baseLangcode,
));
$node
->save();
$node
->addTranslation($this->translateToLangcode, $node
->toArray());
$node
->save();
$this->node = $node;
}
protected function setUpTerm() {
$this->term = $this
->createTerm($this->vocabulary, array(
'name' => $this->baseTagName,
'langcode' => $this->baseLangcode,
));
$this->term
->addTranslation($this->translateToLangcode, array(
'name' => $this->translatedTagName,
));
$this->term
->save();
}
}