DestinationCategoryTest.php in Drupal 10
File
core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php
View source
<?php
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate;
use Drupal\ban\Plugin\migrate\destination\BlockedIp;
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
use Drupal\migrate\Plugin\migrate\destination\ComponentEntityDisplayBase;
use Drupal\migrate\Plugin\migrate\destination\Config;
use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
use Drupal\shortcut\Plugin\migrate\destination\ShortcutSetUsers;
use Drupal\statistics\Plugin\migrate\destination\NodeCounter;
use Drupal\system\Plugin\migrate\destination\d7\ThemeSettings;
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
use Drupal\Tests\migrate_drupal\Traits\CreateMigrationsTrait;
use Drupal\user\Plugin\migrate\destination\UserData;
class DestinationCategoryTest extends MigrateDrupalTestBase {
use FileSystemModuleDiscoveryDataProviderTrait;
use CreateMigrationsTrait;
protected $migrationManager;
protected function setUp() : void {
self::$modules = array_keys($this
->coreModuleListDataProvider());
parent::setUp();
$this->migrationManager = \Drupal::service('plugin.manager.migration');
}
public function testD6Categories() {
$migrations = $this
->drupal6Migrations();
$this
->assertArrayHasKey('d6_node:page', $migrations);
$this
->assertCategories($migrations);
}
public function testD7Categories() {
$migrations = $this
->drupal7Migrations();
$this
->assertArrayHasKey('d7_node:page', $migrations);
$this
->assertCategories($migrations);
}
protected function assertCategories(array $migrations) : void {
foreach ($migrations as $id => $migration) {
$object_classes = class_parents($migration
->getDestinationPlugin());
$object_classes[] = get_class($migration
->getDestinationPlugin());
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'.");
}
}
}
protected function getConfigurationClasses() {
return [
Config::class,
EntityConfigBase::class,
ThemeSettings::class,
ComponentEntityDisplayBase::class,
ShortcutSetUsers::class,
];
}
protected function getContentClasses() {
return [
EntityContentBase::class,
BlockedIp::class,
NodeCounter::class,
UserData::class,
];
}
}