You are here

public function MigrateTaxonomyTermTest::testTaxonomyTerms in Drupal 10

Same name in this branch
  1. 10 core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\d6\MigrateTaxonomyTermTest::testTaxonomyTerms()
  2. 10 core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\d7\MigrateTaxonomyTermTest::testTaxonomyTerms()
Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\d7\MigrateTaxonomyTermTest::testTaxonomyTerms()
  2. 9 core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\d7\MigrateTaxonomyTermTest::testTaxonomyTerms()

Tests the Drupal 7 taxonomy term to Drupal 8 migration.

File

core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php, line 112

Class

MigrateTaxonomyTermTest
Upgrade taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Kernel\Migrate\d7

Code

public function testTaxonomyTerms() {
  $this
    ->assertEntity(1, 'en', 'General discussion', 'forums', '', NULL, 2);

  // Tests that terms that used the Drupal 7 Title module and that have their
  // name and description replaced by real fields are correctly migrated.
  $this
    ->assertEntity(2, 'en', 'Term1 (This is a real field!)', 'test_vocabulary', 'The first term. (This is a real field!)', 'filtered_html', 0, [], NULL, 3);
  $this
    ->assertEntity(3, 'en', 'Term2', 'test_vocabulary', 'The second term.', 'filtered_html');
  $this
    ->assertEntity(4, 'en', 'Term3 in plain old English', 'test_vocabulary', 'The third term in plain old English.', 'full_html', 0, [
    3,
  ], 6);
  $this
    ->assertEntity(5, 'en', 'Custom Forum', 'forums', 'Where the cool kids are.', NULL, 3);
  $this
    ->assertEntity(6, 'en', 'Games', 'forums', NULL, '', 4, []);
  $this
    ->assertEntity(7, 'en', 'Minecraft', 'forums', '', NULL, 1, [
    6,
  ]);
  $this
    ->assertEntity(8, 'en', 'Half Life 3', 'forums', '', NULL, 0, [
    6,
  ]);

  // Verify that we still can create forum containers after the migration.
  $term = Term::create([
    'vid' => 'forums',
    'name' => 'Forum Container',
    'forum_container' => 1,
  ]);
  $term
    ->save();

  // Reset the forums tree data so this new term is included in the tree.
  unset($this->treeData['forums']);
  $this
    ->assertEntity(26, 'en', 'Forum Container', 'forums', '', '', 0, [], NULL, NULL, 1);

  // Test taxonomy term language translations.
  $this
    ->assertEntity(19, 'en', 'Jupiter Station', 'vocablocalized', 'Holographic research.', 'filtered_html', 0, [], NULL, NULL, 1);
  $this
    ->assertEntity(20, 'en', 'DS9', 'vocablocalized', 'Terok Nor', 'filtered_html', 0, [], NULL, NULL, 1);
  $this
    ->assertEntity(21, 'en', 'High council', 'vocabtranslate', NULL, NULL, 0, [], NULL, NULL, 1);
  $this
    ->assertEntity(22, 'fr', 'fr - High council', 'vocabtranslate', NULL, NULL, 0, [], NULL, NULL, 1);
  $this
    ->assertEntity(23, 'is', 'is - High council', 'vocabtranslate', NULL, NULL, 0, [], NULL, NULL, 1);
  $this
    ->assertEntity(24, 'fr', 'FR - Crewman', 'vocabfixed', NULL, NULL, 0, [], NULL, NULL, 1);

  // Localized.
  $this
    ->assertEntity(19, 'en', 'Jupiter Station', 'vocablocalized', 'Holographic research.', 'filtered_html', '0', []);
  $this
    ->assertEntity(20, 'en', 'DS9', 'vocablocalized', 'Terok Nor', 'filtered_html', '0', []);
  $this
    ->assertEntity(25, 'en', 'Emissary', 'vocablocalized2', 'Pilot episode', 'filtered_html', '0', []);

  /** @var \Drupal\taxonomy\TermInterface $entity */
  $entity = Term::load(20);
  $this
    ->assertSame('Bajor', $entity->field_sector->value);

  // Translate.
  $this
    ->assertEntity(21, 'en', 'High council', 'vocabtranslate', NULL, NULL, '0', []);
  $entity = Term::load(21);
  $this
    ->assertSame("K'mpec", $entity->field_chancellor->value);
  $this
    ->assertEntity(22, 'fr', 'fr - High council', 'vocabtranslate', NULL, NULL, '0', []);
  $this
    ->assertEntity(23, 'is', 'is - High council', 'vocabtranslate', NULL, NULL, '0', []);

  // Fixed.
  $this
    ->assertEntity(24, 'fr', 'FR - Crewman', 'vocabfixed', NULL, NULL, '0', []);

  // Tests the migration of taxonomy term entity translations.
  $manager = $this->container
    ->get('content_translation.manager');

  // Get the term and its translations.
  $term = Term::load(4);
  $term_fr = $term
    ->getTranslation('fr');
  $term_is = $term
    ->getTranslation('is');

  // Test that fields translated with Entity Translation are migrated.
  $this
    ->assertSame('Term3 in plain old English', $term
    ->getName());
  $this
    ->assertSame('Term3 en français s\'il vous plaît', $term_fr
    ->getName());
  $this
    ->assertSame('Term3 á íslensku', $term_is
    ->getName());
  $this
    ->assertSame('The third term in plain old English.', $term
    ->getDescription());
  $this
    ->assertSame('The third term en français s\'il vous plaît.', $term_fr
    ->getDescription());
  $this
    ->assertSame('The third term á íslensku.', $term_is
    ->getDescription());
  $this
    ->assertSame('full_html', $term
    ->getFormat());
  $this
    ->assertSame('filtered_html', $term_fr
    ->getFormat());
  $this
    ->assertSame('plain_text', $term_is
    ->getFormat());
  $this
    ->assertSame('6', $term->field_integer->value);
  $this
    ->assertSame('5', $term_fr->field_integer->value);
  $this
    ->assertSame('4', $term_is->field_integer->value);

  // Test that the French translation metadata is correctly migrated.
  $metadata_fr = $manager
    ->getTranslationMetadata($term_fr);
  $this
    ->assertTrue($metadata_fr
    ->isPublished());
  $this
    ->assertSame('en', $metadata_fr
    ->getSource());
  $this
    ->assertSame('2', $metadata_fr
    ->getAuthor()->uid->value);
  $this
    ->assertSame('1531922267', $metadata_fr
    ->getCreatedTime());
  $this
    ->assertSame('1531922268', $metadata_fr
    ->getChangedTime());
  $this
    ->assertTrue($metadata_fr
    ->isOutdated());

  // Test that the Icelandic translation metadata is correctly migrated.
  $metadata_is = $manager
    ->getTranslationMetadata($term_is);
  $this
    ->assertFalse($metadata_is
    ->isPublished());
  $this
    ->assertSame('en', $metadata_is
    ->getSource());
  $this
    ->assertSame('1', $metadata_is
    ->getAuthor()->uid->value);
  $this
    ->assertSame('1531922278', $metadata_is
    ->getCreatedTime());
  $this
    ->assertSame('1531922279', $metadata_is
    ->getChangedTime());
  $this
    ->assertFalse($metadata_is
    ->isOutdated());

  // Test that untranslatable properties are the same as the source language.
  $this
    ->assertSame($term
    ->bundle(), $term_fr
    ->bundle());
  $this
    ->assertSame($term
    ->bundle(), $term_is
    ->bundle());
  $this
    ->assertSame($term
    ->getWeight(), $term_fr
    ->getWeight());
  $this
    ->assertSame($term
    ->getWeight(), $term_is
    ->getWeight());
  $this
    ->assertSame($term->parent->terget_id, $term_fr->parent->terget_id);
  $this
    ->assertSame($term->parent->terget_id, $term_is->parent->terget_id);
}