You are here

public function MigrateTaxonomyTermTest::testTaxonomyTerms in Zircon Profile 8

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

Tests the Drupal 6 taxonomy term to Drupal 8 migration.

File

core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTaxonomyTermTest.php, line 37
Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTaxonomyTermTest.

Class

MigrateTaxonomyTermTest
Upgrade taxonomy terms.

Namespace

Drupal\taxonomy\Tests\Migrate\d6

Code

public function testTaxonomyTerms() {
  $expected_results = array(
    '1' => array(
      'source_vid' => 1,
      'vid' => 'vocabulary_1_i_0_',
      'weight' => 0,
      'parent' => array(
        0,
      ),
    ),
    '2' => array(
      'source_vid' => 2,
      'vid' => 'vocabulary_2_i_1_',
      'weight' => 3,
      'parent' => array(
        0,
      ),
    ),
    '3' => array(
      'source_vid' => 2,
      'vid' => 'vocabulary_2_i_1_',
      'weight' => 4,
      'parent' => array(
        2,
      ),
    ),
    '4' => array(
      'source_vid' => 3,
      'vid' => 'vocabulary_3_i_2_',
      'weight' => 6,
      'parent' => array(
        0,
      ),
    ),
    '5' => array(
      'source_vid' => 3,
      'vid' => 'vocabulary_3_i_2_',
      'weight' => 7,
      'parent' => array(
        4,
      ),
    ),
    '6' => array(
      'source_vid' => 3,
      'vid' => 'vocabulary_3_i_2_',
      'weight' => 8,
      'parent' => array(
        4,
        5,
      ),
    ),
  );
  $terms = Term::loadMultiple(array_keys($expected_results));
  foreach ($expected_results as $tid => $values) {

    /** @var Term $term */
    $term = $terms[$tid];
    $this
      ->assertIdentical("term {$tid} of vocabulary {$values['source_vid']}", $term->name->value);
    $this
      ->assertIdentical("description of term {$tid} of vocabulary {$values['source_vid']}", $term->description->value);
    $this
      ->assertIdentical($values['vid'], $term->vid->target_id);
    $this
      ->assertIdentical((string) $values['weight'], $term->weight->value);
    if ($values['parent'] === array(
      0,
    )) {
      $this
        ->assertNull($term->parent->target_id);
    }
    else {
      $parents = array();
      foreach (\Drupal::entityManager()
        ->getStorage('taxonomy_term')
        ->loadParents($tid) as $parent) {
        $parents[] = (int) $parent
          ->id();
      }
      $this
        ->assertIdentical($parents, $values['parent']);
    }
  }
}