Update to Drupal 8.0.5. For more information, see https://www.drupal.org/node/2679347
This commit is contained in:
parent
2a9f1f148d
commit
fd3b12cf27
251 changed files with 5439 additions and 957 deletions
|
@ -29,6 +29,21 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
|||
* Tests the ensureTables method when the tables do not exist.
|
||||
*/
|
||||
public function testEnsureTablesNotExist() {
|
||||
$fields['source_ids_hash'] = Array(
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'not null' => 1,
|
||||
'description' => 'Hash of source ids. Used as primary key'
|
||||
);
|
||||
$fields['sourceid1'] = array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
);
|
||||
$fields['destid1'] = array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
);
|
||||
$fields['source_row_status'] = array(
|
||||
'type' => 'int',
|
||||
'size' => 'tiny',
|
||||
|
@ -58,19 +73,10 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
|||
'not null' => FALSE,
|
||||
'description' => 'Hash of source row data, for detecting changes',
|
||||
);
|
||||
$fields['sourceid1'] = array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
);
|
||||
$fields['destid1'] = array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
);
|
||||
$map_table_schema = array(
|
||||
'description' => 'Mappings from source identifier value(s) to destination identifier value(s).',
|
||||
'fields' => $fields,
|
||||
'primary key' => array('sourceid1'),
|
||||
'primary key' => array('source_ids_hash'),
|
||||
);
|
||||
$schema = $this->getMockBuilder('Drupal\Core\Database\Schema')
|
||||
->disableOriginalConstructor()
|
||||
|
@ -89,9 +95,11 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
|||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
);
|
||||
$fields['sourceid1'] = array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
$fields['source_ids_hash'] = Array(
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'not null' => 1,
|
||||
'description' => 'Hash of source ids. Used as primary key'
|
||||
);
|
||||
$fields['level'] = array(
|
||||
'type' => 'int',
|
||||
|
@ -109,7 +117,6 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
|||
'fields' => $fields,
|
||||
'primary key' => array('msgid'),
|
||||
);
|
||||
$table_schema['indexes']['sourcekey'] = array('sourceid1');
|
||||
|
||||
$schema->expects($this->at(2))
|
||||
->method('tableExists')
|
||||
|
@ -162,7 +169,20 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
|||
$schema->expects($this->at(4))
|
||||
->method('addField')
|
||||
->with('migrate_map_sql_idmap_test', 'hash', $field_schema);
|
||||
$schema->expects($this->exactly(5))
|
||||
$schema->expects($this->at(5))
|
||||
->method('fieldExists')
|
||||
->with('migrate_map_sql_idmap_test', 'source_ids_hash')
|
||||
->will($this->returnValue(FALSE));
|
||||
$field_schema = array(
|
||||
'type' => 'varchar',
|
||||
'length' => '64',
|
||||
'not null' => TRUE,
|
||||
'description' => 'Hash of source ids. Used as primary key',
|
||||
);
|
||||
$schema->expects($this->at(6))
|
||||
->method('addField')
|
||||
->with('migrate_map_sql_idmap_test', 'source_ids_hash', $field_schema);
|
||||
$schema->expects($this->exactly(7))
|
||||
->method($this->anything());
|
||||
$this->runEnsureTablesTest($schema);
|
||||
}
|
||||
|
|
|
@ -171,6 +171,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
$expected_result = [
|
||||
[
|
||||
'sourceid1' => 'source_value',
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash($source),
|
||||
'destid1' => 2,
|
||||
] + $this->idMapDefaults(),
|
||||
];
|
||||
|
@ -182,6 +183,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
$id_map->saveIdMapping($row, ['destination_id_property' => 3]);
|
||||
$expected_result[] = [
|
||||
'sourceid1' => 'source_value_1',
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash($source),
|
||||
'destid1' => 3,
|
||||
] + $this->idMapDefaults();
|
||||
$this->queryResultTest($this->getIdMapContents(), $expected_result);
|
||||
|
@ -239,6 +241,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
$id_map->saveIdMapping($row, $destination, $status);
|
||||
$expected_results[] = [
|
||||
'sourceid1' => 'source_value_' . $status,
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash($source),
|
||||
'destid1' => 'destination_value_' . $status,
|
||||
'source_row_status' => $status,
|
||||
'rollback_action' => MigrateIdMapInterface::ROLLBACK_DELETE,
|
||||
|
@ -296,20 +299,26 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
*/
|
||||
public function testMessageSave() {
|
||||
$message = 'Hello world.';
|
||||
$expected_results = [
|
||||
$original_values = [
|
||||
1 => ['message' => $message, 'level' => MigrationInterface::MESSAGE_ERROR],
|
||||
2 => ['message' => $message, 'level' => MigrationInterface::MESSAGE_WARNING],
|
||||
3 => ['message' => $message, 'level' => MigrationInterface::MESSAGE_NOTICE],
|
||||
4 => ['message' => $message, 'level' => MigrationInterface::MESSAGE_INFORMATIONAL],
|
||||
];
|
||||
$expected_results = [
|
||||
'7ad742edb7e866caa78ced1e4455d2e9cbd8adb2074e7c323d21b4e67732e755' => ['message' => $message, 'level' => MigrationInterface::MESSAGE_ERROR],
|
||||
'2d3ec2b0c547e819346e6ae03f881fd9f5c978ff3cbe29dfb807d40735e53703' => ['message' => $message, 'level' => MigrationInterface::MESSAGE_WARNING],
|
||||
'12a042f72cad9a2a8c7715df0c7695d762975f0687d87f5d480725dae1432a6f' => ['message' => $message, 'level' => MigrationInterface::MESSAGE_NOTICE],
|
||||
'd9d1fd27a2447ace48f47a2e9ff649673f67b446d9381a7963c949fc083f8791' => ['message' => $message, 'level' => MigrationInterface::MESSAGE_INFORMATIONAL],
|
||||
];
|
||||
$id_map = $this->getIdMap();
|
||||
|
||||
foreach ($expected_results as $key => $expected_result) {
|
||||
$id_map->saveMessage(['source_id_property' => $key], $message, $expected_result['level']);
|
||||
foreach ($original_values as $key => $original_value) {
|
||||
$id_map->saveMessage(['source_id_property' => $key], $message, $original_value['level']);
|
||||
}
|
||||
|
||||
foreach ($id_map->getMessageIterator() as $message_row) {
|
||||
$key = $message_row->sourceid1;
|
||||
$key = $message_row->source_ids_hash;
|
||||
$this->assertEquals($expected_results[$key]['message'], $message_row->message);
|
||||
$this->assertEquals($expected_results[$key]['level'], $message_row->level);
|
||||
}
|
||||
|
@ -344,12 +353,14 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
$row = [
|
||||
'sourceid1' => 'source_id_value_1',
|
||||
'sourceid2' => 'source_id_value_2',
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash(['source_id_property' => 'source_id_value_1']),
|
||||
'destid1' => 'destination_id_value_1',
|
||||
] + $this->idMapDefaults();
|
||||
$this->saveMap($row);
|
||||
$row = [
|
||||
'sourceid1' => 'source_id_value_3',
|
||||
'sourceid2' => 'source_id_value_4',
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash(['source_id_property' => 'source_id_value_3', 'sourceid2' => 'source_id_value_4']),
|
||||
'destid1' => 'destination_id_value_2',
|
||||
] + $this->idMapDefaults();
|
||||
$this->saveMap($row);
|
||||
|
@ -413,6 +424,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
$expected_result[] = "destination_id_value_$i";
|
||||
$this->destinationIds["destination_id_property_$i"] = [];
|
||||
}
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash($source_id_values);
|
||||
$this->saveMap($row);
|
||||
$id_map = $this->getIdMap();
|
||||
// Test for a valid hit.
|
||||
|
@ -430,12 +442,14 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
$row = [
|
||||
'sourceid1' => 'source_id_value_1',
|
||||
'sourceid2' => 'source_id_value_2',
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash(['source_id_property' => 'source_id_value_1']),
|
||||
'destid1' => 'destination_id_value_1',
|
||||
] + $this->idMapDefaults();
|
||||
$this->saveMap($row);
|
||||
$row = [
|
||||
'sourceid1' => 'source_id_value_3',
|
||||
'sourceid2' => 'source_id_value_4',
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash(['source_id_property' => 'source_id_value_3']),
|
||||
'destid1' => 'destination_id_value_2',
|
||||
] + $this->idMapDefaults();
|
||||
$this->saveMap($row);
|
||||
|
@ -487,9 +501,11 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
$this->sourceIds = [];
|
||||
$this->destinationIds = [];
|
||||
$row = $this->idMapDefaults();
|
||||
$source_ids_values = [];
|
||||
$expected_result = [];
|
||||
for ($i = 1; $i <= $num_source_fields; $i++) {
|
||||
$row["sourceid$i"] = "source_id_value_$i";
|
||||
$source_ids_values = [$row["sourceid$i"]];
|
||||
$expected_result["source_id_property_$i"] = "source_id_value_$i";
|
||||
$this->sourceIds["source_id_property_$i"] = [];
|
||||
}
|
||||
|
@ -501,6 +517,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
$nonexistent_id_values["destination_id_property_$i"] = "nonexistent_destination_id_value_$i";
|
||||
$this->destinationIds["destination_id_property_$i"] = [];
|
||||
}
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash($source_ids_values);
|
||||
$this->saveMap($row);
|
||||
$id_map = $this->getIdMap();
|
||||
// Test for a valid hit.
|
||||
|
@ -607,6 +624,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
for ($i = 0; $i < 5; $i++) {
|
||||
$row = $this->idMapDefaults();
|
||||
$row['sourceid1'] = "source_id_value_$i";
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['destid1'] = "destination_id_value_$i";
|
||||
$row['source_row_status'] = MigrateIdMapInterface::STATUS_IMPORTED;
|
||||
$this->saveMap($row);
|
||||
|
@ -614,6 +632,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
for (; $i < 5 + $num_update_rows; $i++) {
|
||||
$row = $this->idMapDefaults();
|
||||
$row['sourceid1'] = "source_id_value_$i";
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['destid1'] = "destination_id_value_$i";
|
||||
$row['source_row_status'] = MigrateIdMapInterface::STATUS_NEEDS_UPDATE;
|
||||
$this->saveMap($row);
|
||||
|
@ -653,6 +672,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
for ($i = 0; $i < 5; $i++) {
|
||||
$row = $this->idMapDefaults();
|
||||
$row['sourceid1'] = "source_id_value_$i";
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['destid1'] = "destination_id_value_$i";
|
||||
$row['source_row_status'] = MigrateIdMapInterface::STATUS_IMPORTED;
|
||||
$this->saveMap($row);
|
||||
|
@ -660,6 +680,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
for (; $i < 5 + $num_error_rows; $i++) {
|
||||
$row = $this->idMapDefaults();
|
||||
$row['sourceid1'] = "source_id_value_$i";
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['destid1'] = "destination_id_value_$i";
|
||||
$row['source_row_status'] = MigrateIdMapInterface::STATUS_FAILED;
|
||||
$this->saveMap($row);
|
||||
|
@ -687,6 +708,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
$id_map->saveIdMapping($row, $destination, $status);
|
||||
$expected_results[] = [
|
||||
'sourceid1' => 'source_value_' . $status,
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash($source),
|
||||
'destid1' => 'destination_value_' . $status,
|
||||
'source_row_status' => $status,
|
||||
'rollback_action' => MigrateIdMapInterface::ROLLBACK_DELETE,
|
||||
|
@ -815,6 +837,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
for ($i = 0; $i < 3; $i++) {
|
||||
$row = $this->idMapDefaults();
|
||||
$row['sourceid1'] = "source_id_value_$i";
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['destid1'] = "destination_id_value_$i";
|
||||
$row['source_row_status'] = MigrateIdMapInterface::STATUS_IMPORTED;
|
||||
$expected_results[serialize(['sourceid1' => $row['sourceid1']])] = ['destid1' => $row['destid1']];
|
||||
|
|
82
core/modules/migrate/tests/src/Unit/process/ExplodeTest.php
Normal file
82
core/modules/migrate/tests/src/Unit/process/ExplodeTest.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\process\ExplodeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\process\Explode;
|
||||
use Drupal\migrate\Plugin\migrate\process\Concat;
|
||||
|
||||
/**
|
||||
* Tests the Explode process plugin.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class ExplodeTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$configuration = [
|
||||
'delimiter' => ',',
|
||||
];
|
||||
$this->plugin = new Explode($configuration, 'map', []);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test explode transform process works.
|
||||
*/
|
||||
public function testTransform() {
|
||||
$value = $this->plugin->transform('foo,bar,tik', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ['foo', 'bar', 'tik']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test explode transform process works with a limit.
|
||||
*/
|
||||
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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the explode process can be chained with a handles_multiple process.
|
||||
*/
|
||||
public function testChainedTransform() {
|
||||
$exploded = $this->plugin->transform('foo,bar,tik', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
|
||||
$concat = new Concat([], 'map', []);
|
||||
$concatenated = $concat->transform($exploded, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($concatenated, 'foobartik');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test explode fails properly on non-strings.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
*
|
||||
* @expectedExceptionMessage is not a string
|
||||
*/
|
||||
public function testExplodeWithNonString() {
|
||||
$this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test explode fails with empty delimiter.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
*
|
||||
* @expectedExceptionMessage delimiter is empty
|
||||
*/
|
||||
public function testExplodeWithEmptyDelimiter() {
|
||||
$plugin = new Explode(['delimiter' => ''], 'map', []);
|
||||
$plugin->transform('foo,bar', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\process\MigrationTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\process\Migration;
|
||||
use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
|
||||
use Drupal\migrate\Plugin\MigrateDestinationInterface;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Plugin\MigratePluginManager;
|
||||
use Drupal\migrate\Plugin\MigrateSourceInterface;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\Migration
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrationTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::transform
|
||||
*/
|
||||
public function testTransformWithStubSkipping() {
|
||||
$migration_entity = $this->prophesize(MigrationInterface::class);
|
||||
$migration_storage = $this->prophesize(EntityStorageInterface::class);
|
||||
$process_plugin_manager = $this->prophesize(MigratePluginManager::class);
|
||||
|
||||
$destination_id_map = $this->prophesize(MigrateIdMapInterface::class);
|
||||
$destination_migration = $this->prophesize(MigrationInterface::class);
|
||||
$destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
|
||||
$migration_storage->loadMultiple(['destination_migration'])
|
||||
->willReturn(['destination_migration' => $destination_migration->reveal()]);
|
||||
$destination_id_map->lookupDestinationId([1])->willReturn(NULL);
|
||||
|
||||
$configuration = [
|
||||
'no_stub' => TRUE,
|
||||
'migration' => 'destination_migration',
|
||||
];
|
||||
|
||||
$migration_entity->id()->willReturn('actual_migration');
|
||||
$destination_migration->getDestinationPlugin(TRUE)->shouldNotBeCalled();
|
||||
|
||||
$migration = new Migration($configuration, '', [], $migration_entity->reveal(), $migration_storage->reveal(), $process_plugin_manager->reveal());
|
||||
$result = $migration->transform(1, $this->migrateExecutable, $this->row, '');
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::transform
|
||||
*/
|
||||
public function testTransformWithStubbing() {
|
||||
$migration_entity = $this->prophesize(MigrationInterface::class);
|
||||
$migration_storage = $this->prophesize(EntityStorageInterface::class);
|
||||
$process_plugin_manager = $this->prophesize(MigratePluginManager::class);
|
||||
|
||||
$destination_id_map = $this->prophesize(MigrateIdMapInterface::class);
|
||||
$destination_migration = $this->prophesize(MigrationInterface::class);
|
||||
$destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
|
||||
$migration_storage->loadMultiple(['destination_migration'])
|
||||
->willReturn(['destination_migration' => $destination_migration->reveal()]);
|
||||
$destination_id_map->lookupDestinationId([1])->willReturn(NULL);
|
||||
|
||||
$configuration = [
|
||||
'no_stub' => FALSE,
|
||||
'migration' => 'destination_migration',
|
||||
];
|
||||
|
||||
$migration_entity->id()->willReturn('actual_migration');
|
||||
$destination_migration->id()->willReturn('destination_migration');
|
||||
$destination_migration->getDestinationPlugin(TRUE)->shouldBeCalled();
|
||||
$destination_migration->get('process')->willReturn([]);
|
||||
$destination_migration->get('source')->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);
|
||||
$destination_plugin->import(Argument::any())->willReturn([2]);
|
||||
$destination_migration->getDestinationPlugin(TRUE)->willReturn($destination_plugin->reveal());
|
||||
|
||||
$migration = new Migration($configuration, '', [], $migration_entity->reveal(), $migration_storage->reveal(), $process_plugin_manager->reveal());
|
||||
$result = $migration->transform(1, $this->migrateExecutable, $this->row, '');
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue