You are here

public function TranslationTest::testValuesForMultipleLanguagesAreImported in Feeds 8.3

Tests importing values for multiple languages at once.

On the feed type, mappings are created for two languages: Spanish and Dutch. A file gets imported that has values for both languages. It is expected that for both these language values get imported.

File

tests/src/Kernel/Feeds/Target/TranslationTest.php, line 274

Class

TranslationTest
Test for the entity field translation.

Namespace

Drupal\Tests\feeds\Kernel\Feeds\Target

Code

public function testValuesForMultipleLanguagesAreImported() {

  // Add mappings for Spanish and Dutch.
  $this
    ->addMappings($this
    ->getMappingsInLanguage('es', '_es'));
  $this
    ->addMappings($this
    ->getMappingsInLanguage('nl', '_nl'));
  $this->feedType
    ->save();

  // Import file that has items with both Spanish and Dutch field values.
  $feed = $this
    ->importContent($this
    ->resourcesPath() . '/csv/translation/content_es_nl.csv');
  $this
    ->assertNodeCount(1);
  $node = Node::load(1);
  $this
    ->assertEquals('HELLO WORLD', $node->title->value);

  // Inspect Spanish values.
  $this
    ->assertTrue($node
    ->hasTranslation('es'));
  $spanish_translation = $node
    ->getTranslation('es');
  $this
    ->assertEquals('HOLA MUNDO', $spanish_translation->title->value);
  $this
    ->assertEquals('Este es el texto del cuerpo.', $spanish_translation->field_alpha->value);
  $this
    ->assertEquals($node->uid->value, $spanish_translation->uid->value);
  $this
    ->assertNotEmpty($spanish_translation->field_tags
    ->referencedEntities());
  $spanish_referenced_entities = $spanish_translation->field_tags
    ->referencedEntities();
  $spanish_translation_first_tag = reset($spanish_referenced_entities);
  $this
    ->assertEquals('Termino de taxonomía', $spanish_translation_first_tag->name->value);

  // Inspect Dutch values.
  $this
    ->assertTrue($node
    ->hasTranslation('nl'));
  $dutch_translation = $node
    ->getTranslation('nl');
  $this
    ->assertEquals('HALLO WERELD', $dutch_translation->title->value);
  $this
    ->assertEquals('Dit is de bodytekst.', $dutch_translation->field_alpha->value);
  $this
    ->assertNotEmpty($dutch_translation->field_tags
    ->referencedEntities());
  $dutch_referenced_entities = $dutch_translation->field_tags
    ->referencedEntities();
  $dutch_translation_first_tag = reset($dutch_referenced_entities);
  $this
    ->assertEquals('Taxonomieterm', $dutch_translation_first_tag->name->value);
}