View source
<?php
namespace Drupal\Tests\migrate_plus\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate_plus\Entity\Migration;
use Drupal\migrate_plus\Entity\MigrationGroup;
class MigrationGroupTest extends KernelTestBase {
public static $modules = [
'migrate',
'migrate_plus',
'migrate_plus_test',
];
public function testConfigurationMerge() {
$group_id = 'test_group';
$group_configuration = [
'id' => $group_id,
'shared_configuration' => [
'migration_tags' => [
'Drupal 6',
],
'source' => [
'constants' => [
'type' => 'image',
'cardinality' => '1',
],
],
'destination' => [
'plugin' => 'field_storage_config',
],
],
];
$this->container
->get('entity_type.manager')
->getStorage('migration_group')
->create($group_configuration)
->save();
$migration = $this->container
->get('entity_type.manager')
->getStorage('migration')
->create([
'id' => 'specific_migration',
'load' => [],
'migration_group' => $group_id,
'label' => 'Unaffected by the group',
'migration_tags' => [
'Drupal 7',
],
'destination' => [],
'source' => [],
'process' => [],
'migration_dependencies' => [],
]);
$migration
->set('source', [
'plugin' => 'empty',
'constants' => [
'entity_type' => 'user',
'cardinality' => '3',
],
]);
$migration
->save();
$expected_config = [
'label' => 'Unaffected by the group',
'getMigrationTags' => [
'Drupal 7',
],
'getSourceConfiguration' => [
'plugin' => 'empty',
'constants' => [
'entity_type' => 'user',
'type' => 'image',
'cardinality' => '3',
],
],
'getDestinationConfiguration' => [
'plugin' => 'field_storage_config',
],
];
$loaded_migration = $this->container
->get('plugin.manager.migration')
->createInstance('specific_migration');
foreach ($expected_config as $method => $expected_value) {
$actual_value = call_user_func([
$loaded_migration,
$method,
]);
$this
->assertEquals($expected_value, $actual_value);
}
}
public function testDelete() {
$group_configuration = [
'id' => 'test_group',
];
$migration_group = $this->container
->get('entity_type.manager')
->getStorage('migration_group')
->create($group_configuration);
$migration_group
->save();
$migration = $this->container
->get('entity_type.manager')
->getStorage('migration')
->create([
'id' => 'specific_migration',
'migration_group' => 'test_group',
'migration_tags' => [],
'load' => [],
'destination' => [],
'source' => [],
'migration_dependencies' => [],
]);
$migration
->save();
$loaded_migration_group = MigrationGroup::load('test_group');
$loaded_migration_group
->delete();
$loaded_migration = Migration::load('specific_migration');
$this
->assertNull($loaded_migration);
}
public function testDefaultGroup() {
$this
->installConfig('migrate_plus_test');
$pluginManager = \Drupal::service('plugin.manager.migration');
$migration = $pluginManager
->getDefinition('dummy');
$this
->assertEqual($migration['migration_group'], 'default', 'Migrations without an explicit group are assigned the default group.');
}
}