outline-8.x-1.x-dev/tests/src/Functional/EntryTranslationFieldViewTest.php
tests/src/Functional/EntryTranslationFieldViewTest.php
<?php
namespace Drupal\Tests\outline\Functional;
use Drupal\node\Entity\Node;
/**
* Tests the translation of outline entries field on nodes.
*
* @group outline
*/
class EntryTranslationFieldViewTest extends OutlineTestBase {
use OutlineTranslationTestTrait;
/**
* The entry that should be translated.
*
* @var \Drupal\outline\Entity\Entry
*/
protected $entry;
/**
* The tag in the source language.
*
* @var string
*/
protected $baseTagName = 'OriginalTagName';
/**
* The translated value for the tag.
*
* @var string
*/
protected $translatedTagName = 'TranslatedTagName';
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = ['language', 'content_translation', 'outline'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
protected function setUp(): void {
parent::setUp();
$this->setupLanguages();
$this->outline = $this->createOutline();
$this->enableTranslation();
$this->setUpEntry();
$this->setUpEntryReferenceField();
$this->setUpNode();
}
/**
* Tests if the translated outline entry is displayed.
*/
public function testTranslatedOutlineEntryReferenceDisplay() {
$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);
}
/**
* Creates a test subject node, with translation.
*/
protected function setUpNode() {
/** @var \Drupal\node\Entity\Node $node */
$node = Node::create([
'title' => $this->randomMachineName(),
'type' => 'article',
'description' => [
[
'value' => $this->randomMachineName(),
'format' => 'basic_html',
],
],
$this->entryFieldName => [['target_id' => $this->entry->id()]],
'langcode' => $this->baseLangcode,
]);
$node->save();
$node->addTranslation($this->translateToLangcode, $node->toArray());
$node->save();
$this->node = $node;
}
/**
* Creates a test subject entry, with translation.
*/
protected function setUpEntry() {
$this->entry = $this->createEntry($this->outline, [
'name' => $this->baseTagName,
'langcode' => $this->baseLangcode,
]);
$this->entry->addTranslation($this->translateToLangcode, [
'name' => $this->translatedTagName,
]);
$this->entry->save();
}
}
