diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php index 48d4716..0719ac2 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php @@ -39,58 +39,6 @@ protected function setUp() { $this->installEntitySchema('comment'); $this->installEntitySchema('taxonomy_term'); - CommentType::create([ - 'id' => 'comment_node_page', - 'label' => $this->randomMachineName(), - ])->save(); - CommentType::create([ - 'id' => 'comment_node_article', - 'label' => $this->randomMachineName(), - ])->save(); - CommentType::create([ - 'id' => 'comment_node_blog', - 'label' => $this->randomMachineName(), - ])->save(); - CommentType::create([ - 'id' => 'comment_node_book', - 'label' => $this->randomMachineName(), - ])->save(); - CommentType::create([ - 'id' => 'comment_node_forum', - 'label' => $this->randomMachineName(), - ])->save(); - CommentType::create([ - 'id' => 'comment_node_test_content_type', - 'label' => $this->randomMachineName(), - ])->save(); - - NodeType::create([ - 'type' => 'page', - 'label' => $this->randomMachineName(), - ])->save(); - NodeType::create([ - 'type' => 'article', - 'label' => $this->randomMachineName(), - ])->save(); - NodeType::create([ - 'type' => 'blog', - 'label' => $this->randomMachineName(), - ])->save(); - NodeType::create([ - 'type' => 'book', - 'label' => $this->randomMachineName(), - ])->save(); - NodeType::create([ - 'type' => 'forum', - 'label' => $this->randomMachineName(), - ])->save(); - NodeType::create([ - 'type' => 'test_content_type', - 'label' => $this->randomMachineName(), - ])->save(); - - Vocabulary::create(['vid' => 'test_vocabulary'])->save(); - // Give one unfortunate field instance invalid display settings to ensure // that the migration provides an empty array as a default (thus avoiding // an "unsupported operand types" fatal). @@ -148,7 +96,11 @@ protected function setUp() { ->condition('field_name', 'body') ->execute(); - $this->migrateFields(); + $this->migrateFieldInstances(); + $this->executeMigrations([ + 'd7_view_modes', + 'd7_field_formatter_settings', + ]); } /** diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php index c50c324..5a3e434 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php @@ -2,12 +2,9 @@ namespace Drupal\Tests\field\Kernel\Migrate\d7; -use Drupal\comment\Entity\CommentType; use Drupal\field\Entity\FieldConfig; use Drupal\field\FieldConfigInterface; -use Drupal\taxonomy\Entity\Vocabulary; use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; -use Drupal\node\Entity\NodeType; /** * Migrates Drupal 7 field instances. @@ -39,34 +36,7 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase { */ protected function setUp() { parent::setUp(); - $this->installConfig(static::$modules); - $this->createType('page'); - $this->createType('article'); - $this->createType('blog'); - $this->createType('book'); - $this->createType('forum'); - $this->createType('test_content_type'); - Vocabulary::create(['vid' => 'test_vocabulary'])->save(); - $this->executeMigrations(['d7_field', 'd7_field_instance']); - } - - /** - * Creates a node type with a corresponding comment type. - * - * @param string $id - * The node type ID. - */ - protected function createType($id) { - NodeType::create(array( - 'type' => $id, - 'label' => $this->randomString(), - ))->save(); - - CommentType::create(array( - 'id' => 'comment_node_' . $id, - 'label' => $this->randomString(), - 'target_entity_type_id' => 'node', - ))->save(); + $this->migrateFieldInstances(); } /** diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php index 35b3168..8e7a011 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php @@ -42,7 +42,8 @@ protected function setUp() { $this->installEntitySchema('taxonomy_term'); $this->installConfig(static::$modules); - $this->migrateFields(); + $this->migrateFieldInstances(); + $this->executeMigration('d7_field_instance_widget_settings'); } /** diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php index 4a0f8cd..d3f3b1e 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php @@ -36,8 +36,7 @@ class MigrateFieldTest extends MigrateDrupal7TestBase { */ protected function setUp() { parent::setUp(); - $this->installConfig(static::$modules); - $this->executeMigration('d7_field'); + $this->migrateFields(); } /** diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php index f316013..c7eaadd 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php @@ -2,7 +2,9 @@ namespace Drupal\Tests\migrate_drupal\Kernel\d7; -use Drupal\migrate\Entity\Migration; +use Drupal\comment\Entity\CommentType; +use Drupal\node\Entity\NodeType; +use Drupal\taxonomy\Entity\Vocabulary; use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase; /** @@ -28,43 +30,67 @@ protected function getFixtureFilePath() { } /** + * Executes all field migrations. + */ + protected function migrateFields() { + $this->executeMigration('d7_field'); + } + + /** + * Executes all field instance migrations. + */ + protected function migrateFieldInstances() { + $this->createType('page'); + $this->createType('article'); + $this->createType('blog'); + $this->createType('book'); + $this->createType('forum'); + $this->createType('test_content_type'); + Vocabulary::create(['vid' => 'test_vocabulary'])->save(); + $this->migrateFields(); + $this->executeMigration('d7_field_instance'); + } + + /** + * Creates a node type with a corresponding comment type. + * + * @param string $id + * The node type ID. + */ + protected function createType($id) { + NodeType::create([ + 'type' => $id, + 'label' => $this->randomString(), + ])->save(); + + CommentType::create([ + 'id' => 'comment_node_' . $id, + 'label' => $this->randomString(), + 'target_entity_type_id' => 'node', + ])->save(); + } + + /** * Executes all user migrations. * * @param bool $include_pictures * If TRUE, migrates user pictures. */ protected function migrateUsers($include_pictures = TRUE) { - $this->installMigrations('Drupal 7'); - $this->executeMigrations(['d7_filter_format', 'd7_user_role']); + // Prepare to migrate user pictures as well. + $this->installEntitySchema('file'); + $migrations = ['d7_user_role', 'd7_user']; + + $this->migrateFieldInstances(); if ($include_pictures) { - // The d7_file source plugin depends on source_base_path being set in - // the destination configuration. This is evil and horrifying, but - // necessary for the time being. - // @see https://www.drupal.org/node/2577871 - /** @var \Drupal\migrate\Entity\MigrationInterface $d7_file */ - $d7_file = Migration::load('d7_file'); - $destination = $d7_file->get('destination'); - $destination['source_base_path'] = $this->siteDirectory; - $d7_file->set('destination', $destination); - $d7_file->save(); - - $this->executeMigrations([ - 'd7_file', + $migrations = array_merge([ 'user_picture_field', 'user_picture_field_instance', - 'user_picture_entity_display', - 'user_picture_entity_form_display', - ]); - } - else { - // These are optional dependencies of d7_user, but we don't need them if - // we're not migrating user pictures. - Migration::load('user_picture_entity_display')->delete(); - Migration::load('user_picture_entity_form_display')->delete(); + ], $migrations); } - $this->executeMigration('d7_user'); + $this->executeMigrations($migrations); } /** @@ -76,42 +102,6 @@ protected function migrateContentTypes() { } /** - * Executes all field migrations. - */ - protected function migrateFields() { - $modules = [ - 'comment', - 'datetime', - 'entity_reference', - 'filter', - 'image', - 'link', - 'node', - 'taxonomy', - 'telephone', - 'text', - ]; - $this->enableModules($modules); - $this->installEntitySchema('comment'); - $this->installEntitySchema('file'); - $this->installEntitySchema('node'); - $this->installEntitySchema('taxonomy_term'); - - $this->installMigrations('Drupal 7'); - $this->migrateContentTypes(); - $this->installConfig(['comment']); - $this->executeMigrations([ - // Comments can also have fields. - 'd7_comment_type', - 'd7_field', - 'd7_field_instance', - 'd7_field_instance_widget_settings', - 'd7_view_modes', - 'd7_field_formatter_settings', - ]); - } - - /** * Executes all content migrations. * * @param bool $include_revisions @@ -121,8 +111,6 @@ protected function migrateContent($include_revisions = FALSE) { $modules = [ 'comment', 'datetime', - 'entity_reference', - 'filter', 'image', 'link', 'node', @@ -131,37 +119,32 @@ protected function migrateContent($include_revisions = FALSE) { 'text', ]; $this->enableModules($modules); + $this->installConfig('node'); + $this->installConfig('comment'); $this->installEntitySchema('comment'); - $this->installEntitySchema('file'); $this->installEntitySchema('node'); - $this->installEntitySchema('taxonomy_term'); - $this->installMigrations('Drupal 7'); + $this->migrateUsers(FALSE); - $this->migrateFields(); - $this->executeMigrations(['d7_node_settings', 'd7_node:*']); + $this->migrateContentTypes(); + $this->executeMigrations(['d7_node']); if ($include_revisions) { - $this->executeMigrations(['d7_node_revision:*']); + $this->executeMigrations(['d7_node_revision']); } } /** - * Executes all taxonomy migrations. + * Executes all taxonomy term migrations. */ - protected function migrateTaxonomy() { - - $modules = [ - 'node', - 'taxonomy', - ]; - $this->enableModules($modules); - $this->installEntitySchema('node'); + protected function migrateTaxonomyTerms() { $this->installEntitySchema('taxonomy_term'); - $this->installMigrations('Drupal 7'); $this->migrateContentTypes(); + $this->executeMigration('d7_comment_type'); + $this->migrateFields(); $this->executeMigrations([ 'd7_taxonomy_vocabulary', + 'd7_field_instance', 'd7_taxonomy_term', ]); } 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 8403874..ce3ba0f 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php @@ -36,15 +36,8 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase { */ protected function setUp() { parent::setUp(); - $this->migrateTaxonomy(); $this->installConfig(static::$modules); - - $this->executeMigrations([ - 'd7_node_type', - 'd7_comment_type', - 'd7_field', - 'd7_field_instance', - ]); + $this->migrateTaxonomyTerms(); } /** diff --git a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php index c5fc439..7f79c63 100644 --- a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php +++ b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php @@ -45,25 +45,6 @@ protected function setUp() { } /** - * Creates a node type with a corresponding comment type. - * - * @param string $id - * The node type ID. - */ - protected function createType($id) { - NodeType::create([ - 'type' => $id, - 'label' => $this->randomString(), - ])->save(); - - CommentType::create([ - 'id' => 'comment_node_' . $id, - 'label' => $this->randomString(), - 'target_entity_type_id' => 'node', - ])->save(); - } - - /** * Asserts various aspects of a user account. * * @param string $id