3 namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate;
5 use Drupal\ban\Plugin\migrate\destination\BlockedIP;
6 use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
7 use Drupal\migrate\Plugin\migrate\destination\ComponentEntityDisplayBase;
8 use Drupal\migrate\Plugin\migrate\destination\Config;
9 use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
10 use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
11 use Drupal\path\Plugin\migrate\destination\UrlAlias;
12 use Drupal\shortcut\Plugin\migrate\destination\ShortcutSetUsers;
13 use Drupal\statistics\Plugin\migrate\destination\NodeCounter;
14 use Drupal\system\Plugin\migrate\destination\d7\ThemeSettings;
15 use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
16 use Drupal\Tests\migrate_drupal\Traits\CreateMigrationsTrait;
17 use Drupal\user\Plugin\migrate\destination\UserData;
20 * Tests that all migrations are tagged as either content or configuration.
22 * @group migrate_drupal
24 class DestinationCategoryTest extends MigrateDrupalTestBase {
26 use FileSystemModuleDiscoveryDataProviderTrait;
27 use CreateMigrationsTrait;
30 * The migration plugin manager.
32 * @var \Drupal\migrate\Plugin\MigrationPluginManager
34 protected $migrationManager;
39 protected function setUp() {
40 // Enable all modules.
41 self::$modules = array_keys($this->coreModuleListDataProvider());
43 $this->migrationManager = \Drupal::service('plugin.manager.migration');
47 * Tests that all D6 migrations are tagged as either Configuration or Content.
49 public function testD6Categories() {
50 $migrations = $this->drupal6Migrations();
51 $this->assertArrayHasKey('d6_node:page', $migrations);
52 $this->assertCategories($migrations);
56 * Tests that all D7 migrations are tagged as either Configuration or Content.
58 public function testD7Categories() {
59 $migrations = $this->drupal7Migrations();
60 $this->assertArrayHasKey('d7_node:page', $migrations);
61 $this->assertCategories($migrations);
66 * Asserts that all migrations are tagged as either Configuration or Content.
68 * @param \Drupal\migrate\Plugin\MigrationInterface[] $migrations
71 protected function assertCategories($migrations) {
72 foreach ($migrations as $id => $migration) {
73 $object_classes = class_parents($migration->getDestinationPlugin());
74 $object_classes[] = get_class($migration->getDestinationPlugin());
76 // Ensure that the destination plugin is an instance of at least one of
77 // the expected classes.
78 if (in_array('Configuration', $migration->getMigrationTags(), TRUE)) {
79 $this->assertNotEmpty(array_intersect($object_classes, $this->getConfigurationClasses()), "The migration $id is tagged as Configuration.");
81 elseif (in_array('Content', $migration->getMigrationTags(), TRUE)) {
82 $this->assertNotEmpty(array_intersect($object_classes, $this->getContentClasses()), "The migration $id is tagged as Content.");
85 $this->fail("The migration $id is not tagged as either 'Content' or 'Configuration'.");
91 * Get configuration classes.
93 * Configuration migrations should have a destination plugin that is an
94 * instance of one of the following classes.
97 * The configuration class names.
99 protected function getConfigurationClasses() {
102 EntityConfigBase::class,
103 ThemeSettings::class,
104 ComponentEntityDisplayBase::class,
105 ShortcutSetUsers::class,
110 * Get content classes.
112 * Content migrations should have a destination plugin that is an instance
113 * of one of the following classes.
116 * The content class names.
118 protected function getContentClasses() {
120 EntityContentBase::class,