View source
<?php
namespace Drupal\taxonomy\Tests\Migrate\d7;
use Drupal\taxonomy\Entity\Term;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
use Drupal\taxonomy\TermInterface;
class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
public static $modules = array(
'taxonomy',
'text',
);
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('taxonomy_term');
$this
->executeMigrations([
'd7_taxonomy_vocabulary',
'd7_taxonomy_term',
]);
}
protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_weight = 0, $expected_parents = []) {
$entity = Term::load($id);
$this
->assertTrue($entity instanceof TermInterface);
$this
->assertIdentical($expected_label, $entity
->label());
$this
->assertIdentical($expected_vid, $entity
->getVocabularyId());
$this
->assertEqual($expected_description, $entity
->getDescription());
$this
->assertEqual($expected_weight, $entity
->getWeight());
$this
->assertIdentical($expected_parents, $this
->getParentIDs($id));
}
public function testTaxonomyTerms() {
$this
->assertEntity(1, 'General discussion', 'forums', '', 2);
$this
->assertEntity(2, 'Term1', 'test_vocabulary', 'The first term.');
$this
->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.');
$this
->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 0, [
3,
]);
$this
->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', 3);
$this
->assertEntity(6, 'Games', 'forums', '', 4);
$this
->assertEntity(7, 'Minecraft', 'forums', '', 1, [
6,
]);
$this
->assertEntity(8, 'Half Life 3', 'forums', '', 0, [
6,
]);
}
protected function getParentIDs($tid) {
return array_keys(\Drupal::entityManager()
->getStorage('taxonomy_term')
->loadParents($tid));
}
}