From 494f931e69c7ce52b6d68fe3d85c97ed2cda2435 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Fri, 16 Feb 2018 21:19:36 +0000 Subject: [PATCH] Issue #2945041 by heddn, maxocub: Categorize derived migrations according to their type --- .../migrate}/DestinationCategoryTest.php | 96 +++++++++++++------ .../src/Traits/CreateMigrationsTrait.php | 33 +++++++ core/modules/node/migrations/d6_node.yml | 1 + .../node/migrations/d6_node_revision.yml | 1 + .../node/migrations/d6_node_translation.yml | 1 + core/modules/node/migrations/d7_node.yml | 1 + .../node/migrations/d7_node_revision.yml | 1 + .../node/migrations/d7_node_translation.yml | 1 + .../taxonomy/migrations/d6_term_node.yml | 1 + .../migrations/d6_term_node_revision.yml | 1 + .../taxonomy/migrations/d7_taxonomy_term.yml | 1 + 11 files changed, 108 insertions(+), 30 deletions(-) rename core/modules/{migrate/tests/src/Kernel/Plugin => migrate_drupal/tests/src/Kernel/Plugin/migrate}/DestinationCategoryTest.php (58%) create mode 100644 core/modules/migrate_drupal/tests/src/Traits/CreateMigrationsTrait.php diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/DestinationCategoryTest.php b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php similarity index 58% rename from core/modules/migrate/tests/src/Kernel/Plugin/DestinationCategoryTest.php rename to core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php index ed3d85ab8c78..0ff29fdf2d27 100644 --- a/core/modules/migrate/tests/src/Kernel/Plugin/DestinationCategoryTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\Tests\migrate\Kernel\Plugin; +namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate; use Drupal\ban\Plugin\migrate\destination\BlockedIP; use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait; @@ -13,18 +13,18 @@ use Drupal\statistics\Plugin\migrate\destination\NodeCounter; use Drupal\system\Plugin\migrate\destination\d7\ThemeSettings; use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase; +use Drupal\Tests\migrate_drupal\Traits\CreateMigrationsTrait; use Drupal\user\Plugin\migrate\destination\UserData; /** * Tests that all migrations are tagged as either content or configuration. * - * @coversDefaultClass \Drupal\migrate\Plugin\MigrationPluginManager - * - * @group migrate + * @group migrate_drupal */ class DestinationCategoryTest extends MigrateDrupalTestBase { use FileSystemModuleDiscoveryDataProviderTrait; + use CreateMigrationsTrait; /** * The migration plugin manager. @@ -44,33 +44,31 @@ protected function setUp() { } /** - * @covers ::getDefinitions + * Tests that all D6 migrations are tagged as either Configuration or Content. */ - public function testGetGroupedDefinitions() { - $definitions = array_keys($this->migrationManager->getDefinitions()); + public function testD6Categories() { + $migrations = $this->drupal6Migrations(); + $this->assertArrayHasKey('d6_node:page', $migrations); + $this->assertCategories($migrations); + } - // Configuration migrations should have a destination plugin that is an - // instance of one of the following classes. - $config_classes = [ - Config::class, - EntityConfigBase::class, - ThemeSettings::class, - ComponentEntityDisplayBase::class, - ShortcutSetUsers::class, - ]; - // Content migrations should have a destination plugin that is an instance - // of one of the following classes. - $content_classes = [ - EntityContentBase::class, - UrlAlias::class, - BlockedIP::class, - NodeCounter::class, - UserData::class, - ]; + /** + * Tests that all D7 migrations are tagged as either Configuration or Content. + */ + public function testD7Categories() { + $migrations = $this->drupal7Migrations(); + $this->assertArrayHasKey('d7_node:page', $migrations); + $this->assertCategories($migrations); + + } - // Instantiate all migrations. - /** @var \Drupal\migrate\Plugin\Migration[] $migrations */ - $migrations = $this->migrationManager->createInstances($definitions); + /** + * Asserts that all migrations are tagged as either Configuration or Content. + * + * @param \Drupal\migrate\Plugin\MigrationInterface[] $migrations + * The migrations. + */ + protected function assertCategories($migrations) { foreach ($migrations as $id => $migration) { $object_classes = class_parents($migration->getDestinationPlugin()); $object_classes[] = get_class($migration->getDestinationPlugin()); @@ -78,10 +76,10 @@ public function testGetGroupedDefinitions() { // Ensure that the destination plugin is an instance of at least one of // the expected classes. if (in_array('Configuration', $migration->getMigrationTags(), TRUE)) { - $this->assertNotEmpty(array_intersect($object_classes, $config_classes), "The migration $id is tagged as Configuration."); + $this->assertNotEmpty(array_intersect($object_classes, $this->getConfigurationClasses()), "The migration $id is tagged as Configuration."); } elseif (in_array('Content', $migration->getMigrationTags(), TRUE)) { - $this->assertNotEmpty(array_intersect($object_classes, $content_classes), "The migration $id is tagged as Content."); + $this->assertNotEmpty(array_intersect($object_classes, $this->getContentClasses()), "The migration $id is tagged as Content."); } else { $this->fail("The migration $id is not tagged as either 'Content' or 'Configuration'."); @@ -89,4 +87,42 @@ public function testGetGroupedDefinitions() { } } + /** + * Get configuration classes. + * + * Configuration migrations should have a destination plugin that is an + * instance of one of the following classes. + * + * @return array + * The configuration class names. + */ + protected function getConfigurationClasses() { + return [ + Config::class, + EntityConfigBase::class, + ThemeSettings::class, + ComponentEntityDisplayBase::class, + ShortcutSetUsers::class, + ]; + } + + /** + * Get content classes. + * + * Content migrations should have a destination plugin that is an instance + * of one of the following classes. + * + * @return array + * The content class names. + */ + protected function getContentClasses() { + return [ + EntityContentBase::class, + UrlAlias::class, + BlockedIP::class, + NodeCounter::class, + UserData::class, + ]; + } + } diff --git a/core/modules/migrate_drupal/tests/src/Traits/CreateMigrationsTrait.php b/core/modules/migrate_drupal/tests/src/Traits/CreateMigrationsTrait.php new file mode 100644 index 000000000000..9b316de2ae87 --- /dev/null +++ b/core/modules/migrate_drupal/tests/src/Traits/CreateMigrationsTrait.php @@ -0,0 +1,33 @@ +<?php + +namespace Drupal\Tests\migrate_drupal\Traits; + +trait CreateMigrationsTrait { + + /** + * Create instances of all Drupal 6 migrations. + * + * @return \Drupal\migrate\Plugin\MigrationInterface[] + * The migrations + */ + public function drupal6Migrations() { + $dirs = \Drupal::service('module_handler')->getModuleDirectories(); + $migrate_drupal_directory = $dirs['migrate_drupal']; + $this->loadFixture("$migrate_drupal_directory/tests/fixtures/drupal6.php"); + return \Drupal::service('plugin.manager.migration')->createInstancesByTag('Drupal 6'); + } + + /** + * Create instances of all Drupal 7 migrations. + * + * @return \Drupal\migrate\Plugin\MigrationInterface[] + * The migrations + */ + public function drupal7Migrations() { + $dirs = \Drupal::service('module_handler')->getModuleDirectories(); + $migrate_drupal_directory = $dirs['migrate_drupal']; + $this->loadFixture("$migrate_drupal_directory/tests/fixtures/drupal7.php"); + return \Drupal::service('plugin.manager.migration')->createInstancesByTag('Drupal 7'); + } + +} diff --git a/core/modules/node/migrations/d6_node.yml b/core/modules/node/migrations/d6_node.yml index 84a4bf18720f..524448bc382a 100644 --- a/core/modules/node/migrations/d6_node.yml +++ b/core/modules/node/migrations/d6_node.yml @@ -3,6 +3,7 @@ label: Nodes audit: true migration_tags: - Drupal 6 + - Content deriver: Drupal\node\Plugin\migrate\D6NodeDeriver source: plugin: d6_node diff --git a/core/modules/node/migrations/d6_node_revision.yml b/core/modules/node/migrations/d6_node_revision.yml index 74a42d430773..732c9abe27f2 100644 --- a/core/modules/node/migrations/d6_node_revision.yml +++ b/core/modules/node/migrations/d6_node_revision.yml @@ -3,6 +3,7 @@ label: Node revisions audit: true migration_tags: - Drupal 6 + - Content deriver: Drupal\node\Plugin\migrate\D6NodeDeriver source: plugin: d6_node_revision diff --git a/core/modules/node/migrations/d6_node_translation.yml b/core/modules/node/migrations/d6_node_translation.yml index 88d79dd9b4b9..26cb0243bc91 100644 --- a/core/modules/node/migrations/d6_node_translation.yml +++ b/core/modules/node/migrations/d6_node_translation.yml @@ -2,6 +2,7 @@ id: d6_node_translation label: Node translations migration_tags: - Drupal 6 + - Content deriver: Drupal\node\Plugin\migrate\D6NodeDeriver source: plugin: d6_node diff --git a/core/modules/node/migrations/d7_node.yml b/core/modules/node/migrations/d7_node.yml index 80367971a3a5..5bf826164a6b 100644 --- a/core/modules/node/migrations/d7_node.yml +++ b/core/modules/node/migrations/d7_node.yml @@ -3,6 +3,7 @@ label: Nodes audit: true migration_tags: - Drupal 7 + - Content deriver: Drupal\node\Plugin\migrate\D7NodeDeriver source: plugin: d7_node diff --git a/core/modules/node/migrations/d7_node_revision.yml b/core/modules/node/migrations/d7_node_revision.yml index 18c90b6f49d3..7310b0d5b0ad 100644 --- a/core/modules/node/migrations/d7_node_revision.yml +++ b/core/modules/node/migrations/d7_node_revision.yml @@ -3,6 +3,7 @@ label: Node revisions audit: true migration_tags: - Drupal 7 + - Content deriver: Drupal\node\Plugin\migrate\D7NodeDeriver source: plugin: d7_node_revision diff --git a/core/modules/node/migrations/d7_node_translation.yml b/core/modules/node/migrations/d7_node_translation.yml index 69217b971fca..542ab33b20a9 100644 --- a/core/modules/node/migrations/d7_node_translation.yml +++ b/core/modules/node/migrations/d7_node_translation.yml @@ -3,6 +3,7 @@ label: Node translations migration_tags: - Drupal 7 - translation + - Content deriver: Drupal\node\Plugin\migrate\D7NodeDeriver source: plugin: d7_node diff --git a/core/modules/taxonomy/migrations/d6_term_node.yml b/core/modules/taxonomy/migrations/d6_term_node.yml index 846334d4b9ca..fdb8cc9a41d0 100644 --- a/core/modules/taxonomy/migrations/d6_term_node.yml +++ b/core/modules/taxonomy/migrations/d6_term_node.yml @@ -2,6 +2,7 @@ id: d6_term_node label: Term/node relationships migration_tags: - Drupal 6 + - Content deriver: Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver source: plugin: d6_term_node diff --git a/core/modules/taxonomy/migrations/d6_term_node_revision.yml b/core/modules/taxonomy/migrations/d6_term_node_revision.yml index c3ebe3059faf..2edf86054dad 100644 --- a/core/modules/taxonomy/migrations/d6_term_node_revision.yml +++ b/core/modules/taxonomy/migrations/d6_term_node_revision.yml @@ -3,6 +3,7 @@ label: Term/node relationship revisions audit: true migration_tags: - Drupal 6 + - Content deriver: Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver source: plugin: d6_term_node_revision diff --git a/core/modules/taxonomy/migrations/d7_taxonomy_term.yml b/core/modules/taxonomy/migrations/d7_taxonomy_term.yml index 6033d4f875ec..0331cf057253 100644 --- a/core/modules/taxonomy/migrations/d7_taxonomy_term.yml +++ b/core/modules/taxonomy/migrations/d7_taxonomy_term.yml @@ -3,6 +3,7 @@ label: Taxonomy terms audit: true migration_tags: - Drupal 7 + - Content deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver source: plugin: d7_taxonomy_term -- GitLab