Commit 494f931e authored by alexpott's avatar alexpott

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

parent 1559ab85
<?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,
];
}
}
<?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
audit: true
migration_tags:
- Drupal 6
- Content
deriver: Drupal\node\Plugin\migrate\D6NodeDeriver
source:
plugin: d6_node
......
......@@ -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
......
......@@ -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
......
......@@ -3,6 +3,7 @@ label: Nodes
audit: true
migration_tags:
- Drupal 7
- Content
deriver: Drupal\node\Plugin\migrate\D7NodeDeriver
source:
plugin: d7_node
......
......@@ -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
......
......@@ -3,6 +3,7 @@ label: Node translations
migration_tags:
- Drupal 7
- translation
- Content
deriver: Drupal\node\Plugin\migrate\D7NodeDeriver
source:
plugin: d7_node
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
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