public function TranslationTest::testTranslation in Feeds 8.3
Tests importing content with Spanish translation.
File
- tests/
src/ Kernel/ Feeds/ Target/ TranslationTest.php, line 122
Class
- TranslationTest
- Test for the entity field translation.
Namespace
Drupal\Tests\feeds\Kernel\Feeds\TargetCode
public function testTranslation() {
// Add mappings for Spanish.
$this
->addMappings($this
->getMappingsInLanguage('es', '_es'));
$this->feedType
->save();
// Import file that contains both English and Spanish content.
$this
->importContent($this
->resourcesPath() . '/csv/translation/content_es_nl.csv');
$this
->assertNodeCount(1);
// Check values on main node.
$node = Node::load(1);
$this
->assertEquals('HELLO WORLD', $node->title->value);
$this
->assertEmpty($node->field_tags
->referencedEntities());
// Inspect Spanish values.
$this
->assertTrue($node
->hasTranslation('es'));
$translation = $node
->getTranslation('es');
$this
->assertEquals('HOLA MUNDO', $translation->title->value);
$this
->assertEquals('Este es el texto del cuerpo.', $translation->field_alpha->value);
$this
->assertEquals($node->uid->value, $translation->uid->value);
$this
->assertNotEmpty($translation->field_tags
->referencedEntities());
$referenced_entities = $translation->field_tags
->referencedEntities();
$first_tag = reset($referenced_entities);
$this
->assertEquals('Termino de taxonomía', $first_tag->name->value);
}