updated core from 8.4 to 8.5 : bug with login_destination
This commit is contained in:
@@ -5,8 +5,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
@@ -4,8 +4,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+3
-3
@@ -7,8 +7,8 @@ dependencies:
|
||||
- node
|
||||
- migrate
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+3
-3
@@ -6,8 +6,8 @@ package: Testing
|
||||
dependencies:
|
||||
- migrate
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+3
-3
@@ -5,8 +5,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+3
-3
@@ -6,8 +6,8 @@ package: Testing
|
||||
dependencies:
|
||||
- migrate
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
name: 'Migration directory test'
|
||||
type: module
|
||||
package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
dependencies:
|
||||
- migrate
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1520457825
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
id: migration_templates_test
|
||||
label: Migration templates test
|
||||
source:
|
||||
plugin: embedded_data
|
||||
process:
|
||||
id: id
|
||||
destination:
|
||||
plugin: null
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Drupal\Tests\migrate\Functional\process;
|
||||
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
@@ -51,7 +50,7 @@ class DownloadFunctionalTest extends BrowserTestBase {
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$result = $executable->import();
|
||||
|
||||
// Check that the migration has completed.
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTestMul;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
@@ -45,6 +45,11 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Enable two required fields with default values: a single-value field and
|
||||
// a multi-value field.
|
||||
\Drupal::state()->set('entity_test.required_default_field', TRUE);
|
||||
\Drupal::state()->set('entity_test.required_multi_default_field', TRUE);
|
||||
$this->installEntitySchema('entity_test_mul');
|
||||
|
||||
ConfigurableLanguage::createFromLangcode('en')->save();
|
||||
@@ -191,7 +196,7 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
|
||||
];
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$result = $executable->import();
|
||||
$this->assertEquals(MigrationInterface::RESULT_COMPLETED, $result);
|
||||
|
||||
@@ -239,7 +244,7 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')
|
||||
->createStubMigration($definition);
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$executable->import();
|
||||
|
||||
/** @var \Drupal\migrate_entity_test\Entity\StringIdEntityTest $entity */
|
||||
@@ -256,7 +261,7 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')
|
||||
->createStubMigration($definition);
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$executable->import();
|
||||
|
||||
/** @var \Drupal\migrate_entity_test\Entity\StringIdEntityTest $entity */
|
||||
@@ -266,4 +271,34 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
|
||||
$this->assertNull($entity->version->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests stub rows.
|
||||
*/
|
||||
public function testStubRows() {
|
||||
// Create a destination.
|
||||
$this->createDestination([]);
|
||||
|
||||
// Import a stub row.
|
||||
$row = new Row([], [], TRUE);
|
||||
$row->setDestinationProperty('type', 'test');
|
||||
$ids = $this->destination->import($row);
|
||||
$this->assertCount(1, $ids);
|
||||
|
||||
// Make sure the entity was saved.
|
||||
$entity = EntityTestMul::load(reset($ids));
|
||||
$this->assertInstanceOf(EntityTestMul::class, $entity);
|
||||
// Make sure the default value was applied to the required fields.
|
||||
$single_field_name = 'required_default_field';
|
||||
$single_default_value = $entity->getFieldDefinition($single_field_name)->getDefaultValueLiteral();
|
||||
$this->assertSame($single_default_value, $entity->get($single_field_name)->getValue());
|
||||
|
||||
$multi_field_name = 'required_multi_default_field';
|
||||
$multi_default_value = $entity->getFieldDefinition($multi_field_name)->getDefaultValueLiteral();
|
||||
$count = 3;
|
||||
$this->assertCount($count, $multi_default_value);
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$this->assertSame($multi_default_value[$i], $entity->get($multi_field_name)->get($i)->getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ use Drupal\migrate\Event\MigrateMapDeleteEvent;
|
||||
use Drupal\migrate\Event\MigrateMapSaveEvent;
|
||||
use Drupal\migrate\Event\MigratePostRowSaveEvent;
|
||||
use Drupal\migrate\Event\MigratePreRowSaveEvent;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Event\MigrateEvents;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
@@ -76,7 +75,7 @@ class MigrateEventsTest extends KernelTestBase {
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
// As the import runs, events will be dispatched, recording the received
|
||||
// information in state.
|
||||
$executable->import();
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\migrate\Event\MigratePostRowSaveEvent;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Event\MigrateEvents;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
@@ -56,7 +55,7 @@ class MigrateInterruptionTest extends KernelTestBase {
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
// When the import runs, the first row imported will trigger an
|
||||
// interruption.
|
||||
$result = $executable->import();
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
@@ -50,7 +49,7 @@ class MigrateSkipRowTest extends KernelTestBase {
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$result = $executable->import();
|
||||
$this->assertEqual($result, MigrationInterface::RESULT_COMPLETED);
|
||||
|
||||
@@ -85,7 +84,7 @@ class MigrateSkipRowTest extends KernelTestBase {
|
||||
];
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$result = $executable->import();
|
||||
$this->assertEquals($result, MigrationInterface::RESULT_COMPLETED);
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel\Plugin;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
|
||||
/**
|
||||
* Tests that migrations exist in the migration_templates directory.
|
||||
*
|
||||
* @group migrate
|
||||
* @group legacy
|
||||
*/
|
||||
class MigrationDirectoryTest extends MigrateDrupalTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migration_directory_test'];
|
||||
|
||||
/**
|
||||
* Tests that migrations in the migration_templates directory are created.
|
||||
*
|
||||
* @expectedDeprecationMessage Use of the /migration_templates directory to store migration configuration files is deprecated in Drupal 8.1.0 and will be removed before Drupal 9.0.0.
|
||||
*/
|
||||
public function testMigrationDirectory() {
|
||||
/** @var \Drupal\migrate\Plugin\MigrationPluginManager $plugin_manager */
|
||||
$plugin_manager = $this->container->get('plugin.manager.migration');
|
||||
// Tests that a migration in directory 'migration_templates' is discovered.
|
||||
$this->assertTrue($plugin_manager->hasDefinition('migration_templates_test'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel\Plugin;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use Drupal\migrate\Plugin\Exception\BadPluginDefinitionException;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
|
||||
/**
|
||||
@@ -16,49 +17,215 @@ class MigrationProvidersExistTest extends MigrateDrupalTestBase {
|
||||
use FileSystemModuleDiscoveryDataProviderTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Tests that a missing source_module property raises an exception.
|
||||
*/
|
||||
public static $modules = ['migration_provider_test'];
|
||||
public function testSourceProvider() {
|
||||
$this->enableModules(['migration_provider_test']);
|
||||
$this->setExpectedException(BadPluginDefinitionException::class, 'The no_source_module plugin must define the source_module property.');
|
||||
$this->container->get('plugin.manager.migration')->getDefinition('migration_provider_no_annotation');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that modules exist for all source and destination plugins.
|
||||
* Tests that modules exist for all source plugins.
|
||||
*/
|
||||
public function testProvidersExist() {
|
||||
$this->enableAllModules();
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\MigrationPluginManager $plugin_manager */
|
||||
$plugin_manager = $this->container->get('plugin.manager.migration');
|
||||
|
||||
// Instantiate all migrations.
|
||||
$migrations = array_keys($plugin_manager->getDefinitions());
|
||||
$migrations = $plugin_manager->createInstances($migrations);
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
foreach ($migrations as $migration) {
|
||||
$this->assertInternalType('string', $migration->getSourcePlugin()->getSourceModule());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable all available modules.
|
||||
*/
|
||||
protected function enableAllModules() {
|
||||
// Install all available modules.
|
||||
$module_handler = $this->container->get('module_handler');
|
||||
$modules = $this->coreModuleListDataProvider();
|
||||
$modules_enabled = $module_handler->getModuleList();
|
||||
$modules_to_enable = array_keys(array_diff_key($modules, $modules_enabled));
|
||||
$this->enableModules($modules_to_enable);
|
||||
}
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\MigrationPluginManager $plugin_manager */
|
||||
$plugin_manager = $this->container->get('plugin.manager.migration');
|
||||
// Get all the migrations
|
||||
$migrations = $plugin_manager->createInstances(array_keys($plugin_manager->getDefinitions()));
|
||||
// Ensure the test module was enabled.
|
||||
$this->assertTrue(array_key_exists('migration_provider_test', $migrations));
|
||||
$this->assertTrue(array_key_exists('migration_provider_no_annotation', $migrations));
|
||||
/** @var \Drupal\migrate\Plugin\Migration $migration */
|
||||
foreach ($migrations as $migration) {
|
||||
$source_module = $migration->getSourcePlugin()->getSourceModule();
|
||||
$destination_module = $migration->getDestinationPlugin()->getDestinationModule();
|
||||
$migration_id = $migration->getPluginId();
|
||||
if ($migration_id == 'migration_provider_test') {
|
||||
$this->assertFalse($source_module, new FormattableMarkup('Source module not found for @migration_id.', ['@migration_id' => $migration_id]));
|
||||
$this->assertFalse($destination_module, new FormattableMarkup('Destination module not found for @migration_id.', ['@migration_id' => $migration_id]));
|
||||
}
|
||||
elseif ($migration_id == 'migration_provider_no_annotation') {
|
||||
$this->assertFalse($source_module, new FormattableMarkup('Source module not found for @migration_id.', ['@migration_id' => $migration_id]));
|
||||
$this->assertTrue($destination_module, new FormattableMarkup('Destination module found for @migration_id.', ['@migration_id' => $migration_id]));
|
||||
}
|
||||
else {
|
||||
$this->assertTrue($source_module, new FormattableMarkup('Source module found for @migration_id.', ['@migration_id' => $migration_id]));
|
||||
$this->assertTrue($destination_module, new FormattableMarkup('Destination module found for @migration_id.', ['@migration_id' => $migration_id]));
|
||||
}
|
||||
// Destination module can't be migrate or migrate_drupal or migrate_drupal_ui
|
||||
$invalid_destinations = ['migrate', 'migrate_drupal', 'migrate_drupal_ui'];
|
||||
$this->assertNotContains($destination_module, $invalid_destinations, new FormattableMarkup('Invalid destination for @migration_id.', ['@migration_id' => $migration_id]));
|
||||
/**
|
||||
* Tests that modules exist for all field plugins.
|
||||
*/
|
||||
public function testFieldProvidersExist() {
|
||||
$expected_mappings = [
|
||||
'userreference' => [
|
||||
'source_module' => 'userreference',
|
||||
'destination_module' => 'core',
|
||||
],
|
||||
'nodereference' => [
|
||||
'source_module' => 'nodereference',
|
||||
'destination_module' => 'core',
|
||||
],
|
||||
'optionwidgets' => [
|
||||
'source_module' => 'optionwidgets',
|
||||
'destination_module' => 'options',
|
||||
],
|
||||
'list' => [
|
||||
'source_module' => 'list',
|
||||
'destination_module' => 'options',
|
||||
],
|
||||
'options' => [
|
||||
'source_module' => 'options',
|
||||
'destination_module' => 'options',
|
||||
],
|
||||
'filefield' => [
|
||||
'source_module' => 'filefield',
|
||||
'destination_module' => 'file',
|
||||
],
|
||||
'imagefield' => [
|
||||
'source_module' => 'imagefield',
|
||||
'destination_module' => 'image',
|
||||
],
|
||||
'file' => [
|
||||
'source_module' => 'file',
|
||||
'destination_module' => 'file',
|
||||
],
|
||||
'image' => [
|
||||
'source_module' => 'image',
|
||||
'destination_module' => 'image',
|
||||
],
|
||||
'phone' => [
|
||||
'source_module' => 'phone',
|
||||
'destination_module' => 'telephone',
|
||||
],
|
||||
'link' => [
|
||||
'source_module' => 'link',
|
||||
'destination_module' => 'link',
|
||||
],
|
||||
'link_field' => [
|
||||
'source_module' => 'link',
|
||||
'destination_module' => 'link',
|
||||
],
|
||||
'd6_text' => [
|
||||
'source_module' => 'text',
|
||||
'destination_module' => 'text',
|
||||
],
|
||||
'd7_text' => [
|
||||
'source_module' => 'text',
|
||||
'destination_module' => 'text',
|
||||
],
|
||||
'taxonomy_term_reference' => [
|
||||
'source_module' => 'taxonomy',
|
||||
'destination_module' => 'core',
|
||||
],
|
||||
'date' => [
|
||||
'source_module' => 'date',
|
||||
'destination_module' => 'datetime',
|
||||
],
|
||||
'datetime' => [
|
||||
'source_module' => 'date',
|
||||
'destination_module' => 'datetime',
|
||||
],
|
||||
'email' => [
|
||||
'source_module' => 'email',
|
||||
'destination_module' => 'core',
|
||||
],
|
||||
'number_default' => [
|
||||
'source_module' => 'number',
|
||||
'destination_module' => 'core',
|
||||
],
|
||||
'entityreference' => [
|
||||
'source_module' => 'entityreference',
|
||||
'destination_module' => 'core',
|
||||
],
|
||||
];
|
||||
$this->enableAllModules();
|
||||
|
||||
$definitions = $this->container->get('plugin.manager.migrate.field')->getDefinitions();
|
||||
foreach ($definitions as $key => $definition) {
|
||||
$this->assertArrayHasKey($key, $expected_mappings);
|
||||
$this->assertEquals($expected_mappings[$key]['source_module'], $definition['source_module']);
|
||||
$this->assertEquals($expected_mappings[$key]['destination_module'], $definition['destination_module']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a missing required definition.
|
||||
*
|
||||
* @param array $definitions
|
||||
* A field plugin definition.
|
||||
* @param string $missing_property
|
||||
* The name of the property missing from the definition.
|
||||
*
|
||||
* @dataProvider fieldPluginDefinitionsProvider
|
||||
*/
|
||||
public function testFieldProviderMissingRequiredProperty(array $definitions, $missing_property) {
|
||||
$discovery = $this->getMockBuilder(MigrateFieldPluginManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getDefinitions'])
|
||||
->getMock();
|
||||
$discovery->method('getDefinitions')
|
||||
->willReturn($definitions);
|
||||
|
||||
$plugin_manager = $this->getMockBuilder(MigrateFieldPluginManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getDiscovery'])
|
||||
->getMock();
|
||||
$plugin_manager->method('getDiscovery')
|
||||
->willReturn($discovery);
|
||||
|
||||
$this->setExpectedException(BadPluginDefinitionException::class, "The missing_{$missing_property} plugin must define the $missing_property property.");
|
||||
$plugin_manager->getDefinitions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for field plugin definitions.
|
||||
*
|
||||
* @return array
|
||||
* Array of plugin definitions.
|
||||
*/
|
||||
public function fieldPluginDefinitionsProvider() {
|
||||
return [
|
||||
'missing_core_scenario' => [
|
||||
'definitions' => [
|
||||
'missing_core' => [
|
||||
'source_module' => 'migrate',
|
||||
'destination_module' => 'migrate',
|
||||
'id' => 'missing_core',
|
||||
'class' => 'foo',
|
||||
'provider' => 'foo',
|
||||
],
|
||||
],
|
||||
'missing_property' => 'core',
|
||||
],
|
||||
'missing_source_scenario' => [
|
||||
'definitions' => [
|
||||
'missing_source_module' => [
|
||||
'core' => [6, 7],
|
||||
'destination_module' => 'migrate',
|
||||
'id' => 'missing_source_module',
|
||||
'class' => 'foo',
|
||||
'provider' => 'foo',
|
||||
],
|
||||
],
|
||||
'missing_property' => 'source_module',
|
||||
],
|
||||
'missing_destination_scenario' => [
|
||||
'definitions' => [
|
||||
'missing_destination_module' => [
|
||||
'core' => [6, 7],
|
||||
'source_module' => 'migrate',
|
||||
'id' => 'missing_destination_module',
|
||||
'class' => 'foo',
|
||||
'provider' => 'foo',
|
||||
],
|
||||
],
|
||||
'missing_property' => 'destination_module',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\Core\Database\Query\ConditionInterface;
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
use Drupal\Core\Database\StatementInterface;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\migrate\Plugin\migrate\source\SqlBase;
|
||||
@@ -46,8 +47,8 @@ class SqlBaseTest extends MigrateTestBase {
|
||||
|
||||
// Verify that falling back to the default 'migrate' connection (defined in
|
||||
// the base class) works.
|
||||
$this->assertSame($sql_base->getDatabase()->getTarget(), 'default');
|
||||
$this->assertSame($sql_base->getDatabase()->getKey(), 'migrate');
|
||||
$this->assertSame('default', $sql_base->getDatabase()->getTarget());
|
||||
$this->assertSame('migrate', $sql_base->getDatabase()->getKey());
|
||||
|
||||
// Verify the fallback state key overrides the 'migrate' connection.
|
||||
$target = 'test_fallback_target';
|
||||
@@ -149,10 +150,10 @@ class SqlBaseTest extends MigrateTestBase {
|
||||
$source->getHighWaterStorage()->set($this->migration->id(), $high_water);
|
||||
}
|
||||
|
||||
$query_result = new \ArrayIterator($query_result);
|
||||
|
||||
$query = $this->getMock(SelectInterface::class);
|
||||
$query->method('execute')->willReturn($query_result);
|
||||
$statement = $this->createMock(StatementInterface::class);
|
||||
$statement->expects($this->atLeastOnce())->method('setFetchMode')->with(\PDO::FETCH_ASSOC);
|
||||
$query = $this->createMock(SelectInterface::class);
|
||||
$query->method('execute')->willReturn($statement);
|
||||
$query->expects($this->atLeastOnce())->method('orderBy')->with('order', 'ASC');
|
||||
|
||||
$condition_group = $this->getMock(ConditionInterface::class);
|
||||
|
||||
@@ -9,7 +9,6 @@ use Drupal\migrate\Plugin\migrate\process\Download;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
|
||||
/**
|
||||
* Tests the download process plugin.
|
||||
@@ -100,14 +99,8 @@ class DownloadTest extends FileTestBase {
|
||||
* The local URI of the downloaded file.
|
||||
*/
|
||||
protected function doTransform($destination_uri, $configuration = []) {
|
||||
// The HTTP client will return a file with contents 'It worked!'
|
||||
$body = fopen('data://text/plain;base64,SXQgd29ya2VkIQ==', 'r');
|
||||
|
||||
// Prepare a mock HTTP client.
|
||||
$this->container->set('http_client', $this->getMock(Client::class));
|
||||
$this->container->get('http_client')
|
||||
->method('get')
|
||||
->willReturn(new Response(200, [], $body));
|
||||
|
||||
// Instantiate the plugin statically so it can pull dependencies out of
|
||||
// the container.
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Drupal\Tests\migrate\Kernel\process;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
@@ -66,7 +65,7 @@ class ExtractTest extends KernelTestBase {
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$result = $executable->import();
|
||||
|
||||
// Migration needs to succeed before further assertions are made.
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Drupal\Tests\migrate\Kernel\process;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
@@ -94,7 +93,7 @@ class HandleMultiplesTest extends KernelTestBase {
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$result = $executable->import();
|
||||
|
||||
// Migration needs to succeed before further assertions are made.
|
||||
|
||||
@@ -7,7 +7,7 @@ use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Exception\RequirementsException
|
||||
* @group migration
|
||||
* @group migrate
|
||||
*/
|
||||
class RequirementsExceptionTest extends UnitTestCase {
|
||||
|
||||
|
||||
@@ -211,10 +211,10 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
}
|
||||
|
||||
// Truncate and check that 4 messages were deleted.
|
||||
$this->assertEquals($id_map->messageCount(), 4);
|
||||
$this->assertSame($id_map->messageCount(), 4);
|
||||
$id_map->clearMessages();
|
||||
$count = $id_map->messageCount();
|
||||
$this->assertEquals($count, 0);
|
||||
$this->assertSame($count, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,7 +284,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
// Test count message multiple times starting from 0.
|
||||
foreach ($expected_results as $key => $expected_result) {
|
||||
$count = $id_map->messageCount();
|
||||
$this->assertEquals($expected_result, $count);
|
||||
$this->assertSame($expected_result, $count);
|
||||
$id_map->saveMessage(['source_id_property' => $key], $message);
|
||||
}
|
||||
}
|
||||
@@ -684,21 +684,21 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$row = new Row($source, ['source_id_property' => []]);
|
||||
$destination = ['destination_id_property' => 'destination_value_failed'];
|
||||
$id_map->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_FAILED);
|
||||
$this->assertSame(0, (int) $id_map->importedCount());
|
||||
$this->assertSame(0, $id_map->importedCount());
|
||||
|
||||
// Add an imported row and assert single count.
|
||||
$source = ['source_id_property' => 'source_value_imported'];
|
||||
$row = new Row($source, ['source_id_property' => []]);
|
||||
$destination = ['destination_id_property' => 'destination_value_imported'];
|
||||
$id_map->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_IMPORTED);
|
||||
$this->assertSame(1, (int) $id_map->importedCount());
|
||||
$this->assertSame(1, $id_map->importedCount());
|
||||
|
||||
// Add a row needing update and assert multiple imported rows.
|
||||
$source = ['source_id_property' => 'source_value_update'];
|
||||
$row = new Row($source, ['source_id_property' => []]);
|
||||
$destination = ['destination_id_property' => 'destination_value_update'];
|
||||
$id_map->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
|
||||
$this->assertSame(2, (int) $id_map->importedCount());
|
||||
$this->assertSame(2, $id_map->importedCount());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -712,7 +712,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
public function testProcessedCount() {
|
||||
$id_map = $this->getIdMap();
|
||||
// Assert zero rows have been processed before adding rows.
|
||||
$this->assertSame(0, (int) $id_map->processedCount());
|
||||
$this->assertSame(0, $id_map->processedCount());
|
||||
$row_statuses = [
|
||||
MigrateIdMapInterface::STATUS_IMPORTED,
|
||||
MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
|
||||
@@ -727,11 +727,11 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$id_map->saveIdMapping($row, $destination, $status);
|
||||
if ($status == MigrateIdMapInterface::STATUS_IMPORTED) {
|
||||
// Assert a single row has been processed.
|
||||
$this->assertSame(1, (int) $id_map->processedCount());
|
||||
$this->assertSame(1, $id_map->processedCount());
|
||||
}
|
||||
}
|
||||
// Assert multiple rows have been processed.
|
||||
$this->assertSame(count($row_statuses), (int) $id_map->processedCount());
|
||||
$this->assertSame(count($row_statuses), $id_map->processedCount());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -779,7 +779,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$this->saveMap($row);
|
||||
}
|
||||
$id_map = $this->getIdMap();
|
||||
$this->assertSame($num_update_rows, (int) $id_map->updateCount());
|
||||
$this->assertSame($num_update_rows, $id_map->updateCount());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -827,7 +827,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$this->saveMap($row);
|
||||
}
|
||||
|
||||
$this->assertSame($num_error_rows, (int) $this->getIdMap()->errorCount());
|
||||
$this->assertSame($num_error_rows, $this->getIdMap()->errorCount());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,11 +78,6 @@ abstract class MigrateTestCase extends UnitTestCase {
|
||||
|
||||
$configuration = &$this->migrationConfiguration;
|
||||
|
||||
$migration->method('getHighWaterProperty')
|
||||
->willReturnCallback(function () use ($configuration) {
|
||||
return isset($configuration['high_water_property']) ? $configuration['high_water_property'] : '';
|
||||
});
|
||||
|
||||
$migration->method('set')
|
||||
->willReturnCallback(function ($argument, $value) use (&$configuration) {
|
||||
$configuration[$argument] = $value;
|
||||
|
||||
@@ -19,7 +19,7 @@ use Drupal\Tests\UnitTestCase;
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\Migration
|
||||
*
|
||||
* @group Migration
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrationTest extends UnitTestCase {
|
||||
|
||||
|
||||
+13
-6
@@ -8,9 +8,9 @@
|
||||
namespace Drupal\Tests\migrate\Unit\Plugin\migrate\destination;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\ContentEntityType;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
@@ -38,6 +38,11 @@ class EntityContentBaseTest extends UnitTestCase {
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\EntityTypeInterface
|
||||
*/
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
@@ -51,6 +56,11 @@ class EntityContentBaseTest extends UnitTestCase {
|
||||
|
||||
$this->migration = $this->prophesize(MigrationInterface::class);
|
||||
$this->storage = $this->prophesize(EntityStorageInterface::class);
|
||||
|
||||
$this->entityType = $this->prophesize(EntityTypeInterface::class);
|
||||
$this->entityType->getPluralLabel()->willReturn('wonkiness');
|
||||
$this->storage->getEntityType()->willReturn($this->entityType->reveal());
|
||||
|
||||
$this->entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
@@ -104,14 +114,11 @@ class EntityContentBaseTest extends UnitTestCase {
|
||||
*/
|
||||
public function testUntranslatable() {
|
||||
// An entity type without a language.
|
||||
$entity_type = $this->prophesize(ContentEntityType::class);
|
||||
$entity_type->getKey('langcode')->willReturn('');
|
||||
$entity_type->getKey('id')->willReturn('id');
|
||||
$this->entityType->getKey('langcode')->willReturn('');
|
||||
$this->entityType->getKey('id')->willReturn('id');
|
||||
$this->entityManager->getBaseFieldDefinitions('foo')
|
||||
->willReturn(['id' => BaseFieldDefinitionTest::create('integer')]);
|
||||
|
||||
$this->storage->getEntityType()->willReturn($entity_type->reveal());
|
||||
|
||||
$destination = new EntityTestDestination(
|
||||
['translations' => TRUE],
|
||||
'',
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Drupal\Tests\migrate\Unit\destination;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityRevision as RealEntityRevision;
|
||||
use Drupal\migrate\Row;
|
||||
@@ -48,6 +49,12 @@ class EntityRevisionTest extends UnitTestCase {
|
||||
// Setup mocks to be used when creating a revision destination.
|
||||
$this->migration = $this->prophesize(MigrationInterface::class);
|
||||
$this->storage = $this->prophesize('\Drupal\Core\Entity\EntityStorageInterface');
|
||||
|
||||
$entity_type = $this->prophesize(EntityTypeInterface::class);
|
||||
$entity_type->getSingularLabel()->willReturn('crazy');
|
||||
$entity_type->getPluralLabel()->willReturn('craziness');
|
||||
$this->storage->getEntityType()->willReturn($entity_type->reveal());
|
||||
|
||||
$this->entityManager = $this->prophesize('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->fieldTypeManager = $this->prophesize('\Drupal\Core\Field\FieldTypePluginManagerInterface');
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@ class PerComponentEntityDisplayTest extends MigrateTestCase {
|
||||
->method('save')
|
||||
->with();
|
||||
$plugin = new TestPerComponentEntityDisplay($entity);
|
||||
$this->assertSame($plugin->import($row), ['entity_type_test', 'bundle_test', 'view_mode_test', 'field_name_test']);
|
||||
$this->assertSame($plugin->getTestValues(), ['entity_type_test', 'bundle_test', 'view_mode_test']);
|
||||
$this->assertSame(['entity_type_test', 'bundle_test', 'view_mode_test', 'field_name_test'], $plugin->import($row));
|
||||
$this->assertSame(['entity_type_test', 'bundle_test', 'view_mode_test'], $plugin->getTestValues());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -44,8 +44,8 @@ class PerComponentEntityFormDisplayTest extends MigrateTestCase {
|
||||
->method('save')
|
||||
->with();
|
||||
$plugin = new TestPerComponentEntityFormDisplay($entity);
|
||||
$this->assertSame($plugin->import($row), ['entity_type_test', 'bundle_test', 'form_mode_test', 'field_name_test']);
|
||||
$this->assertSame($plugin->getTestValues(), ['entity_type_test', 'bundle_test', 'form_mode_test']);
|
||||
$this->assertSame(['entity_type_test', 'bundle_test', 'form_mode_test', 'field_name_test'], $plugin->import($row));
|
||||
$this->assertSame(['entity_type_test', 'bundle_test', 'form_mode_test'], $plugin->getTestValues());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class CallbackTest extends MigrateProcessTestCase {
|
||||
public function testCallbackWithFunction() {
|
||||
$this->plugin->setCallable('strtolower');
|
||||
$value = $this->plugin->transform('FooBar', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'foobar');
|
||||
$this->assertSame('foobar', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +39,7 @@ class CallbackTest extends MigrateProcessTestCase {
|
||||
public function testCallbackWithClassMethod() {
|
||||
$this->plugin->setCallable(['\Drupal\Component\Utility\Unicode', 'strtolower']);
|
||||
$value = $this->plugin->transform('FooBar', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'foobar');
|
||||
$this->assertSame('foobar', $value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class ConcatTest extends MigrateProcessTestCase {
|
||||
*/
|
||||
public function testConcatWithoutDelimiter() {
|
||||
$value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'foobar');
|
||||
$this->assertSame('foobar', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +47,7 @@ class ConcatTest extends MigrateProcessTestCase {
|
||||
public function testConcatWithDelimiter() {
|
||||
$this->plugin->setDelimiter('_');
|
||||
$value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'foo_bar');
|
||||
$this->assertSame('foo_bar', $value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class ExplodeTest extends MigrateProcessTestCase {
|
||||
*/
|
||||
public function testTransform() {
|
||||
$value = $this->plugin->transform('foo,bar,tik', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ['foo', 'bar', 'tik']);
|
||||
$this->assertSame(['foo', 'bar', 'tik'], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ class ExplodeTest extends MigrateProcessTestCase {
|
||||
public function testTransformLimit() {
|
||||
$plugin = new Explode(['delimiter' => '_', 'limit' => 2], 'map', []);
|
||||
$value = $plugin->transform('foo_bar_tik', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ['foo', 'bar_tik']);
|
||||
$this->assertSame(['foo', 'bar_tik'], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +49,7 @@ class ExplodeTest extends MigrateProcessTestCase {
|
||||
|
||||
$concat = new Concat([], 'map', []);
|
||||
$concatenated = $concat->transform($exploded, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($concatenated, 'foobartik');
|
||||
$this->assertSame('foobartik', $concatenated);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,7 @@ class ExtractTest extends MigrateProcessTestCase {
|
||||
*/
|
||||
public function testExtract() {
|
||||
$value = $this->plugin->transform(['foo' => 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'bar');
|
||||
$this->assertSame('bar', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ class ExtractTest extends MigrateProcessTestCase {
|
||||
public function testExtractFailDefault() {
|
||||
$plugin = new Extract(['index' => ['foo'], 'default' => 'test'], 'map', []);
|
||||
$value = $plugin->transform(['bar' => 'foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'test', '');
|
||||
$this->assertSame('test', $value, '');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class FlattenTest extends MigrateProcessTestCase {
|
||||
public function testFlatten() {
|
||||
$plugin = new Flatten([], 'flatten', []);
|
||||
$flattened = $plugin->transform([1, 2, [3, 4, [5]], [], [7, 8]], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($flattened, [1, 2, 3, 4, 5, 7, 8]);
|
||||
$this->assertSame([1, 2, 3, 4, 5, 7, 8], $flattened);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,6 +56,40 @@ class FormatDateTest extends MigrateProcessTestCase {
|
||||
$this->plugin->transform('January 5, 1955', $this->migrateExecutable, $this->row, 'field_date');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that "timezone" configuration key triggers deprecation error.
|
||||
*
|
||||
* @covers ::transform
|
||||
*
|
||||
* @dataProvider providerTestDeprecatedTimezoneConfigurationKey
|
||||
*
|
||||
* @group legacy
|
||||
* @expectedDeprecation Configuration key "timezone" is deprecated in 8.4.x and will be removed before Drupal 9.0.0, use "from_timezone" and "to_timezone" instead. See https://www.drupal.org/node/2885746
|
||||
*/
|
||||
public function testDeprecatedTimezoneConfigurationKey($configuration, $value, $expected) {
|
||||
$this->plugin = new FormatDate($configuration, 'test_format_date', []);
|
||||
$actual = $this->plugin->transform($value, $this->migrateExecutable, $this->row, 'field_date');
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testDeprecatedTimezoneConfigurationKey.
|
||||
*/
|
||||
public function providerTestDeprecatedTimezoneConfigurationKey() {
|
||||
return [
|
||||
[
|
||||
'configuration' => [
|
||||
'from_format' => 'Y-m-d\TH:i:sO',
|
||||
'to_format' => 'c e',
|
||||
'timezone' => 'America/Managua',
|
||||
],
|
||||
'value' => '2004-12-19T10:19:42-0600',
|
||||
'expected' => '2004-12-19T10:19:42-06:00 -06:00'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests transformation.
|
||||
*
|
||||
@@ -96,10 +130,10 @@ class FormatDateTest extends MigrateProcessTestCase {
|
||||
'datetime_datetime' => [
|
||||
'configuration' => [
|
||||
'from_format' => 'm/d/Y H:i:s',
|
||||
'to_format' => 'Y-m-d\TH:i:s',
|
||||
'to_format' => 'Y-m-d\TH:i:s e',
|
||||
],
|
||||
'value' => '01/05/1955 10:43:22',
|
||||
'expected' => '1955-01-05T10:43:22',
|
||||
'expected' => '1955-01-05T10:43:22 Australia/Sydney',
|
||||
],
|
||||
'empty_values' => [
|
||||
'configuration' => [
|
||||
@@ -109,14 +143,37 @@ class FormatDateTest extends MigrateProcessTestCase {
|
||||
'value' => '',
|
||||
'expected' => '',
|
||||
],
|
||||
'timezone' => [
|
||||
'timezone_from_to' => [
|
||||
'configuration' => [
|
||||
'from_format' => 'Y-m-d\TH:i:sO',
|
||||
'to_format' => 'Y-m-d\TH:i:s',
|
||||
'timezone' => 'America/Managua',
|
||||
'from_format' => 'Y-m-d H:i:s',
|
||||
'to_format' => 'Y-m-d H:i:s e',
|
||||
'from_timezone' => 'America/Managua',
|
||||
'to_timezone' => 'UTC',
|
||||
],
|
||||
'value' => '2004-12-19T10:19:42-0600',
|
||||
'expected' => '2004-12-19T10:19:42',
|
||||
'value' => '2004-12-19 10:19:42',
|
||||
'expected' => '2004-12-19 16:19:42 UTC',
|
||||
],
|
||||
'timezone_from' => [
|
||||
'configuration' => [
|
||||
'from_format' => 'Y-m-d h:i:s',
|
||||
'to_format' => 'Y-m-d h:i:s e',
|
||||
'from_timezone' => 'America/Managua',
|
||||
],
|
||||
'value' => '2004-11-19 10:25:33',
|
||||
// Unit tests use Australia/Sydney timezone, so date value will be
|
||||
// converted from America/Managua to Australia/Sydney timezone.
|
||||
'expected' => '2004-11-20 03:25:33 Australia/Sydney',
|
||||
],
|
||||
'timezone_to' => [
|
||||
'configuration' => [
|
||||
'from_format' => 'Y-m-d H:i:s',
|
||||
'to_format' => 'Y-m-d H:i:s e',
|
||||
'to_timezone' => 'America/Managua',
|
||||
],
|
||||
'value' => '2004-12-19 10:19:42',
|
||||
// Unit tests use Australia/Sydney timezone, so date value will be
|
||||
// converted from Australia/Sydney to America/Managua timezone.
|
||||
'expected' => '2004-12-18 17:19:42 America/Managua',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class GetTest extends MigrateProcessTestCase {
|
||||
->will($this->returnValue('source_value'));
|
||||
$this->plugin->setSource('test');
|
||||
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'source_value');
|
||||
$this->assertSame('source_value', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +52,7 @@ class GetTest extends MigrateProcessTestCase {
|
||||
return $map[$argument];
|
||||
}));
|
||||
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ['source_value1', 'source_value2']);
|
||||
$this->assertSame(['source_value1', 'source_value2'], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,7 @@ class GetTest extends MigrateProcessTestCase {
|
||||
->will($this->returnValue('source_value'));
|
||||
$this->plugin->setSource('@@test');
|
||||
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'source_value');
|
||||
$this->assertSame('source_value', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ class GetTest extends MigrateProcessTestCase {
|
||||
return $map[$argument];
|
||||
}));
|
||||
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ['source_value1', 'source_value2', 'source_value3', 'source_value4']);
|
||||
$this->assertSame(['source_value1', 'source_value2', 'source_value3', 'source_value4'], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,10 +75,10 @@ class IteratorTest extends MigrateTestCase {
|
||||
// values ended up in the proper destinations, and that the value of the
|
||||
// key (@id) is the same as the destination ID (42).
|
||||
$new_value = $plugin->transform($current_value, $migrate_executable, $row, 'test');
|
||||
$this->assertSame(count($new_value), 1);
|
||||
$this->assertSame(count($new_value[42]), 2);
|
||||
$this->assertSame($new_value[42]['foo'], 'test');
|
||||
$this->assertSame($new_value[42]['id'], 42);
|
||||
$this->assertSame(1, count($new_value));
|
||||
$this->assertSame(2, count($new_value[42]));
|
||||
$this->assertSame('test', $new_value[42]['foo']);
|
||||
$this->assertSame(42, $new_value[42]['id']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Plugin\MigratePluginManager;
|
||||
use Drupal\migrate\Plugin\MigrateSourceInterface;
|
||||
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
@@ -100,6 +101,8 @@ class MigrationLookupTest extends MigrateProcessTestCase {
|
||||
'migration' => 'foobaz',
|
||||
];
|
||||
$migration_plugin->id()->willReturn(uniqid());
|
||||
$migration_plugin_manager->createInstances(['foobaz'])
|
||||
->willReturn(['foobaz' => $migration_plugin->reveal()]);
|
||||
$migration = new MigrationLookup($configuration, 'migration_lookup', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
|
||||
$this->setExpectedException(MigrateSkipProcessException::class);
|
||||
$migration->transform(0, $this->migrateExecutable, $this->row, 'foo');
|
||||
@@ -238,4 +241,61 @@ class MigrationLookupTest extends MigrateProcessTestCase {
|
||||
$migration->transform(1, $this->migrateExecutable, $this->row, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests processing multiple source IDs.
|
||||
*/
|
||||
public function testMultipleSourceIds() {
|
||||
$migration_plugin = $this->prophesize(MigrationInterface::class);
|
||||
$migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
|
||||
$process_plugin_manager = $this->prophesize(MigratePluginManager::class);
|
||||
$foobaz_migration = $this->prophesize(MigrationInterface::class);
|
||||
$get_migration = $this->prophesize(MigrationLookup::class);
|
||||
$id_map = $this->prophesize(MigrateIdMapInterface::class);
|
||||
$destination_plugin = $this->prophesize(MigrateDestinationInterface::class);
|
||||
$source_plugin = $this->prophesize(MigrateSourceInterface::class);
|
||||
|
||||
$migration_plugin_manager->createInstances(['foobaz'])
|
||||
->willReturn(['foobaz' => $foobaz_migration->reveal()]);
|
||||
|
||||
$process_plugin_manager->createInstance('get', ['source' => ['string_id', 'integer_id']], $migration_plugin->reveal())
|
||||
->willReturn($get_migration->reveal());
|
||||
|
||||
$foobaz_migration->getIdMap()->willReturn($id_map->reveal());
|
||||
$foobaz_migration->getDestinationPlugin(TRUE)->willReturn($destination_plugin->reveal());
|
||||
$foobaz_migration->getProcess()->willReturn([]);
|
||||
$foobaz_migration->getSourcePlugin()->willReturn($source_plugin->reveal());
|
||||
$foobaz_migration->id()->willReturn('foobaz');
|
||||
$foobaz_migration->getSourceConfiguration()->willReturn([]);
|
||||
|
||||
$get_migration->transform(NULL, $this->migrateExecutable, $this->row, 'foo')
|
||||
->willReturn(['example_string', 99]);
|
||||
|
||||
$source_plugin_ids = [
|
||||
'string_id' => [
|
||||
'type' => 'string',
|
||||
'max_length' => 128,
|
||||
'is_ascii' => TRUE,
|
||||
'alias' => 'wpt',
|
||||
],
|
||||
'integer_id' => [
|
||||
'type' => 'integer',
|
||||
'unsigned' => FALSE,
|
||||
'alias' => 'wpt',
|
||||
],
|
||||
];
|
||||
|
||||
$stub_row = new Row(['string_id' => 'example_string', 'integer_id' => 99], $source_plugin_ids, TRUE);
|
||||
$destination_plugin->import($stub_row)->willReturn([2]);
|
||||
|
||||
$source_plugin->getIds()->willReturn($source_plugin_ids);
|
||||
|
||||
$configuration = [
|
||||
'migration' => 'foobaz',
|
||||
'source_ids' => ['foobaz' => ['string_id', 'integer_id']],
|
||||
];
|
||||
$migration = new MigrationLookup($configuration, 'migration', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
|
||||
$result = $migration->transform(NULL, $this->migrateExecutable, $this->row, 'foo');
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -124,6 +124,8 @@ class MigrationTest extends MigrateProcessTestCase {
|
||||
'migration' => 'foobaz',
|
||||
];
|
||||
$this->migration_plugin->id()->willReturn(uniqid());
|
||||
$this->migration_plugin_manager->createInstances(['foobaz'])
|
||||
->willReturn(['foobaz' => $this->migration_plugin->reveal()]);
|
||||
$migration = new Migration($configuration, 'migration', [], $this->migration_plugin->reveal(), $this->migration_plugin_manager->reveal(), $this->process_plugin_manager->reveal());
|
||||
$this->setExpectedException(MigrateSkipProcessException::class);
|
||||
$migration->transform(0, $this->migrateExecutable, $this->row, 'foo');
|
||||
|
||||
@@ -31,7 +31,7 @@ class SkipOnEmptyTest extends MigrateProcessTestCase {
|
||||
$configuration['method'] = 'process';
|
||||
$value = (new SkipOnEmpty($configuration, 'skip_on_empty', []))
|
||||
->transform(' ', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ' ');
|
||||
$this->assertSame(' ', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +51,7 @@ class SkipOnEmptyTest extends MigrateProcessTestCase {
|
||||
$configuration['method'] = 'row';
|
||||
$value = (new SkipOnEmpty($configuration, 'skip_on_empty', []))
|
||||
->transform(' ', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ' ');
|
||||
$this->assertSame(' ', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,7 +27,7 @@ class StaticMapTest extends MigrateProcessTestCase {
|
||||
*/
|
||||
public function testMapWithSourceString() {
|
||||
$value = $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ['bar' => 'baz']);
|
||||
$this->assertSame(['bar' => 'baz'], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ class StaticMapTest extends MigrateProcessTestCase {
|
||||
*/
|
||||
public function testMapWithSourceList() {
|
||||
$value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'baz');
|
||||
$this->assertSame('baz', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,7 @@ class StaticMapTest extends MigrateProcessTestCase {
|
||||
$configuration['default_value'] = 'test';
|
||||
$this->plugin = new StaticMap($configuration, 'map', []);
|
||||
$value = $this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'test');
|
||||
$this->assertSame('test', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -73,10 +73,10 @@ class SubProcessTest extends MigrateTestCase {
|
||||
// values ended up in the proper destinations, and that the value of the
|
||||
// key (@id) is the same as the destination ID (42).
|
||||
$new_value = $plugin->transform($current_value, $migrate_executable, $row, 'test');
|
||||
$this->assertSame(count($new_value), 1);
|
||||
$this->assertSame(count($new_value[42]), 2);
|
||||
$this->assertSame($new_value[42]['foo'], 'test');
|
||||
$this->assertSame($new_value[42]['id'], 42);
|
||||
$this->assertSame(1, count($new_value));
|
||||
$this->assertSame(2, count($new_value[42]));
|
||||
$this->assertSame('test', $new_value[42]['foo']);
|
||||
$this->assertSame(42, $new_value[42]['id']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\process\UrlEncode;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\migrate\Unit\MigrateTestCase;
|
||||
|
||||
@@ -56,7 +55,7 @@ class UrlEncodeTest extends MigrateTestCase {
|
||||
* Encoded URL.
|
||||
*/
|
||||
protected function doTransform($value) {
|
||||
$executable = new MigrateExecutable($this->getMigration(), new MigrateMessage());
|
||||
$executable = new MigrateExecutable($this->getMigration());
|
||||
$row = new Row();
|
||||
|
||||
return (new UrlEncode([], 'urlencode', []))
|
||||
|
||||
Reference in New Issue
Block a user