Commit 494f931e authored by alexpott's avatar alexpott

Issue #2945041 by heddn, maxocub: Categorize derived migrations according to their type

parent 1559ab85
<?php <?php
namespace Drupal\Tests\migrate\Kernel\Plugin; namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate;
use Drupal\ban\Plugin\migrate\destination\BlockedIP; use Drupal\ban\Plugin\migrate\destination\BlockedIP;
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait; use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
...@@ -13,18 +13,18 @@ ...@@ -13,18 +13,18 @@
use Drupal\statistics\Plugin\migrate\destination\NodeCounter; use Drupal\statistics\Plugin\migrate\destination\NodeCounter;
use Drupal\system\Plugin\migrate\destination\d7\ThemeSettings; use Drupal\system\Plugin\migrate\destination\d7\ThemeSettings;
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase; use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
use Drupal\Tests\migrate_drupal\Traits\CreateMigrationsTrait;
use Drupal\user\Plugin\migrate\destination\UserData; use Drupal\user\Plugin\migrate\destination\UserData;
/** /**
* Tests that all migrations are tagged as either content or configuration. * Tests that all migrations are tagged as either content or configuration.
* *
* @coversDefaultClass \Drupal\migrate\Plugin\MigrationPluginManager * @group migrate_drupal
*
* @group migrate
*/ */
class DestinationCategoryTest extends MigrateDrupalTestBase { class DestinationCategoryTest extends MigrateDrupalTestBase {
use FileSystemModuleDiscoveryDataProviderTrait; use FileSystemModuleDiscoveryDataProviderTrait;
use CreateMigrationsTrait;
/** /**
* The migration plugin manager. * The migration plugin manager.
...@@ -44,33 +44,31 @@ protected function setUp() { ...@@ -44,33 +44,31 @@ protected function setUp() {
} }
/** /**
* @covers ::getDefinitions * Tests that all D6 migrations are tagged as either Configuration or Content.
*/ */
public function testGetGroupedDefinitions() { public function testD6Categories() {
$definitions = array_keys($this->migrationManager->getDefinitions()); $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. * Tests that all D7 migrations are tagged as either Configuration or Content.
$config_classes = [ */
Config::class, public function testD7Categories() {
EntityConfigBase::class, $migrations = $this->drupal7Migrations();
ThemeSettings::class, $this->assertArrayHasKey('d7_node:page', $migrations);
ComponentEntityDisplayBase::class, $this->assertCategories($migrations);
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,
];
// Instantiate all migrations. /**
/** @var \Drupal\migrate\Plugin\Migration[] $migrations */ * Asserts that all migrations are tagged as either Configuration or Content.
$migrations = $this->migrationManager->createInstances($definitions); *
* @param \Drupal\migrate\Plugin\MigrationInterface[] $migrations
* The migrations.
*/
protected function assertCategories($migrations) {
foreach ($migrations as $id => $migration) { foreach ($migrations as $id => $migration) {
$object_classes = class_parents($migration->getDestinationPlugin()); $object_classes = class_parents($migration->getDestinationPlugin());
$object_classes[] = get_class($migration->getDestinationPlugin()); $object_classes[] = get_class($migration->getDestinationPlugin());
...@@ -78,10 +76,10 @@ public function testGetGroupedDefinitions() { ...@@ -78,10 +76,10 @@ public function testGetGroupedDefinitions() {
// Ensure that the destination plugin is an instance of at least one of // Ensure that the destination plugin is an instance of at least one of
// the expected classes. // the expected classes.
if (in_array('Configuration', $migration->getMigrationTags(), TRUE)) { 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)) { 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 { else {
$this->fail("The migration $id is not tagged as either 'Content' or 'Configuration'."); $this->fail("The migration $id is not tagged as either 'Content' or 'Configuration'.");
...@@ -89,4 +87,42 @@ public function testGetGroupedDefinitions() { ...@@ -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,
];
}
} }
<?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');
}
}
...@@ -3,6 +3,7 @@ label: Nodes ...@@ -3,6 +3,7 @@ label: Nodes
audit: true audit: true
migration_tags: migration_tags:
- Drupal 6 - Drupal 6
- Content
deriver: Drupal\node\Plugin\migrate\D6NodeDeriver deriver: Drupal\node\Plugin\migrate\D6NodeDeriver
source: source:
plugin: d6_node plugin: d6_node
......
...@@ -3,6 +3,7 @@ label: Node revisions ...@@ -3,6 +3,7 @@ label: Node revisions
audit: true audit: true
migration_tags: migration_tags:
- Drupal 6 - Drupal 6
- Content
deriver: Drupal\node\Plugin\migrate\D6NodeDeriver deriver: Drupal\node\Plugin\migrate\D6NodeDeriver
source: source:
plugin: d6_node_revision plugin: d6_node_revision
......
...@@ -2,6 +2,7 @@ id: d6_node_translation ...@@ -2,6 +2,7 @@ id: d6_node_translation
label: Node translations label: Node translations
migration_tags: migration_tags:
- Drupal 6 - Drupal 6
- Content
deriver: Drupal\node\Plugin\migrate\D6NodeDeriver deriver: Drupal\node\Plugin\migrate\D6NodeDeriver
source: source:
plugin: d6_node plugin: d6_node
......
...@@ -3,6 +3,7 @@ label: Nodes ...@@ -3,6 +3,7 @@ label: Nodes
audit: true audit: true
migration_tags: migration_tags:
- Drupal 7 - Drupal 7
- Content
deriver: Drupal\node\Plugin\migrate\D7NodeDeriver deriver: Drupal\node\Plugin\migrate\D7NodeDeriver
source: source:
plugin: d7_node plugin: d7_node
......
...@@ -3,6 +3,7 @@ label: Node revisions ...@@ -3,6 +3,7 @@ label: Node revisions
audit: true audit: true
migration_tags: migration_tags:
- Drupal 7 - Drupal 7
- Content
deriver: Drupal\node\Plugin\migrate\D7NodeDeriver deriver: Drupal\node\Plugin\migrate\D7NodeDeriver
source: source:
plugin: d7_node_revision plugin: d7_node_revision
......
...@@ -3,6 +3,7 @@ label: Node translations ...@@ -3,6 +3,7 @@ label: Node translations
migration_tags: migration_tags:
- Drupal 7 - Drupal 7
- translation - translation
- Content
deriver: Drupal\node\Plugin\migrate\D7NodeDeriver deriver: Drupal\node\Plugin\migrate\D7NodeDeriver
source: source:
plugin: d7_node plugin: d7_node
......
...@@ -2,6 +2,7 @@ id: d6_term_node ...@@ -2,6 +2,7 @@ id: d6_term_node
label: Term/node relationships label: Term/node relationships
migration_tags: migration_tags:
- Drupal 6 - Drupal 6
- Content
deriver: Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver deriver: Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver
source: source:
plugin: d6_term_node plugin: d6_term_node
......
...@@ -3,6 +3,7 @@ label: Term/node relationship revisions ...@@ -3,6 +3,7 @@ label: Term/node relationship revisions
audit: true audit: true
migration_tags: migration_tags:
- Drupal 6 - Drupal 6
- Content
deriver: Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver deriver: Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver
source: source:
plugin: d6_term_node_revision plugin: d6_term_node_revision
......
...@@ -3,6 +3,7 @@ label: Taxonomy terms ...@@ -3,6 +3,7 @@ label: Taxonomy terms
audit: true audit: true
migration_tags: migration_tags:
- Drupal 7 - Drupal 7
- Content
deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver
source: source:
plugin: d7_taxonomy_term plugin: d7_taxonomy_term
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment