upgrades core to 8.4.2
This commit is contained in:
@@ -5,8 +5,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1502903957
|
||||
datestamp: 1509719929
|
||||
|
||||
@@ -4,8 +4,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1502903957
|
||||
datestamp: 1509719929
|
||||
|
||||
+3
-3
@@ -7,8 +7,8 @@ dependencies:
|
||||
- node
|
||||
- migrate
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1502903957
|
||||
datestamp: 1509719929
|
||||
|
||||
+2
-1
@@ -8,7 +8,8 @@ use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
|
||||
* A simple migrate source for our tests.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "migrate_external_translated_test"
|
||||
* id = "migrate_external_translated_test",
|
||||
* source_module = "migrate_external_translated_test"
|
||||
* )
|
||||
*/
|
||||
class MigrateExternalTranslatedTestSource extends SourcePluginBase {
|
||||
|
||||
+3
-3
@@ -6,8 +6,8 @@ package: Testing
|
||||
dependencies:
|
||||
- migrate
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1502903957
|
||||
datestamp: 1509719929
|
||||
|
||||
+3
-3
@@ -5,8 +5,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1502903957
|
||||
datestamp: 1509719929
|
||||
|
||||
+3
-3
@@ -6,8 +6,8 @@ package: Testing
|
||||
dependencies:
|
||||
- migrate
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1502903957
|
||||
datestamp: 1509719929
|
||||
|
||||
@@ -18,13 +18,14 @@ class MigrateBundleTest extends MigrateTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['taxonomy', 'text'];
|
||||
public static $modules = ['taxonomy', 'text', 'user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('taxonomy_vocabulary');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installConfig(['taxonomy']);
|
||||
|
||||
@@ -10,6 +10,7 @@ use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_entity_test\Entity\StringIdEntityTest;
|
||||
|
||||
/**
|
||||
* Tests the EntityContentBase destination.
|
||||
@@ -204,4 +205,65 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
|
||||
$this->assertEquals(123456789012, $map_row['destid1']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests empty destinations.
|
||||
*/
|
||||
public function testEmptyDestinations() {
|
||||
$this->enableModules(['migrate_entity_test']);
|
||||
$this->installEntitySchema('migrate_string_id_entity_test');
|
||||
|
||||
$definition = [
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => [
|
||||
['id' => 123, 'version' => 'foo'],
|
||||
// This integer needs an 'int' schema with 'big' size. If 'destid1'
|
||||
// is not correctly taking the definition from the destination entity
|
||||
// type, the import will fail with an SQL exception.
|
||||
['id' => 123456789012, 'version' => 'bar'],
|
||||
],
|
||||
'ids' => [
|
||||
'id' => ['type' => 'integer', 'size' => 'big'],
|
||||
'version' => ['type' => 'string'],
|
||||
],
|
||||
'constants' => ['null' => NULL],
|
||||
],
|
||||
'process' => [
|
||||
'id' => 'id',
|
||||
'version' => 'version',
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'entity:migrate_string_id_entity_test',
|
||||
],
|
||||
];
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')
|
||||
->createStubMigration($definition);
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable->import();
|
||||
|
||||
/** @var \Drupal\migrate_entity_test\Entity\StringIdEntityTest $entity */
|
||||
$entity = StringIdEntityTest::load('123');
|
||||
$this->assertSame('foo', $entity->version->value);
|
||||
$entity = StringIdEntityTest::load('123456789012');
|
||||
$this->assertSame('bar', $entity->version->value);
|
||||
|
||||
// Rerun the migration forcing the version to NULL.
|
||||
$definition['process'] = [
|
||||
'id' => 'id',
|
||||
'version' => 'constants/null',
|
||||
];
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')
|
||||
->createStubMigration($definition);
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable->import();
|
||||
|
||||
/** @var \Drupal\migrate_entity_test\Entity\StringIdEntityTest $entity */
|
||||
$entity = StringIdEntityTest::load('123');
|
||||
$this->assertNull($entity->version->value);
|
||||
$entity = StringIdEntityTest::load('123456789012');
|
||||
$this->assertNull($entity->version->value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,13 +17,14 @@ class MigrateRollbackEntityConfigTest extends MigrateTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['field', 'taxonomy', 'text', 'language', 'config_translation'];
|
||||
public static $modules = ['field', 'taxonomy', 'text', 'language', 'config_translation', 'user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('taxonomy_vocabulary');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installConfig(['taxonomy']);
|
||||
|
||||
@@ -20,13 +20,14 @@ class MigrateRollbackTest extends MigrateTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['field', 'taxonomy', 'text'];
|
||||
public static $modules = ['field', 'taxonomy', 'text', 'user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('taxonomy_vocabulary');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installConfig(['taxonomy']);
|
||||
|
||||
@@ -39,7 +39,9 @@ abstract class MigrateSqlSourceTestBase extends MigrateSourceTestBase {
|
||||
->createTable($table, [
|
||||
// SQLite uses loose affinity typing, so it's OK for every field to
|
||||
// be a text field.
|
||||
'fields' => array_map(function() { return ['type' => 'text']; }, $pilot),
|
||||
'fields' => array_map(function () {
|
||||
return ['type' => 'text'];
|
||||
}, $pilot),
|
||||
]);
|
||||
|
||||
$fields = array_keys($pilot);
|
||||
|
||||
@@ -230,7 +230,9 @@ abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageI
|
||||
$migration = $this->getMigration($migration);
|
||||
}
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$destination = array_map(function() { return NULL; }, $migration->getDestinationPlugin()->getIds());
|
||||
$destination = array_map(function () {
|
||||
return NULL;
|
||||
}, $migration->getDestinationPlugin()->getIds());
|
||||
$row = new Row($row, $migration->getSourcePlugin()->getIds());
|
||||
$migration->getIdMap()->saveIdMapping($row, $destination, $status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
|
||||
/**
|
||||
* Provides methods for testing node and comment combinations.
|
||||
*/
|
||||
trait NodeCommentCombinationTrait {
|
||||
|
||||
/**
|
||||
* Creates a node type with a corresponding comment type.
|
||||
*
|
||||
* @param string $node_type
|
||||
* The node type ID.
|
||||
* @param string $comment_type
|
||||
* (optional) The comment type ID, if not provided defaults to
|
||||
* comment_node_{type}.
|
||||
*/
|
||||
protected function createNodeCommentCombination($node_type, $comment_type = NULL) {
|
||||
if (!$comment_type) {
|
||||
$comment_type = "comment_node_$node_type";
|
||||
}
|
||||
NodeType::create([
|
||||
'type' => $node_type,
|
||||
'label' => $this->randomString(),
|
||||
])->save();
|
||||
|
||||
CommentType::create([
|
||||
'id' => $comment_type,
|
||||
'label' => $this->randomString(),
|
||||
'target_entity_type_id' => 'node',
|
||||
])->save();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -89,7 +89,9 @@ class MigrationPluginListTest extends KernelTestBase {
|
||||
// Any database-based source plugins should fail a requirements test in the
|
||||
// absence of a source database connection (e.g., a connection with the
|
||||
// 'migrate' key).
|
||||
$source_plugins = array_map(function ($migration_plugin) { return $migration_plugin->getSourcePlugin(); }, $migration_plugins);
|
||||
$source_plugins = array_map(function ($migration_plugin) {
|
||||
return $migration_plugin->getSourcePlugin();
|
||||
}, $migration_plugins);
|
||||
foreach ($source_plugins as $id => $source_plugin) {
|
||||
if ($source_plugin instanceof RequirementsInterface) {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel\Plugin;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
|
||||
/**
|
||||
* Tests that modules exist for all source and destination plugins.
|
||||
*
|
||||
* @group migrate_drupal_ui
|
||||
*/
|
||||
class MigrationProvidersExistTest extends MigrateDrupalTestBase {
|
||||
|
||||
use FileSystemModuleDiscoveryDataProviderTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migration_provider_test'];
|
||||
|
||||
/**
|
||||
* Tests that modules exist for all source and destination plugins.
|
||||
*/
|
||||
public function testProvidersExist() {
|
||||
// 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]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,8 +7,12 @@
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\source\TestSqlBase;
|
||||
use Drupal\Core\Database\Query\ConditionInterface;
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\migrate\Plugin\migrate\source\SqlBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* Tests the functionality of SqlBase.
|
||||
@@ -17,17 +21,47 @@ use Drupal\Core\Database\Database;
|
||||
*/
|
||||
class SqlBaseTest extends MigrateTestBase {
|
||||
|
||||
/**
|
||||
* The (probably mocked) migration under test.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->migration = $this->getMock(MigrationInterface::class);
|
||||
$this->migration->method('id')->willReturn('fubar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests different connection types.
|
||||
*/
|
||||
public function testConnectionTypes() {
|
||||
$sql_base = new TestSqlBase();
|
||||
$sql_base = new TestSqlBase([], $this->migration);
|
||||
|
||||
// Check the default values.
|
||||
$sql_base->setConfiguration([]);
|
||||
$this->assertIdentical($sql_base->getDatabase()->getTarget(), 'default');
|
||||
$this->assertIdentical($sql_base->getDatabase()->getKey(), 'migrate');
|
||||
// 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');
|
||||
|
||||
// Verify the fallback state key overrides the 'migrate' connection.
|
||||
$target = 'test_fallback_target';
|
||||
$key = 'test_fallback_key';
|
||||
$config = ['target' => $target, 'key' => $key];
|
||||
$database_state_key = 'test_fallback_state';
|
||||
\Drupal::state()->set($database_state_key, $config);
|
||||
\Drupal::state()->set('migrate.fallback_state_key', $database_state_key);
|
||||
// Create a test connection using the default database configuration.
|
||||
Database::addConnectionInfo($key, $target, Database::getConnectionInfo('default')['default']);
|
||||
$this->assertSame($sql_base->getDatabase()->getTarget(), $target);
|
||||
$this->assertSame($sql_base->getDatabase()->getKey(), $key);
|
||||
|
||||
// Verify that setting explicit connection information overrides fallbacks.
|
||||
$target = 'test_db_target';
|
||||
$key = 'test_migrate_connection';
|
||||
$config = ['target' => $target, 'key' => $key];
|
||||
@@ -35,11 +69,11 @@ class SqlBaseTest extends MigrateTestBase {
|
||||
Database::addConnectionInfo($key, $target, Database::getConnectionInfo('default')['default']);
|
||||
|
||||
// Validate we have injected our custom key and target.
|
||||
$this->assertIdentical($sql_base->getDatabase()->getTarget(), $target);
|
||||
$this->assertIdentical($sql_base->getDatabase()->getKey(), $key);
|
||||
$this->assertSame($sql_base->getDatabase()->getTarget(), $target);
|
||||
$this->assertSame($sql_base->getDatabase()->getKey(), $key);
|
||||
|
||||
// Now test we can have SqlBase create the connection from an info array.
|
||||
$sql_base = new TestSqlBase();
|
||||
$sql_base = new TestSqlBase([], $this->migration);
|
||||
|
||||
$target = 'test_db_target2';
|
||||
$key = 'test_migrate_connection2';
|
||||
@@ -51,7 +85,7 @@ class SqlBaseTest extends MigrateTestBase {
|
||||
$sql_base->getDatabase();
|
||||
|
||||
// Validate the connection has been created with the right values.
|
||||
$this->assertIdentical(Database::getConnectionInfo($key)[$target], $database);
|
||||
$this->assertSame(Database::getConnectionInfo($key)[$target], $database);
|
||||
|
||||
// Now, test this all works when using state to store db info.
|
||||
$target = 'test_state_db_target';
|
||||
@@ -63,11 +97,11 @@ class SqlBaseTest extends MigrateTestBase {
|
||||
Database::addConnectionInfo($key, $target, Database::getConnectionInfo('default')['default']);
|
||||
|
||||
// Validate we have injected our custom key and target.
|
||||
$this->assertIdentical($sql_base->getDatabase()->getTarget(), $target);
|
||||
$this->assertIdentical($sql_base->getDatabase()->getKey(), $key);
|
||||
$this->assertSame($sql_base->getDatabase()->getTarget(), $target);
|
||||
$this->assertSame($sql_base->getDatabase()->getKey(), $key);
|
||||
|
||||
// Now test we can have SqlBase create the connection from an info array.
|
||||
$sql_base = new TestSqlBase();
|
||||
$sql_base = new TestSqlBase([], $this->migration);
|
||||
|
||||
$target = 'test_state_db_target2';
|
||||
$key = 'test_state_migrate_connection2';
|
||||
@@ -81,13 +115,68 @@ class SqlBaseTest extends MigrateTestBase {
|
||||
$sql_base->getDatabase();
|
||||
|
||||
// Validate the connection has been created with the right values.
|
||||
$this->assertIdentical(Database::getConnectionInfo($key)[$target], $database);
|
||||
$this->assertSame(Database::getConnectionInfo($key)[$target], $database);
|
||||
|
||||
// Verify that falling back to 'migrate' when the connection is not defined
|
||||
// throws a RequirementsException.
|
||||
\Drupal::state()->delete('migrate.fallback_state_key');
|
||||
$sql_base->setConfiguration([]);
|
||||
Database::renameConnection('migrate', 'fallback_connection');
|
||||
$this->setExpectedException(RequirementsException::class,
|
||||
'No database connection configured for source plugin');
|
||||
$sql_base->getDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that SqlBase respects high-water values.
|
||||
*
|
||||
* @param mixed $high_water
|
||||
* (optional) The high-water value to set.
|
||||
* @param array $query_result
|
||||
* (optional) The expected query results.
|
||||
*
|
||||
* @dataProvider highWaterDataProvider
|
||||
*/
|
||||
public function testHighWater($high_water = NULL, array $query_result = []) {
|
||||
$configuration = [
|
||||
'high_water_property' => [
|
||||
'name' => 'order',
|
||||
],
|
||||
];
|
||||
$source = new TestSqlBase($configuration, $this->migration);
|
||||
|
||||
if ($high_water) {
|
||||
$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);
|
||||
$query->expects($this->atLeastOnce())->method('orderBy')->with('order', 'ASC');
|
||||
|
||||
$condition_group = $this->getMock(ConditionInterface::class);
|
||||
$query->method('orConditionGroup')->willReturn($condition_group);
|
||||
|
||||
$source->setQuery($query);
|
||||
$source->rewind();
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for ::testHighWater().
|
||||
*
|
||||
* @return array
|
||||
* The scenarios to test.
|
||||
*/
|
||||
public function highWaterDataProvider() {
|
||||
return [
|
||||
'no high-water value set' => [],
|
||||
'high-water value set' => [33],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Drupal\migrate\Plugin\migrate\source;
|
||||
|
||||
/**
|
||||
* A dummy source to help with testing SqlBase.
|
||||
*
|
||||
@@ -96,10 +185,22 @@ namespace Drupal\migrate\Plugin\migrate\source;
|
||||
class TestSqlBase extends SqlBase {
|
||||
|
||||
/**
|
||||
* Overrides the constructor so we can create one easily.
|
||||
* The query to execute.
|
||||
*
|
||||
* @var \Drupal\Core\Database\Query\SelectInterface
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->state = \Drupal::state();
|
||||
protected $query;
|
||||
|
||||
/**
|
||||
* Overrides the constructor so we can create one easily.
|
||||
*
|
||||
* @param array $configuration
|
||||
* The plugin instance configuration.
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* (optional) The migration being run.
|
||||
*/
|
||||
public function __construct(array $configuration = [], MigrationInterface $migration = NULL) {
|
||||
parent::__construct($configuration, 'sql_base', [], $migration, \Drupal::state());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,6 +234,25 @@ class TestSqlBase extends SqlBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {}
|
||||
public function query() {
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the query to execute.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Query\SelectInterface $query
|
||||
* The query to execute.
|
||||
*/
|
||||
public function setQuery(SelectInterface $query) {
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHighWaterStorage() {
|
||||
return parent::getHighWaterStorage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
namespace Drupal\Tests\migrate\Unit\Event;
|
||||
|
||||
use Drupal\migrate\Event\EventBase;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Event\EventBase
|
||||
* @group migrate
|
||||
*/
|
||||
class EventBaseTest extends \PHPUnit_Framework_TestCase {
|
||||
class EventBaseTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Test getMigration method.
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
namespace Drupal\Tests\migrate\Unit\Event;
|
||||
|
||||
use Drupal\migrate\Event\MigrateImportEvent;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Event\MigrateImportEvent
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrateImportEventTest extends \PHPUnit_Framework_TestCase {
|
||||
class MigrateImportEventTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Test getMigration method.
|
||||
|
||||
@@ -439,6 +439,33 @@ class MigrateExecutableTest extends MigrateTestCase {
|
||||
$this->executable->processRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the processRow method.
|
||||
*/
|
||||
public function testProcessRowEmptyDestination() {
|
||||
$expected = [
|
||||
'test' => 'test destination',
|
||||
'test1' => 'test1 destination',
|
||||
'test2' => NULL,
|
||||
];
|
||||
$row = new Row();
|
||||
$plugins = [];
|
||||
foreach ($expected as $key => $value) {
|
||||
$plugin = $this->prophesize(MigrateProcessInterface::class);
|
||||
$plugin->getPluginDefinition()->willReturn([]);
|
||||
$plugin->transform(NULL, $this->executable, $row, $key)->willReturn($value);
|
||||
$plugin->multiple()->willReturn(TRUE);
|
||||
$plugins[$key][0] = $plugin->reveal();
|
||||
}
|
||||
$this->migration->method('getProcessPlugins')->willReturn($plugins);
|
||||
$this->executable->processRow($row);
|
||||
foreach ($expected as $key => $value) {
|
||||
$this->assertSame($value, $row->getDestinationProperty($key));
|
||||
}
|
||||
$this->assertCount(2, $row->getDestination());
|
||||
$this->assertSame(['test2'], $row->getEmptyDestinationProperties());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a mock migration source instance.
|
||||
*
|
||||
|
||||
@@ -61,12 +61,12 @@ abstract class MigrateTestCase extends UnitTestCase {
|
||||
// on the test class and use a return callback.
|
||||
$migration->expects($this->any())
|
||||
->method('getStatus')
|
||||
->willReturnCallback(function() {
|
||||
->willReturnCallback(function () {
|
||||
return $this->migrationStatus;
|
||||
});
|
||||
$migration->expects($this->any())
|
||||
->method('setStatus')
|
||||
->willReturnCallback(function($status) {
|
||||
->willReturnCallback(function ($status) {
|
||||
$this->migrationStatus = $status;
|
||||
});
|
||||
|
||||
@@ -147,7 +147,9 @@ abstract class MigrateTestCase extends UnitTestCase {
|
||||
protected function createSchemaFromRow(array $row) {
|
||||
// SQLite uses loose ("affinity") typing, so it is OK for every column to be
|
||||
// a text field.
|
||||
$fields = array_map(function() { return ['type' => 'text']; }, $row);
|
||||
$fields = array_map(function () {
|
||||
return ['type' => 'text'];
|
||||
}, $row);
|
||||
return ['fields' => $fields];
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ class TestMigrationMock extends Migration {
|
||||
/**
|
||||
* The values passed into set().
|
||||
*
|
||||
* @var array $set
|
||||
* @var array
|
||||
*/
|
||||
public $set = [];
|
||||
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ class EntityContentBaseTest extends UnitTestCase {
|
||||
$this->storage->getEntityType()->willReturn($entity_type->reveal());
|
||||
|
||||
$destination = new EntityTestDestination(
|
||||
[ 'translations' => TRUE ],
|
||||
['translations' => TRUE],
|
||||
'',
|
||||
[],
|
||||
$this->migration->reveal(),
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
@trigger_error('The ' . __NAMESPACE__ . '\DedupeEntityTest is deprecated in
|
||||
Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\MakeUniqueEntityFieldTest', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\Query\QueryInterface;
|
||||
@@ -14,14 +11,14 @@ use Drupal\Component\Utility\Unicode;
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\DedupeEntity
|
||||
* @group migrate
|
||||
* @group legacy
|
||||
*/
|
||||
class DedupeEntityTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* The mock entity query.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface|\Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $entityQuery;
|
||||
|
||||
@@ -168,7 +165,9 @@ class DedupeEntityTest extends MigrateProcessTestCase {
|
||||
->will($this->returnValue($this->entityQuery));
|
||||
$this->entityQuery->expects($this->exactly($count + 1))
|
||||
->method('execute')
|
||||
->will($this->returnCallback(function () use (&$count) { return $count--;}));
|
||||
->will($this->returnCallback(function () use (&$count) {
|
||||
return $count--;
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
use Drupal\migrate\Plugin\migrate\process\Flatten;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\process\Flatten;
|
||||
|
||||
/**
|
||||
* Tests the flatten plugin.
|
||||
|
||||
@@ -48,7 +48,9 @@ class GetTest extends MigrateProcessTestCase {
|
||||
$this->plugin->setSource(['test1', 'test2']);
|
||||
$this->row->expects($this->exactly(2))
|
||||
->method('getSourceProperty')
|
||||
->will($this->returnCallback(function ($argument) use ($map) { return $map[$argument]; } ));
|
||||
->will($this->returnCallback(function ($argument) use ($map) {
|
||||
return $map[$argument];
|
||||
}));
|
||||
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ['source_value1', 'source_value2']);
|
||||
}
|
||||
@@ -79,7 +81,9 @@ class GetTest extends MigrateProcessTestCase {
|
||||
$this->plugin->setSource(['test1', '@@test2', '@@test3', 'test4']);
|
||||
$this->row->expects($this->exactly(4))
|
||||
->method('getSourceProperty')
|
||||
->will($this->returnCallback(function ($argument) use ($map) { return $map[$argument]; } ));
|
||||
->will($this->returnCallback(function ($argument) use ($map) {
|
||||
return $map[$argument];
|
||||
}));
|
||||
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ['source_value1', 'source_value2', 'source_value3', 'source_value4']);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ class IteratorTest extends MigrateTestCase {
|
||||
|
||||
/**
|
||||
* Tests the iterator process plugin.
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
public function testIterator() {
|
||||
$migration = $this->getMigration();
|
||||
|
||||
@@ -17,8 +17,7 @@ class MakeUniqueEntityFieldTest extends MigrateProcessTestCase {
|
||||
/**
|
||||
* The mock entity query.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface|\Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $entityQuery;
|
||||
|
||||
@@ -165,7 +164,9 @@ class MakeUniqueEntityFieldTest extends MigrateProcessTestCase {
|
||||
->will($this->returnValue($this->entityQuery));
|
||||
$this->entityQuery->expects($this->exactly($count + 1))
|
||||
->method('execute')
|
||||
->will($this->returnCallback(function () use (&$count) { return $count--;}));
|
||||
->will($this->returnCallback(function () use (&$count) {
|
||||
return $count--;
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -199,4 +199,43 @@ class MigrationLookupTest extends MigrateProcessTestCase {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a message is successfully created if import fails.
|
||||
*/
|
||||
public function testImportException() {
|
||||
$migration_plugin = $this->prophesize(MigrationInterface::class);
|
||||
$migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
|
||||
$process_plugin_manager = $this->prophesize(MigratePluginManager::class);
|
||||
|
||||
$destination_id_map = $this->prophesize(MigrateIdMapInterface::class);
|
||||
$destination_migration = $this->prophesize('Drupal\migrate\Plugin\Migration');
|
||||
$destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
|
||||
$migration_plugin_manager->createInstances(['destination_migration'])
|
||||
->willReturn(['destination_migration' => $destination_migration->reveal()]);
|
||||
$destination_id_map->lookupDestinationId([1])->willReturn(NULL);
|
||||
$destination_id_map->saveMessage(Argument::any(), Argument::any())->willReturn(NULL);
|
||||
$destination_id_map->saveIdMapping(Argument::any(), Argument::any(), Argument::any())->shouldNotBeCalled();
|
||||
|
||||
$configuration = [
|
||||
'no_stub' => FALSE,
|
||||
'migration' => 'destination_migration',
|
||||
];
|
||||
|
||||
$destination_migration->id()->willReturn('destination_migration');
|
||||
$destination_migration->getDestinationPlugin(TRUE)->shouldBeCalled();
|
||||
$destination_migration->getProcess()->willReturn([]);
|
||||
$destination_migration->getSourceConfiguration()->willReturn([]);
|
||||
|
||||
$source_plugin = $this->prophesize(MigrateSourceInterface::class);
|
||||
$source_plugin->getIds()->willReturn(['nid']);
|
||||
$destination_migration->getSourcePlugin()->willReturn($source_plugin->reveal());
|
||||
$destination_plugin = $this->prophesize(MigrateDestinationInterface::class);
|
||||
$e = new \Exception();
|
||||
$destination_plugin->import(Argument::any())->willThrow($e);
|
||||
$destination_migration->getDestinationPlugin(TRUE)->willReturn($destination_plugin->reveal());
|
||||
|
||||
$migration = new MigrationLookup($configuration, '', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
|
||||
$migration->transform(1, $this->migrateExecutable, $this->row, '');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
@trigger_error('The ' . __NAMESPACE__ . '\MigrationTest is deprecated in
|
||||
Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\MigrationLookupTest', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\migrate\MigrateSkipProcessException;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
@@ -17,11 +14,9 @@ use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\Tests\migrate\Unit\process\MigrationLookupTest instead.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\Migration
|
||||
* @group migrate
|
||||
* @group legacy
|
||||
*/
|
||||
class MigrationTest extends MigrateProcessTestCase {
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\Plugin\migrate\process\Get;
|
||||
use Drupal\migrate\Plugin\migrate\process\SubProcess;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\migrate\Unit\MigrateTestCase;
|
||||
|
||||
/**
|
||||
* Tests the sub_process process plugin.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class SubProcessTest extends MigrateTestCase {
|
||||
|
||||
/**
|
||||
* The sub_process plugin being tested.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\migrate\process\SubProcess
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'test',
|
||||
];
|
||||
|
||||
/**
|
||||
* Tests the sub_process process plugin.
|
||||
*/
|
||||
public function testSubProcess() {
|
||||
$migration = $this->getMigration();
|
||||
// Set up the properties for the sub_process.
|
||||
$configuration = [
|
||||
'process' => [
|
||||
'foo' => 'source_foo',
|
||||
'id' => 'source_id',
|
||||
],
|
||||
'key' => '@id',
|
||||
];
|
||||
$plugin = new SubProcess($configuration, 'sub_process', []);
|
||||
// Manually create the plugins. Migration::getProcessPlugins does this
|
||||
// normally but the plugin system is not available.
|
||||
foreach ($configuration['process'] as $destination => $source) {
|
||||
$sub_process_plugins[$destination][] = new Get(['source' => $source], 'get', []);
|
||||
}
|
||||
$migration->expects($this->at(1))
|
||||
->method('getProcessPlugins')
|
||||
->willReturn($sub_process_plugins);
|
||||
// Set up the key plugins.
|
||||
$key_plugin['key'][] = new Get(['source' => '@id'], 'get', []);
|
||||
$migration->expects($this->at(2))
|
||||
->method('getProcessPlugins')
|
||||
->will($this->returnValue($key_plugin));
|
||||
$event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||
$migrate_executable = new MigrateExecutable($migration, $this->getMock('Drupal\migrate\MigrateMessageInterface'), $event_dispatcher);
|
||||
|
||||
// The current value of the pipeline.
|
||||
$current_value = [
|
||||
[
|
||||
'source_foo' => 'test',
|
||||
'source_id' => 42,
|
||||
],
|
||||
];
|
||||
// This is not used but the interface requires it, so create an empty row.
|
||||
$row = new Row();
|
||||
|
||||
// After transformation, check to make sure that source_foo and source_id's
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user