You are here

public function TranslationTest::testAutocreatedTermLanguage in Feeds 8.3

Tests if auto-created terms are imported in the configured language.

This test uses a vocabulary that is configured to be multilingual. On the feed type, there is being mapped to a taxonomy reference target. This target is configured as follows:

  • Language is set to Spanish;
  • Auto-create option is enabled.

A Spanish value is imported into the taxonomy reference field that does not exist in the vocabulary yet. It is expected that a term gets created in the vocabulary and that it gets the Spanish language assigned.

File

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

Class

TranslationTest
Test for the entity field translation.

Namespace

Drupal\Tests\feeds\Kernel\Feeds\Target

Code

public function testAutocreatedTermLanguage() {

  // Make the vocabulary to test with multilingual.
  $this->container
    ->get('content_translation.manager')
    ->setEnabled('taxonomy_term', $this->vocabulary
    ->id(), TRUE);

  // Add mappings for Spanish.
  $this
    ->addMappings($this
    ->getMappingsInLanguage('es'));
  $this->feedType
    ->save();

  // Import Spanish content.
  $this
    ->importContent($this
    ->resourcesPath() . '/csv/translation/content_es.csv');
  $this
    ->assertNodeCount(1);

  // Assert that the created term is in the Spanish language.
  $term = Term::load(1);
  $this
    ->assertEquals('Termino de taxonomía', $term->name->value);
  $this
    ->assertEquals('es', $term->langcode->value);
}