diff --git a/core/modules/field/migration_templates/d7_field_instance.yml b/core/modules/field/migration_templates/d7_field_instance.yml index b6d2497..781c452 100644 --- a/core/modules/field/migration_templates/d7_field_instance.yml +++ b/core/modules/field/migration_templates/d7_field_instance.yml @@ -35,3 +35,4 @@ migration_dependencies: optional: - d7_node_type - d7_comment_type + - d7_taxonomy_vocabulary diff --git a/core/modules/migrate/src/Plugin/migrate/process/Iterator.php b/core/modules/migrate/src/Plugin/migrate/process/Iterator.php index 7affba9..10f1434 100644 --- a/core/modules/migrate/src/Plugin/migrate/process/Iterator.php +++ b/core/modules/migrate/src/Plugin/migrate/process/Iterator.php @@ -22,15 +22,17 @@ class Iterator extends ProcessPluginBase { * Runs a process pipeline on each destination property per list item. */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - $return = array(); - foreach ($value as $key => $new_value) { - $new_row = new Row($new_value, array()); - $migrate_executable->processRow($new_row, $this->configuration['process']); - $destination = $new_row->getDestination(); - if (array_key_exists('key', $this->configuration)) { - $key = $this->transformKey($key, $migrate_executable, $new_row); + $return = []; + if (!is_null($value)) { + foreach ($value as $key => $new_value) { + $new_row = new Row($new_value, []); + $migrate_executable->processRow($new_row, $this->configuration['process']); + $destination = $new_row->getDestination(); + if (array_key_exists('key', $this->configuration)) { + $key = $this->transformKey($key, $migrate_executable, $new_row); + } + $return[$key] = $destination; } - $return[$key] = $destination; } return $return; } @@ -49,7 +51,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable * The transformed key. */ protected function transformKey($key, MigrateExecutableInterface $migrate_executable, Row $row) { - $process = array('key' => $this->configuration['key']); + $process = ['key' => $this->configuration['key']]; $migrate_executable->processRow($row, $process, $key); return $row->getDestinationProperty('key'); } diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php index bbc8088..48fa5bb 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -3738,6 +3738,15 @@ 'data' => 'a:7:{s:5:"label";s:7:"Integer";s:6:"widget";a:5:{s:6:"weight";s:1:"2";s:4:"type";s:6:"number";s:6:"module";s:6:"number";s:6:"active";i:0;s:8:"settings";a:0:{}}s:8:"settings";a:5:{s:3:"min";s:0:"";s:3:"max";s:0:"";s:6:"prefix";s:0:"";s:6:"suffix";s:0:"";s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:14:"number_integer";s:8:"settings";a:4:{s:18:"thousand_separator";s:0:"";s:17:"decimal_separator";s:1:".";s:5:"scale";i:0;s:13:"prefix_suffix";b:1;}s:6:"module";s:6:"number";s:6:"weight";i:0;}}s:8:"required";i:0;s:11:"description";s:0:"";s:13:"default_value";N;}', 'deleted' => '0', )) +->values(array( + 'id' => '36', + 'field_id' => '20', + 'field_name' => 'field_term_reference', + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'data' => 'a:7:{s:5:"label";s:14:"Term Reference";s:6:"widget";a:5:{s:6:"weight";s:2:"14";s:4:"type";s:21:"taxonomy_autocomplete";s:6:"module";s:8:"taxonomy";s:6:"active";i:0;s:8:"settings";a:2:{s:4:"size";i:60;s:17:"autocomplete_path";s:21:"taxonomy/autocomplete";}}s:8:"settings";a:1:{s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:4:{s:5:"label";s:5:"above";s:4:"type";s:6:"hidden";s:6:"weight";s:2:"13";s:8:"settings";a:0:{}}}s:8:"required";i:0;s:11:"description";s:0:"";s:13:"default_value";N;}', + 'deleted' => '0', +)) ->execute(); $connection->schema()->createTable('field_data_body', array( @@ -4738,6 +4747,16 @@ 'delta' => '0', 'field_integer_value' => '5', )) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'und', + 'delta' => '0', + 'field_integer_value' => '6', +)) ->execute(); $connection->schema()->createTable('field_data_field_integer_list', array( @@ -5271,6 +5290,16 @@ 'delta' => '0', 'field_term_reference_tid' => '4', )) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '2', + 'revision_id' => '2', + 'language' => 'und', + 'delta' => '0', + 'field_term_reference_tid' => '3', +)) ->execute(); $connection->schema()->createTable('field_data_field_text', array( @@ -6516,6 +6545,16 @@ 'delta' => '0', 'field_integer_value' => '5', )) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'und', + 'delta' => '0', + 'field_integer_value' => '6', +)) ->execute(); $connection->schema()->createTable('field_revision_field_integer_list', array( @@ -7055,6 +7094,16 @@ 'delta' => '0', 'field_term_reference_tid' => '4', )) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '2', + 'revision_id' => '2', + 'language' => 'und', + 'delta' => '0', + 'field_term_reference_tid' => '3', +)) ->execute(); $connection->schema()->createTable('field_revision_field_text', array( diff --git a/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php b/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php index 6b30ade..beb3708 100644 --- a/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php +++ b/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php @@ -43,8 +43,8 @@ protected function getEntityCounts() { 'configurable_language' => 4, 'contact_form' => 3, 'editor' => 2, - 'field_config' => 43, - 'field_storage_config' => 32, + 'field_config' => 44, + 'field_storage_config' => 33, 'file' => 1, 'filter_format' => 7, 'image_style' => 6, @@ -66,9 +66,9 @@ protected function getEntityCounts() { 'menu_link_content' => 9, 'view' => 12, 'date_format' => 11, - 'entity_form_display' => 16, + 'entity_form_display' => 15, 'entity_form_mode' => 1, - 'entity_view_display' => 24, + 'entity_view_display' => 22, 'entity_view_mode' => 11, 'base_field_override' => 7, ]; diff --git a/core/modules/taxonomy/migration_templates/d6_taxonomy_term.yml b/core/modules/taxonomy/migration_templates/d6_taxonomy_term.yml index 44f9f7f..22bd441 100644 --- a/core/modules/taxonomy/migration_templates/d6_taxonomy_term.yml +++ b/core/modules/taxonomy/migration_templates/d6_taxonomy_term.yml @@ -3,7 +3,7 @@ label: Taxonomy terms migration_tags: - Drupal 6 source: - plugin: taxonomy_term + plugin: d6_taxonomy_term process: tid: tid vid: diff --git a/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml b/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml index 8d4adbb..c31c99a 100644 --- a/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml +++ b/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml @@ -2,8 +2,9 @@ id: d7_taxonomy_term label: Taxonomy terms migration_tags: - Drupal 7 +class: Drupal\taxonomy\Plugin\migrate\Term source: - plugin: taxonomy_term + plugin: d7_taxonomy_term process: tid: tid vid: @@ -33,3 +34,5 @@ destination: migration_dependencies: required: - d7_taxonomy_vocabulary + optional: + - d7_field_instance diff --git a/core/modules/taxonomy/src/Plugin/migrate/Term.php b/core/modules/taxonomy/src/Plugin/migrate/Term.php new file mode 100644 index 0000000..45a5661 --- /dev/null +++ b/core/modules/taxonomy/src/Plugin/migrate/Term.php @@ -0,0 +1,61 @@ +init) { + $this->init = TRUE; + $definition['source'] = [ + 'entity_type' => 'taxonomy_term', + 'ignore_map' => TRUE, + ] + $this->source; + $definition['destination']['plugin'] = 'null'; + if (\Drupal::moduleHandler()->moduleExists('field')) { + $definition['source']['plugin'] = 'd7_field_instance'; + $field_migration = $this->migrationPluginManager->createStubMigration($definition); + foreach ($field_migration->getSourcePlugin() as $row) { + $field_name = $row->getSourceProperty('field_name'); + $field_type = $row->getSourceProperty('type'); + if ($this->cckPluginManager->hasDefinition($field_type)) { + if (!isset($this->cckPluginCache[$field_type])) { + $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $this); + } + $info = $row->getSource(); + $this->cckPluginCache[$field_type] + ->processCckFieldValues($this, $field_name, $info); + } + else { + $this->process[$field_name] = $field_name; + } + } + } + try { + $definition['source']['plugin'] = 'profile_field'; + $profile_migration = $this->migrationPluginManager->createStubMigration($definition); + // Ensure that Profile is enabled in the source DB. + $profile_migration->checkRequirements(); + foreach ($profile_migration->getSourcePlugin() as $row) { + $name = $row->getSourceProperty('name'); + $this->process[$name] = $name; + } + } + catch (RequirementsException $e) { + // The checkRequirements() call will fail when the profile module does + // not exist on the source site. + } + } + return parent::getProcess(); + } + +} diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/Term.php b/core/modules/taxonomy/src/Plugin/migrate/source/Term.php deleted file mode 100644 index 0b2a5c3..0000000 --- a/core/modules/taxonomy/src/Plugin/migrate/source/Term.php +++ /dev/null @@ -1,100 +0,0 @@ -getModuleSchemaVersion('taxonomy') >= 7000) { - $this->termDataTable = 'taxonomy_term_data'; - $this->termHierarchyTable = 'taxonomy_term_hierarchy'; - } - else { - $this->termDataTable = 'term_data'; - $this->termHierarchyTable = 'term_hierarchy'; - } - - $query = $this->select($this->termDataTable, 'td') - ->fields('td') - ->distinct() - ->orderBy('td.tid'); - - if (isset($this->configuration['vocabulary'])) { - $query->condition('td.vid', $this->configuration['vocabulary'], 'IN'); - } - - return $query; - } - - /** - * {@inheritdoc} - */ - public function fields() { - $fields = array( - 'tid' => $this->t('The term ID.'), - 'vid' => $this->t('Existing term VID'), - 'name' => $this->t('The name of the term.'), - 'description' => $this->t('The term description.'), - 'weight' => $this->t('Weight'), - 'parent' => $this->t("The Drupal term IDs of the term's parents."), - ); - if ($this->getModuleSchemaVersion('taxonomy') >= 7000) { - $fields['format'] = $this->t('Format of the term description.'); - } - return $fields; - } - - /** - * {@inheritdoc} - */ - public function prepareRow(Row $row) { - // Find parents for this row. - $parents = $this->select($this->termHierarchyTable, 'th') - ->fields('th', array('parent', 'tid')) - ->condition('tid', $row->getSourceProperty('tid')) - ->execute() - ->fetchCol(); - $row->setSourceProperty('parent', $parents); - - return parent::prepareRow($row); - } - - /** - * {@inheritdoc} - */ - public function getIds() { - $ids['tid']['type'] = 'integer'; - return $ids; - } - -} diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php b/core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php new file mode 100644 index 0000000..d32c78a --- /dev/null +++ b/core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php @@ -0,0 +1,91 @@ +termDataTable = 'term_data'; + $this->termHierarchyTable = 'term_hierarchy'; + + $query = $this->select($this->termDataTable, 'td') + ->fields('td') + ->distinct() + ->orderBy('tid'); + + if (isset($this->configuration['vocabulary'])) { + $query->condition('vid', $this->configuration['vocabulary'], 'IN'); + } + + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + $fields = [ + 'tid' => $this->t('The term ID.'), + 'vid' => $this->t('Existing term VID'), + 'name' => $this->t('The name of the term.'), + 'description' => $this->t('The term description.'), + 'weight' => $this->t('Weight'), + 'parent' => $this->t("The Drupal term IDs of the term's parents."), + ]; + return $fields; + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + // Find parents for this row. + $parents = $this->select($this->termHierarchyTable, 'th') + ->fields('th', ['parent', 'tid']) + ->condition('tid', $row->getSourceProperty('tid')) + ->execute() + ->fetchCol(); + $row->setSourceProperty('parent', $parents); + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['tid']['type'] = 'integer'; + return $ids; + } + +} diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php b/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php new file mode 100644 index 0000000..c8488f1 --- /dev/null +++ b/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php @@ -0,0 +1,109 @@ +termDataTable = 'taxonomy_term_data'; + $this->termHierarchyTable = 'taxonomy_term_hierarchy'; + $this->vocabularyTable = 'taxonomy_vocabulary'; + + $query = $this->select($this->termDataTable, 'td') + ->fields('td') + ->distinct() + ->orderBy('tid'); + $query->leftJoin($this->vocabularyTable, 'tv', 'td.vid = tv.vid'); + $query->addField('tv', 'machine_name'); + + if (isset($this->configuration['vocabulary'])) { + $query->condition('td.vid', $this->configuration['vocabulary'], 'IN'); + } + + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + $fields = [ + 'tid' => $this->t('The term ID.'), + 'vid' => $this->t('Existing term VID'), + 'machine_name' => $this->t('Vocabulary machine name'), + 'name' => $this->t('The name of the term.'), + 'description' => $this->t('The term description.'), + 'weight' => $this->t('Weight'), + 'parent' => $this->t("The Drupal term IDs of the term's parents."), + 'format' => $this->t("Format of the term description."), + ]; + return $fields; + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + // Get Field API field values. + foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) { + $tid = $row->getSourceProperty('tid'); + $row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid)); + } + + // Find parents for this row. + $parents = $this->select($this->termHierarchyTable, 'th') + ->fields('th', ['parent', 'tid']) + ->condition('tid', $row->getSourceProperty('tid')) + ->execute() + ->fetchCol(); + $row->setSourceProperty('parent', $parents); + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['tid']['type'] = 'integer'; + return $ids; + } + +} diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php index c7e7828..4ee97c7 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php @@ -13,7 +13,16 @@ */ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase { - public static $modules = array('taxonomy', 'text'); + public static $modules = [ + 'comment', + 'datetime', + 'image', + 'link', + 'node', + 'taxonomy', + 'telephone', + 'text', + ]; /** * The cached taxonomy tree items, keyed by vid and tid. @@ -28,7 +37,16 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase { protected function setUp() { parent::setUp(); $this->installEntitySchema('taxonomy_term'); - $this->executeMigrations(['d7_taxonomy_vocabulary', 'd7_taxonomy_term']); + $this->installConfig(static::$modules); + + $this->executeMigrations([ + 'd7_node_type', + 'd7_comment_type', + 'd7_field', + 'd7_taxonomy_vocabulary', + 'd7_field_instance', + 'd7_taxonomy_term' + ]); } /** @@ -48,8 +66,10 @@ protected function setUp() { * The weight the migrated entity should have. * @param array $expected_parents * The parent terms the migrated entity should have. + * @param int $expected_field_integer_value + * The value the migrated entity field should have. */ - protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, $expected_parents = []) { + protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL) { /** @var \Drupal\taxonomy\TermInterface $entity */ $entity = Term::load($id); $this->assertTrue($entity instanceof TermInterface); @@ -60,6 +80,14 @@ protected function assertEntity($id, $expected_label, $expected_vid, $expected_d $this->assertEqual($expected_weight, $entity->getWeight()); $this->assertIdentical($expected_parents, $this->getParentIDs($id)); $this->assertHierarchy($expected_vid, $id, $expected_parents); + if (!is_null($expected_field_integer_value)) { + $this->assertTrue($entity->hasField('field_integer')); + $this->assertEquals($expected_field_integer_value, $entity->field_integer->value); + } + if (!is_null($expected_term_reference_tid)) { + $this->assertTrue($entity->hasField('field_integer')); + $this->assertEquals($expected_term_reference_tid, $entity->field_term_reference->target_id); + } } /** @@ -67,9 +95,9 @@ protected function assertEntity($id, $expected_label, $expected_vid, $expected_d */ public function testTaxonomyTerms() { $this->assertEntity(1, 'General discussion', 'forums', '', NULL, 2); - $this->assertEntity(2, 'Term1', 'test_vocabulary', 'The first term.', 'filtered_html'); + $this->assertEntity(2, 'Term1', 'test_vocabulary', 'The first term.', 'filtered_html', 0, [], NULL, 3); $this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.', 'filtered_html'); - $this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 'full_html', 0, [3]); + $this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 'full_html', 0, [3], 6); $this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', NULL, 3); $this->assertEntity(6, 'Games', 'forums', '', NULL, 4); $this->assertEntity(7, 'Minecraft', 'forums', '', NULL, 1, [6]); diff --git a/core/modules/taxonomy/tests/src/Unit/Migrate/TermSourceWithVocabularyFilterTest.php b/core/modules/taxonomy/tests/src/Unit/Migrate/TermSourceWithVocabularyFilterTest.php index 67c46cb..c7fd197 100644 --- a/core/modules/taxonomy/tests/src/Unit/Migrate/TermSourceWithVocabularyFilterTest.php +++ b/core/modules/taxonomy/tests/src/Unit/Migrate/TermSourceWithVocabularyFilterTest.php @@ -1,6 +1,6 @@ migrationConfiguration['source']['vocabulary'] = array(5); + $this->migrationConfiguration['source']['vocabulary'] = [5]; parent::setUp(); $this->expectedResults = array_values(array_filter($this->expectedResults, function($result) { return $result['vid'] == 5; diff --git a/core/modules/taxonomy/tests/src/Unit/Migrate/TermTest.php b/core/modules/taxonomy/tests/src/Unit/Migrate/TermTest.php deleted file mode 100644 index ad2706b..0000000 --- a/core/modules/taxonomy/tests/src/Unit/Migrate/TermTest.php +++ /dev/null @@ -1,12 +0,0 @@ - 'test', - 'highWaterProperty' => array('field' => 'test'), - 'source' => array( + 'highWaterProperty' => ['field' => 'test'], + 'source' => [ 'plugin' => 'd6_taxonomy_term', - ), - ); + ], + ]; - protected $expectedResults = array( - array( + protected $expectedResults = [ + [ 'tid' => 1, 'vid' => 5, 'name' => 'name value 1', 'description' => 'description value 1', 'weight' => 0, - 'parent' => array(0), - ), - array( + 'parent' => [0], + ], + [ 'tid' => 2, 'vid' => 6, 'name' => 'name value 2', 'description' => 'description value 2', 'weight' => 0, - 'parent' => array(0), - ), - array( + 'parent' => [0], + ], + [ 'tid' => 3, 'vid' => 6, 'name' => 'name value 3', 'description' => 'description value 3', 'weight' => 0, - 'parent' => array(0), - ), - array( + 'parent' => [0], + ], + [ 'tid' => 4, 'vid' => 5, 'name' => 'name value 4', 'description' => 'description value 4', 'weight' => 1, - 'parent' => array(1), - ), - array( + 'parent' => [1], + ], + [ 'tid' => 5, 'vid' => 6, 'name' => 'name value 5', 'description' => 'description value 5', 'weight' => 1, - 'parent' => array(2), - ), - array( + 'parent' => [2], + ], + [ 'tid' => 6, 'vid' => 6, 'name' => 'name value 6', 'description' => 'description value 6', 'weight' => 0, - 'parent' => array(3, 2), - ), - ); + 'parent' => [3, 2], + ], + ]; /** * {@inheritdoc} @@ -76,10 +76,10 @@ protected function setUp() { foreach ($this->expectedResults as $k => $row) { foreach ($row['parent'] as $parent) { - $this->databaseContents['term_hierarchy'][] = array( + $this->databaseContents['term_hierarchy'][] = [ 'tid' => $row['tid'], 'parent' => $parent, - ); + ]; } unset($row['parent']); $this->databaseContents['term_data'][$k] = $row; diff --git a/core/modules/taxonomy/tests/src/Unit/Migrate/d6/TermSourceWithVocabularyFilterTest.php b/core/modules/taxonomy/tests/src/Unit/Migrate/d6/TermSourceWithVocabularyFilterTest.php new file mode 100644 index 0000000..dbe771d --- /dev/null +++ b/core/modules/taxonomy/tests/src/Unit/Migrate/d6/TermSourceWithVocabularyFilterTest.php @@ -0,0 +1,25 @@ +migrationConfiguration['source']['vocabulary'] = [5]; + parent::setUp(); + $this->expectedResults = array_values(array_filter($this->expectedResults, function($result) { + return $result['vid'] == 5; + })); + // We know there are two rows with vid == 5. + $this->expectedCount = 2; + } + +} diff --git a/core/modules/taxonomy/tests/src/Unit/Migrate/d7/TermTestBase.php b/core/modules/taxonomy/tests/src/Unit/Migrate/d7/TermTestBase.php new file mode 100644 index 0000000..4f5acc8 --- /dev/null +++ b/core/modules/taxonomy/tests/src/Unit/Migrate/d7/TermTestBase.php @@ -0,0 +1,114 @@ + 'test', + 'highWaterProperty' => ['field' => 'test'], + 'source' => [ + 'plugin' => 'd7_taxonomy_term', + ], + ]; + + protected $expectedResults = [ + [ + 'tid' => 1, + 'vid' => 5, + 'machine_name' => 'tags', + 'name' => 'name value 1', + 'description' => 'description value 1', + 'weight' => 0, + 'parent' => [0], + ], + [ + 'tid' => 2, + 'vid' => 6, + 'machine_name' => 'categories', + 'name' => 'name value 2', + 'description' => 'description value 2', + 'weight' => 0, + 'parent' => [0], + ], + [ + 'tid' => 3, + 'vid' => 6, + 'machine_name' => 'categories', + 'name' => 'name value 3', + 'description' => 'description value 3', + 'weight' => 0, + 'parent' => [0], + ], + [ + 'tid' => 4, + 'vid' => 5, + 'machine_name' => 'tags', + 'name' => 'name value 4', + 'description' => 'description value 4', + 'weight' => 1, + 'parent' => [1], + ], + [ + 'tid' => 5, + 'vid' => 6, + 'machine_name' => 'categories', + 'name' => 'name value 5', + 'description' => 'description value 5', + 'weight' => 1, + 'parent' => [2], + ], + [ + 'tid' => 6, + 'vid' => 6, + 'machine_name' => 'categories', + 'name' => 'name value 6', + 'description' => 'description value 6', + 'weight' => 0, + 'parent' => [3, 2], + ], + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + foreach ($this->expectedResults as $k => $row) { + foreach ($row['parent'] as $parent) { + $this->databaseContents['taxonomy_term_hierarchy'][] = [ + 'tid' => $row['tid'], + 'parent' => $parent, + ]; + } + unset($row['parent']); + $this->databaseContents['taxonomy_term_data'][$k] = $row; + $this->databaseContents['taxonomy_vocabulary'][$row['vid']] = [ + 'vid' => $row['vid'], + 'machine_name' => $row['machine_name'], + ]; + $this->databaseContents['field_config_instance'][$row['machine_name']] = [ + 'field_name' => 'field_term_field', + 'entity_type' => 'taxonomy_term', + 'bundle' => $row['machine_name'], + 'deleted' => 0, + ]; + $this->databaseContents['field_data_field_term_field'][$row['machine_name']] = [ + 'entity_type' => 'taxonomy_term', + 'bundle' => $row['machine_name'], + 'deleted' => 0, + 'entity_id' => 1, + 'delta' => 0, + ]; + } + + parent::setUp(); + } + +}