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