Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / migrate_drupal / tests / src / Kernel / Plugin / migrate / DestinationCategoryTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate;
4
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;
18
19 /**
20  * Tests that all migrations are tagged as either content or configuration.
21  *
22  * @group migrate_drupal
23  */
24 class DestinationCategoryTest extends MigrateDrupalTestBase {
25
26   use FileSystemModuleDiscoveryDataProviderTrait;
27   use CreateMigrationsTrait;
28
29   /**
30    * The migration plugin manager.
31    *
32    * @var \Drupal\migrate\Plugin\MigrationPluginManager
33    */
34   protected $migrationManager;
35
36   /**
37    * {@inheritdoc}
38    */
39   protected function setUp() {
40     // Enable all modules.
41     self::$modules = array_keys($this->coreModuleListDataProvider());
42     parent::setUp();
43     $this->migrationManager = \Drupal::service('plugin.manager.migration');
44   }
45
46   /**
47    * Tests that all D6 migrations are tagged as either Configuration or Content.
48    */
49   public function testD6Categories() {
50     $migrations = $this->drupal6Migrations();
51     $this->assertArrayHasKey('d6_node:page', $migrations);
52     $this->assertCategories($migrations);
53   }
54
55   /**
56    * Tests that all D7 migrations are tagged as either Configuration or Content.
57    */
58   public function testD7Categories() {
59     $migrations = $this->drupal7Migrations();
60     $this->assertArrayHasKey('d7_node:page', $migrations);
61     $this->assertCategories($migrations);
62
63   }
64
65   /**
66    * Asserts that all migrations are tagged as either Configuration or Content.
67    *
68    * @param \Drupal\migrate\Plugin\MigrationInterface[] $migrations
69    *   The migrations.
70    */
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());
75
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.");
80       }
81       elseif (in_array('Content', $migration->getMigrationTags(), TRUE)) {
82         $this->assertNotEmpty(array_intersect($object_classes, $this->getContentClasses()), "The migration $id is tagged as Content.");
83       }
84       else {
85         $this->fail("The migration $id is not tagged as either 'Content' or 'Configuration'.");
86       }
87     }
88   }
89
90   /**
91    * Get configuration classes.
92    *
93    * Configuration migrations should have a destination plugin that is an
94    * instance of one of the following classes.
95    *
96    * @return array
97    *   The configuration class names.
98    */
99   protected function getConfigurationClasses() {
100     return [
101       Config::class,
102       EntityConfigBase::class,
103       ThemeSettings::class,
104       ComponentEntityDisplayBase::class,
105       ShortcutSetUsers::class,
106     ];
107   }
108
109   /**
110    * Get content classes.
111    *
112    * Content migrations should have a destination plugin that is an instance
113    * of one of the following classes.
114    *
115    * @return array
116    *   The content class names.
117    */
118   protected function getContentClasses() {
119     return [
120       EntityContentBase::class,
121       UrlAlias::class,
122       BlockedIP::class,
123       NodeCounter::class,
124       UserData::class,
125     ];
126   }
127
128 }