3 namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate;
5 use Drupal\ban\Plugin\migrate\destination\BlockedIP;
6 use Drupal\color\Plugin\migrate\destination\Color;
7 use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
8 use Drupal\migrate\Plugin\migrate\destination\ComponentEntityDisplayBase;
9 use Drupal\migrate\Plugin\migrate\destination\Config;
10 use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
11 use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
12 use Drupal\path\Plugin\migrate\destination\UrlAlias;
13 use Drupal\shortcut\Plugin\migrate\destination\ShortcutSetUsers;
14 use Drupal\statistics\Plugin\migrate\destination\NodeCounter;
15 use Drupal\system\Plugin\migrate\destination\d7\ThemeSettings;
16 use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
17 use Drupal\Tests\migrate_drupal\Traits\CreateMigrationsTrait;
18 use Drupal\user\Plugin\migrate\destination\UserData;
21 * Tests that all migrations are tagged as either content or configuration.
23 * @group migrate_drupal
25 class DestinationCategoryTest extends MigrateDrupalTestBase {
27 use FileSystemModuleDiscoveryDataProviderTrait;
28 use CreateMigrationsTrait;
31 * The migration plugin manager.
33 * @var \Drupal\migrate\Plugin\MigrationPluginManager
35 protected $migrationManager;
40 protected function setUp() {
41 // Enable all modules.
42 self::$modules = array_keys($this->coreModuleListDataProvider());
44 $this->migrationManager = \Drupal::service('plugin.manager.migration');
48 * Tests that all D6 migrations are tagged as either Configuration or Content.
50 public function testD6Categories() {
51 $migrations = $this->drupal6Migrations();
52 $this->assertArrayHasKey('d6_node:page', $migrations);
53 $this->assertCategories($migrations);
57 * Tests that all D7 migrations are tagged as either Configuration or Content.
59 public function testD7Categories() {
60 $migrations = $this->drupal7Migrations();
61 $this->assertArrayHasKey('d7_node:page', $migrations);
62 $this->assertCategories($migrations);
67 * Asserts that all migrations are tagged as either Configuration or Content.
69 * @param \Drupal\migrate\Plugin\MigrationInterface[] $migrations
72 protected function assertCategories($migrations) {
73 foreach ($migrations as $id => $migration) {
74 $object_classes = class_parents($migration->getDestinationPlugin());
75 $object_classes[] = get_class($migration->getDestinationPlugin());
77 // Ensure that the destination plugin is an instance of at least one of
78 // the expected classes.
79 if (in_array('Configuration', $migration->getMigrationTags(), TRUE)) {
80 $this->assertNotEmpty(array_intersect($object_classes, $this->getConfigurationClasses()), "The migration $id is tagged as Configuration.");
82 elseif (in_array('Content', $migration->getMigrationTags(), TRUE)) {
83 $this->assertNotEmpty(array_intersect($object_classes, $this->getContentClasses()), "The migration $id is tagged as Content.");
86 $this->fail("The migration $id is not tagged as either 'Content' or 'Configuration'.");
92 * Get configuration classes.
94 * Configuration migrations should have a destination plugin that is an
95 * instance of one of the following classes.
98 * The configuration class names.
100 protected function getConfigurationClasses() {
104 EntityConfigBase::class,
105 ThemeSettings::class,
106 ComponentEntityDisplayBase::class,
107 ShortcutSetUsers::class,
112 * Get content classes.
114 * Content migrations should have a destination plugin that is an instance
115 * of one of the following classes.
118 * The content class names.
120 protected function getContentClasses() {
122 EntityContentBase::class,