summaryrefslogtreecommitdiffstats
path: root/core/modules/migrate_drupal/src/Tests/d6/MigrateTaxonomyVocabularyTest.php
blob: 0995ecfbd2ceb59877c7f425657d525938147c59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php

/**
 * @file
 * Contains \Drupal\migrate_drupal\Tests\d6\MigrateTaxonomyVocabularyTest.
 */

namespace Drupal\migrate_drupal\Tests\d6;

use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;

/**
 * Migrate taxonomy vocabularies to taxonomy.vocabulary.*.yml.
 *
 * @group migrate_drupal
 */
class MigrateTaxonomyVocabularyTest extends MigrateDrupalTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('taxonomy');

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $migration = entity_load('migration', 'd6_taxonomy_vocabulary');
    $dumps = array(
      $this->getDumpDirectory() . '/Drupal6TaxonomyVocabulary.php',
    );
    $this->prepare($migration, $dumps);
    $executable = new MigrateExecutable($migration, $this);
    $executable->import();
  }

  /**
   * Tests the Drupal 6 taxonomy vocabularies to Drupal 8 migration.
   */
  public function testTaxonomyVocabulary() {
    for ($i = 0; $i < 3; $i++) {
      $j = $i + 1;
      $vocabulary = entity_load('taxonomy_vocabulary', "vocabulary_{$j}_i_{$i}_");
      $this->assertEqual(array($vocabulary->id()), entity_load('migration', 'd6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID(array($j)));
      $this->assertEqual($vocabulary->label(), "vocabulary $j (i=$i)");
      $this->assertEqual($vocabulary->getDescription(), "description of vocabulary $j (i=$i)");
      $this->assertEqual($vocabulary->getHierarchy(), $i);
      $this->assertEqual($vocabulary->get('weight'), 4 + $i);
    }
    $vocabulary = entity_load('taxonomy_vocabulary', 'vocabulary_name_much_longer_than');
    $this->assertEqual($vocabulary->label(), 'vocabulary name much longer than thirty two characters');
    $this->assertEqual($vocabulary->getDescription(), 'description of vocabulary name much longer than thirty two characters');
    $this->assertEqual($vocabulary->getHierarchy(), 3);
    $this->assertEqual($vocabulary->get('weight'), 7);
  }

}