X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmigrate_drupal%2Ftests%2Fsrc%2FKernel%2FPlugin%2Fmigrate%2FDestinationCategoryTest.php;fp=web%2Fcore%2Fmodules%2Fmigrate_drupal%2Ftests%2Fsrc%2FKernel%2FPlugin%2Fmigrate%2FDestinationCategoryTest.php;h=0ff29fdf2d279cce41f88ac20144ed549c12461b;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php b/web/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php new file mode 100644 index 000000000..0ff29fdf2 --- /dev/null +++ b/web/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php @@ -0,0 +1,128 @@ +coreModuleListDataProvider()); + parent::setUp(); + $this->migrationManager = \Drupal::service('plugin.manager.migration'); + } + + /** + * Tests that all D6 migrations are tagged as either Configuration or Content. + */ + public function testD6Categories() { + $migrations = $this->drupal6Migrations(); + $this->assertArrayHasKey('d6_node:page', $migrations); + $this->assertCategories($migrations); + } + + /** + * 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); + + } + + /** + * 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()); + + // 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, $this->getConfigurationClasses()), "The migration $id is tagged as Configuration."); + } + elseif (in_array('Content', $migration->getMigrationTags(), TRUE)) { + $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'."); + } + } + } + + /** + * 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, + ]; + } + +}