public function MigrationStateUnitTest::testGetUpgradeStates in Drupal 8
Same name and namespace in other branches
- 9 core/modules/migrate_drupal/tests/src/Unit/MigrationStateUnitTest.php \Drupal\Tests\migrate_drupal\Unit\MigrationStateUnitTest::testGetUpgradeStates()
- 10 core/modules/migrate_drupal/tests/src/Unit/MigrationStateUnitTest.php \Drupal\Tests\migrate_drupal\Unit\MigrationStateUnitTest::testGetUpgradeStates()
Tests ::getUpgradeStates.
@dataProvider providerGetUpgradeStates
@covers ::getUpgradeStates @covers ::buildDiscoveredDestinationsBySource @covers ::buildDeclaredStateBySource @covers ::buildUpgradeState @covers ::getMigrationStates @covers ::getSourceState @covers ::getDestinationsForSource
File
- core/
modules/ migrate_drupal/ tests/ src/ Unit/ MigrationStateUnitTest.php, line 40
Class
- MigrationStateUnitTest
- Defines a class for testing \Drupal\migrate_drupal\MigrationState.
Namespace
Drupal\Tests\migrate_drupal\UnitCode
public function testGetUpgradeStates($modules_to_enable, $files, $field_plugins, $migrations, $source_system_data, $expected_7, $expected_6) {
$fieldPluginManager = $this
->prophesize(MigrateFieldPluginManagerInterface::class);
$fieldPluginManager
->getDefinitions()
->willReturn($field_plugins);
$moduleHandler = $this
->prophesize(ModuleHandlerInterface::class);
$moduleHandler
->getModuleList()
->willReturn($modules_to_enable);
vfsStreamWrapper::register();
$root = new vfsStreamDirectory('modules');
vfsStreamWrapper::setRoot($root);
$url = vfsStream::url('modules');
foreach ($files as $module => $contents) {
$path = $url . '/' . $module . '/migrations/state';
mkdir($path, '0755', TRUE);
file_put_contents($path . '/' . $module . '.migrate_drupal.yml', $contents);
}
$moduleHandler
->getModuleDirectories()
->willReturn(array_combine(array_keys($files), array_map(function ($module) use ($url) {
return $url . '/' . $module;
}, array_keys($files))));
$migrationState = new MigrationState($fieldPluginManager
->reveal(), $moduleHandler
->reveal(), $this
->createMock(MessengerInterface::class), $this
->getStringTranslationStub());
$all_migrations = [];
foreach ($migrations as $name => $values) {
$migration = $this
->prophesize(MigrationInterface::class);
$source = $this
->prophesize(MigrateSourceInterface::class);
$destination = $this
->prophesize(MigrateDestinationInterface::class);
$source
->getSourceModule()
->willReturn($values['source_module']);
$destination
->getDestinationModule()
->willReturn($values['destination_module']);
$migration
->getSourcePlugin()
->willReturn($source
->reveal());
$migration
->getDestinationPlugin()
->willReturn($destination
->reveal());
$migration
->getPluginId()
->willReturn($name);
$migration
->label()
->willReturn($name);
$all_migrations[] = $migration
->reveal();
}
// Tests Drupal 7 states.
$states = $migrationState
->getUpgradeStates(7, $source_system_data, $all_migrations);
$this
->assertEquals($expected_7, $states);
$source_system_data['module']['content'] = [
'name' => 'content',
'status' => TRUE,
];
// Tests Drupal 6 states.
unset($source_system_data['module']['rdf'], $source_system_data['module']['filter']);
$states = $migrationState
->getUpgradeStates(6, $source_system_data, []);
$this
->assertEquals($expected_6, $states);
}