Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
This commit is contained in:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
|
@ -1,13 +1,8 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\migrate_events_test\Plugin\migrate\destination\DummyDestination.
|
||||
*/
|
||||
|
||||
namespace Drupal\migrate_events_test\Plugin\migrate\destination;
|
||||
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* handling.
|
||||
*/
|
||||
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
use Drupal\migrate\Plugin\MigrateSourceInterface;
|
||||
use Drupal\migrate\Row;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: url_template
|
||||
label: Template test - url
|
||||
label: Template test - URL
|
||||
migration_tags:
|
||||
- Template Test
|
||||
source:
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Kernel\Entity\MigrationTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel\Entity;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
|
||||
/**
|
||||
* Tests the Migration entity.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\migrate\Entity\Migration
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrationTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate'];
|
||||
|
||||
/**
|
||||
* @covers ::calculateDependencies
|
||||
*/
|
||||
public function testCalculateDependencies() {
|
||||
$fixture_migrations = [
|
||||
'd6_node__article' => 'd6_node',
|
||||
'd6_node__page' => 'd6_node',
|
||||
'd6_variables' => 'd6_variables',
|
||||
];
|
||||
|
||||
foreach ($fixture_migrations as $id => $template) {
|
||||
$values = [
|
||||
'id' => $id,
|
||||
'template' => $template,
|
||||
'source' => [
|
||||
'plugin' => 'empty',
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'null',
|
||||
],
|
||||
'migration_tags' => []
|
||||
];
|
||||
Migration::create($values)->save();
|
||||
}
|
||||
|
||||
$values = [
|
||||
'migration_dependencies' => [
|
||||
'required' => [
|
||||
'd6_node:*',
|
||||
'd6_variables'
|
||||
]
|
||||
],
|
||||
'source' => [
|
||||
'plugin' => 'empty',
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'null',
|
||||
],
|
||||
];
|
||||
|
||||
$migration = new Migration($values, 'migration');
|
||||
$expected = [
|
||||
'migrate.migration.d6_node__article',
|
||||
'migrate.migration.d6_node__page',
|
||||
'migrate.migration.d6_variables'
|
||||
];
|
||||
$migration->calculateDependencies();
|
||||
$this->assertEquals($expected, $migration->getDependencies()['config']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Allows tests to alter dumps after they have loaded.
|
||||
*
|
||||
* @see \Drupal\migrate_drupal\Tests\d6\MigrateFileTest
|
||||
*/
|
||||
interface MigrateDumpAlterInterface {
|
||||
|
||||
/**
|
||||
* Allows tests to alter dumps after they have loaded.
|
||||
*
|
||||
* @param \Drupal\KernelTests\KernelTestBase $test
|
||||
* The test that is being run.
|
||||
*/
|
||||
public static function migrateDumpAlter(KernelTestBase $test);
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the EmbeddedDataSource plugin.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrateEmbeddedDataTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['migrate'];
|
||||
|
||||
/**
|
||||
* Tests the embedded_data source plugin.
|
||||
*/
|
||||
public function testEmbeddedData() {
|
||||
$data_rows = [
|
||||
['key' => '1', 'field1' => 'f1value1', 'field2' => 'f2value1'],
|
||||
['key' => '2', 'field1' => 'f1value2', 'field2' => 'f2value2'],
|
||||
];
|
||||
$ids = ['key' => ['type' => 'integer']];
|
||||
$definition = [
|
||||
'migration_tags' => ['Embedded data test'],
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => $data_rows,
|
||||
'ids' => $ids,
|
||||
],
|
||||
'process' => [],
|
||||
'destination' => ['plugin' => 'null'],
|
||||
];
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
$source = $migration->getSourcePlugin();
|
||||
|
||||
// Validate the plugin returns the source data that was provided.
|
||||
$results = [];
|
||||
/** @var \Drupal\migrate\Row $row */
|
||||
foreach ($source as $row) {
|
||||
$data_row = $row->getSource();
|
||||
// The "data" row returned by getSource() also includes all source
|
||||
// configuration - we remove it so we see only the data itself.
|
||||
unset($data_row['plugin']);
|
||||
unset($data_row['data_rows']);
|
||||
unset($data_row['ids']);
|
||||
$results[] = $data_row;
|
||||
}
|
||||
$this->assertIdentical($results, $data_rows);
|
||||
|
||||
// Validate the public APIs.
|
||||
$this->assertIdentical($source->count(), count($data_rows));
|
||||
$this->assertIdentical($source->getIds(), $ids);
|
||||
$expected_fields = [
|
||||
'key' => 'key',
|
||||
'field1' => 'field1',
|
||||
'field2' => 'field2',
|
||||
];
|
||||
$this->assertIdentical($source->fields(), $expected_fields);
|
||||
}
|
||||
|
||||
}
|
218
core/modules/migrate/tests/src/Kernel/MigrateEventsTest.php
Normal file
218
core/modules/migrate/tests/src/Kernel/MigrateEventsTest.php
Normal file
|
@ -0,0 +1,218 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\migrate\Event\MigrateImportEvent;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Tests events fired on migrations.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrateEventsTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* State service for recording information received by event listeners.
|
||||
*
|
||||
* @var \Drupal\Core\State\State
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['migrate', 'migrate_events_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->state = \Drupal::state();
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::MAP_SAVE,
|
||||
array($this, 'mapSaveEventRecorder'));
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::MAP_DELETE,
|
||||
array($this, 'mapDeleteEventRecorder'));
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::PRE_IMPORT,
|
||||
array($this, 'preImportEventRecorder'));
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::POST_IMPORT,
|
||||
array($this, 'postImportEventRecorder'));
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::PRE_ROW_SAVE,
|
||||
array($this, 'preRowSaveEventRecorder'));
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::POST_ROW_SAVE,
|
||||
array($this, 'postRowSaveEventRecorder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration events.
|
||||
*/
|
||||
public function testMigrateEvents() {
|
||||
// Run a simple little migration, which should trigger one of each event
|
||||
// other than map_delete.
|
||||
$definition = [
|
||||
'migration_tags' => ['Event test'],
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => [
|
||||
['data' => 'dummy value'],
|
||||
],
|
||||
'ids' => [
|
||||
'data' => ['type' => 'string'],
|
||||
],
|
||||
],
|
||||
'process' => ['value' => 'data'],
|
||||
'destination' => ['plugin' => 'dummy'],
|
||||
];
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
// As the import runs, events will be dispatched, recording the received
|
||||
// information in state.
|
||||
$executable->import();
|
||||
|
||||
// Validate from the recorded state that the events were received.
|
||||
$event = $this->state->get('migrate_events_test.pre_import_event', []);
|
||||
$this->assertIdentical($event['event_name'], MigrateEvents::PRE_IMPORT);
|
||||
$this->assertIdentical($event['migration']->id(), $migration->id());
|
||||
|
||||
$event = $this->state->get('migrate_events_test.post_import_event', []);
|
||||
$this->assertIdentical($event['event_name'], MigrateEvents::POST_IMPORT);
|
||||
$this->assertIdentical($event['migration']->id(), $migration->id());
|
||||
|
||||
$event = $this->state->get('migrate_events_test.map_save_event', []);
|
||||
$this->assertIdentical($event['event_name'], MigrateEvents::MAP_SAVE);
|
||||
// Validating the last row processed.
|
||||
$this->assertIdentical($event['fields']['sourceid1'], 'dummy value');
|
||||
$this->assertIdentical($event['fields']['destid1'], 'dummy value');
|
||||
$this->assertIdentical($event['fields']['source_row_status'], 0);
|
||||
|
||||
$event = $this->state->get('migrate_events_test.map_delete_event', []);
|
||||
$this->assertIdentical($event, []);
|
||||
|
||||
$event = $this->state->get('migrate_events_test.pre_row_save_event', []);
|
||||
$this->assertIdentical($event['event_name'], MigrateEvents::PRE_ROW_SAVE);
|
||||
$this->assertIdentical($event['migration']->id(), $migration->id());
|
||||
// Validating the last row processed.
|
||||
$this->assertIdentical($event['row']->getSourceProperty('data'), 'dummy value');
|
||||
|
||||
$event = $this->state->get('migrate_events_test.post_row_save_event', []);
|
||||
$this->assertIdentical($event['event_name'], MigrateEvents::POST_ROW_SAVE);
|
||||
$this->assertIdentical($event['migration']->id(), $migration->id());
|
||||
// Validating the last row processed.
|
||||
$this->assertIdentical($event['row']->getSourceProperty('data'), 'dummy value');
|
||||
$this->assertIdentical($event['destination_id_values']['value'], 'dummy value');
|
||||
|
||||
// Generate a map delete event.
|
||||
$migration->getIdMap()->delete(['data' => 'dummy value']);
|
||||
$event = $this->state->get('migrate_events_test.map_delete_event', []);
|
||||
$this->assertIdentical($event['event_name'], MigrateEvents::MAP_DELETE);
|
||||
$this->assertIdentical($event['source_id'], ['data' => 'dummy value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reacts to map save event.
|
||||
*
|
||||
* @param \Drupal\Migrate\Event\MigrateMapSaveEvent $event
|
||||
* The migration event.
|
||||
* @param string $name
|
||||
* The event name.
|
||||
*/
|
||||
public function mapSaveEventRecorder(MigrateMapSaveEvent $event, $name) {
|
||||
$this->state->set('migrate_events_test.map_save_event', array(
|
||||
'event_name' => $name,
|
||||
'map' => $event->getMap(),
|
||||
'fields' => $event->getFields(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reacts to map delete event.
|
||||
*
|
||||
* @param \Drupal\Migrate\Event\MigrateMapDeleteEvent $event
|
||||
* The migration event.
|
||||
* @param string $name
|
||||
* The event name.
|
||||
*/
|
||||
public function mapDeleteEventRecorder(MigrateMapDeleteEvent $event, $name) {
|
||||
$this->state->set('migrate_events_test.map_delete_event', array(
|
||||
'event_name' => $name,
|
||||
'map' => $event->getMap(),
|
||||
'source_id' => $event->getSourceId(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reacts to pre-import event.
|
||||
*
|
||||
* @param \Drupal\Migrate\Event\MigrateImportEvent $event
|
||||
* The migration event.
|
||||
* @param string $name
|
||||
* The event name.
|
||||
*/
|
||||
public function preImportEventRecorder(MigrateImportEvent $event, $name) {
|
||||
$this->state->set('migrate_events_test.pre_import_event', array(
|
||||
'event_name' => $name,
|
||||
'migration' => $event->getMigration(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reacts to post-import event.
|
||||
*
|
||||
* @param \Drupal\Migrate\Event\MigrateImportEvent $event
|
||||
* The migration event.
|
||||
* @param string $name
|
||||
* The event name.
|
||||
*/
|
||||
public function postImportEventRecorder(MigrateImportEvent $event, $name) {
|
||||
$this->state->set('migrate_events_test.post_import_event', array(
|
||||
'event_name' => $name,
|
||||
'migration' => $event->getMigration(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reacts to pre-row-save event.
|
||||
*
|
||||
* @param \Drupal\Migrate\Event\MigratePreRowSaveEvent $event
|
||||
* The migration event.
|
||||
* @param string $name
|
||||
* The event name.
|
||||
*/
|
||||
public function preRowSaveEventRecorder(MigratePreRowSaveEvent $event, $name) {
|
||||
$this->state->set('migrate_events_test.pre_row_save_event', array(
|
||||
'event_name' => $name,
|
||||
'migration' => $event->getMigration(),
|
||||
'row' => $event->getRow(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reacts to post-row-save event.
|
||||
*
|
||||
* @param \Drupal\Migrate\Event\MigratePostRowSaveEvent $event
|
||||
* The migration event.
|
||||
* @param string $name
|
||||
* The event name.
|
||||
*/
|
||||
public function postRowSaveEventRecorder(MigratePostRowSaveEvent $event, $name) {
|
||||
$this->state->set('migrate_events_test.post_row_save_event', array(
|
||||
'event_name' => $name,
|
||||
'migration' => $event->getMigration(),
|
||||
'row' => $event->getRow(),
|
||||
'destination_id_values' => $event->getDestinationIdValues(),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
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;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests interruptions triggered during migrations.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrateInterruptionTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['migrate', 'migrate_events_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::POST_ROW_SAVE,
|
||||
array($this, 'postRowSaveEventRecorder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration interruptions.
|
||||
*/
|
||||
public function testMigrateEvents() {
|
||||
// Run a simple little migration, which should trigger one of each event
|
||||
// other than map_delete.
|
||||
$definition = [
|
||||
'migration_tags' => ['Interruption test'],
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => [
|
||||
['data' => 'dummy value'],
|
||||
['data' => 'dummy value2'],
|
||||
],
|
||||
'ids' => [
|
||||
'data' => ['type' => 'string'],
|
||||
],
|
||||
],
|
||||
'process' => ['value' => 'data'],
|
||||
'destination' => ['plugin' => 'dummy'],
|
||||
];
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
// When the import runs, the first row imported will trigger an
|
||||
// interruption.
|
||||
$result = $executable->import();
|
||||
|
||||
$this->assertEqual($result, MigrationInterface::RESULT_INCOMPLETE);
|
||||
|
||||
// The status should have been reset to IDLE.
|
||||
$this->assertEqual($migration->getStatus(), MigrationInterface::STATUS_IDLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reacts to post-row-save event.
|
||||
*
|
||||
* @param \Drupal\Migrate\Event\MigratePostRowSaveEvent $event
|
||||
* The migration event.
|
||||
* @param string $name
|
||||
* The event name.
|
||||
*/
|
||||
public function postRowSaveEventRecorder(MigratePostRowSaveEvent $event, $name) {
|
||||
$event->getMigration()->interruptMigration(MigrationInterface::RESULT_INCOMPLETE);
|
||||
}
|
||||
|
||||
}
|
126
core/modules/migrate/tests/src/Kernel/MigrateMessageTest.php
Normal file
126
core/modules/migrate/tests/src/Kernel/MigrateMessageTest.php
Normal file
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Event\MigrateEvents;
|
||||
use Drupal\migrate\Event\MigrateIdMapMessageEvent;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessageInterface;
|
||||
|
||||
/**
|
||||
* Tests whether idmap messages are sent to message interface when requested.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrateMessageTest extends KernelTestBase implements MigrateMessageInterface {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['migrate', 'system'];
|
||||
|
||||
/**
|
||||
* Migration to run.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* Messages accumulated during the migration run.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $messages = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(['system']);
|
||||
|
||||
// A simple migration, which will generate a message to the ID map because
|
||||
// the concat plugin throws an exception if its source is not an array.
|
||||
$definition = [
|
||||
'migration_tags' => ['Message test'],
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => [
|
||||
['name' => 'source_message', 'value' => 'a message'],
|
||||
],
|
||||
'ids' => [
|
||||
'name' => ['type' => 'string'],
|
||||
],
|
||||
],
|
||||
'process' => [
|
||||
'message' => [
|
||||
'plugin' => 'concat',
|
||||
'source' => 'value',
|
||||
],
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'config',
|
||||
'config_name' => 'system.maintenance',
|
||||
],
|
||||
];
|
||||
|
||||
$this->migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration interruptions.
|
||||
*/
|
||||
public function testMessagesNotTeed() {
|
||||
// We don't ask for messages to be teed, so don't expect any.
|
||||
$executable = new MigrateExecutable($this->migration, $this);
|
||||
$executable->import();
|
||||
$this->assertIdentical(count($this->messages), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration interruptions.
|
||||
*/
|
||||
public function testMessagesTeed() {
|
||||
// Ask to receive any messages sent to the idmap.
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::IDMAP_MESSAGE,
|
||||
array($this, 'mapMessageRecorder'));
|
||||
$executable = new MigrateExecutable($this->migration, $this);
|
||||
$executable->import();
|
||||
$this->assertIdentical(count($this->messages), 1);
|
||||
$this->assertIdentical(reset($this->messages), "source_message: 'a message' is not an array");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reacts to map message event.
|
||||
*
|
||||
* @param \Drupal\Migrate\Event\MigrateIdMapMessageEvent $event
|
||||
* The migration event.
|
||||
* @param string $name
|
||||
* The event name.
|
||||
*/
|
||||
public function mapMessageRecorder(MigrateIdMapMessageEvent $event, $name) {
|
||||
if ($event->getLevel() == MigrationInterface::MESSAGE_NOTICE ||
|
||||
$event->getLevel() == MigrationInterface::MESSAGE_INFORMATIONAL) {
|
||||
$type = 'status';
|
||||
}
|
||||
else {
|
||||
$type = 'error';
|
||||
}
|
||||
$source_id_string = implode(',', $event->getSourceIdValues());
|
||||
$this->display($source_id_string . ': ' . $event->getMessage(), $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function display($message, $type = 'status') {
|
||||
$this->messages[] = $message;
|
||||
}
|
||||
|
||||
}
|
180
core/modules/migrate/tests/src/Kernel/MigrateRollbackTest.php
Normal file
180
core/modules/migrate/tests/src/Kernel/MigrateRollbackTest.php
Normal file
|
@ -0,0 +1,180 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
|
||||
/**
|
||||
* Tests rolling back of imports.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrateRollbackTest extends MigrateTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['field', 'taxonomy', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('taxonomy_vocabulary');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installConfig(['taxonomy']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests rolling back configuration and content entities.
|
||||
*/
|
||||
public function testRollback() {
|
||||
// We use vocabularies to demonstrate importing and rolling back
|
||||
// configuration entities.
|
||||
$vocabulary_data_rows = [
|
||||
['id' => '1', 'name' => 'categories', 'weight' => '2'],
|
||||
['id' => '2', 'name' => 'tags', 'weight' => '1'],
|
||||
];
|
||||
$ids = ['id' => ['type' => 'integer']];
|
||||
$definition = [
|
||||
'id' => 'vocabularies',
|
||||
'migration_tags' => ['Import and rollback test'],
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => $vocabulary_data_rows,
|
||||
'ids' => $ids,
|
||||
],
|
||||
'process' => [
|
||||
'vid' => 'id',
|
||||
'name' => 'name',
|
||||
'weight' => 'weight',
|
||||
],
|
||||
'destination' => ['plugin' => 'entity:taxonomy_vocabulary'],
|
||||
];
|
||||
|
||||
$vocabulary_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
$vocabulary_id_map = $vocabulary_migration->getIdMap();
|
||||
|
||||
$this->assertTrue($vocabulary_migration->getDestinationPlugin()->supportsRollback());
|
||||
|
||||
// Import and validate vocabulary config entities were created.
|
||||
$vocabulary_executable = new MigrateExecutable($vocabulary_migration, $this);
|
||||
$vocabulary_executable->import();
|
||||
foreach ($vocabulary_data_rows as $row) {
|
||||
/** @var Vocabulary $vocabulary */
|
||||
$vocabulary = Vocabulary::load($row['id']);
|
||||
$this->assertTrue($vocabulary);
|
||||
$map_row = $vocabulary_id_map->getRowBySource(['id' => $row['id']]);
|
||||
$this->assertNotNull($map_row['destid1']);
|
||||
}
|
||||
|
||||
// We use taxonomy terms to demonstrate importing and rolling back content
|
||||
// entities.
|
||||
$term_data_rows = [
|
||||
['id' => '1', 'vocab' => '1', 'name' => 'music'],
|
||||
['id' => '2', 'vocab' => '2', 'name' => 'Bach'],
|
||||
['id' => '3', 'vocab' => '2', 'name' => 'Beethoven'],
|
||||
];
|
||||
$ids = ['id' => ['type' => 'integer']];
|
||||
$definition = [
|
||||
'id' => 'terms',
|
||||
'migration_tags' => ['Import and rollback test'],
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => $term_data_rows,
|
||||
'ids' => $ids,
|
||||
],
|
||||
'process' => [
|
||||
'tid' => 'id',
|
||||
'vid' => 'vocab',
|
||||
'name' => 'name',
|
||||
],
|
||||
'destination' => ['plugin' => 'entity:taxonomy_term'],
|
||||
'migration_dependencies' => ['required' => ['vocabularies']],
|
||||
];
|
||||
|
||||
$term_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
$term_id_map = $term_migration->getIdMap();
|
||||
|
||||
$this->assertTrue($term_migration->getDestinationPlugin()->supportsRollback());
|
||||
|
||||
// Pre-create a term, to make sure it isn't deleted on rollback.
|
||||
$preserved_term_ids[] = 1;
|
||||
$new_term = Term::create(['tid' => 1, 'vid' => 1, 'name' => 'music']);
|
||||
$new_term->save();
|
||||
|
||||
// Import and validate term entities were created.
|
||||
$term_executable = new MigrateExecutable($term_migration, $this);
|
||||
$term_executable->import();
|
||||
// Also explicitly mark one row to be preserved on rollback.
|
||||
$preserved_term_ids[] = 2;
|
||||
$map_row = $term_id_map->getRowBySource(['id' => 2]);
|
||||
$dummy_row = new Row(['id' => 2], $ids);
|
||||
$term_id_map->saveIdMapping($dummy_row, [$map_row['destid1']],
|
||||
$map_row['source_row_status'], MigrateIdMapInterface::ROLLBACK_PRESERVE);
|
||||
|
||||
foreach ($term_data_rows as $row) {
|
||||
/** @var Term $term */
|
||||
$term = Term::load($row['id']);
|
||||
$this->assertTrue($term);
|
||||
$map_row = $term_id_map->getRowBySource(['id' => $row['id']]);
|
||||
$this->assertNotNull($map_row['destid1']);
|
||||
}
|
||||
|
||||
// Rollback and verify the entities are gone.
|
||||
$term_executable->rollback();
|
||||
foreach ($term_data_rows as $row) {
|
||||
$term = Term::load($row['id']);
|
||||
if (in_array($row['id'], $preserved_term_ids)) {
|
||||
$this->assertNotNull($term);
|
||||
}
|
||||
else {
|
||||
$this->assertNull($term);
|
||||
}
|
||||
$map_row = $term_id_map->getRowBySource(['id' => $row['id']]);
|
||||
$this->assertFalse($map_row);
|
||||
}
|
||||
$vocabulary_executable->rollback();
|
||||
foreach ($vocabulary_data_rows as $row) {
|
||||
$term = Vocabulary::load($row['id']);
|
||||
$this->assertNull($term);
|
||||
$map_row = $vocabulary_id_map->getRowBySource(['id' => $row['id']]);
|
||||
$this->assertFalse($map_row);
|
||||
}
|
||||
|
||||
// Test that simple configuration is not rollbackable.
|
||||
$term_setting_rows = [
|
||||
['id' => 1, 'override_selector' => '0', 'terms_per_page_admin' => '10'],
|
||||
];
|
||||
$ids = ['id' => ['type' => 'integer']];
|
||||
$definition = [
|
||||
'id' => 'taxonomy_settings',
|
||||
'migration_tags' => ['Import and rollback test'],
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => $term_setting_rows,
|
||||
'ids' => $ids,
|
||||
],
|
||||
'process' => [
|
||||
'override_selector' => 'override_selector',
|
||||
'terms_per_page_admin' => 'terms_per_page_admin',
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'config',
|
||||
'config_name' => 'taxonomy.settings',
|
||||
],
|
||||
'migration_dependencies' => ['required' => ['vocabularies']],
|
||||
];
|
||||
|
||||
$settings_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
$this->assertFalse($settings_migration->getDestinationPlugin()->supportsRollback());
|
||||
}
|
||||
|
||||
}
|
67
core/modules/migrate/tests/src/Kernel/MigrateSkipRowTest.php
Normal file
67
core/modules/migrate/tests/src/Kernel/MigrateSkipRowTest.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Tests row skips triggered during hook_migrate_prepare_row().
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrateSkipRowTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['migrate', 'migrate_prepare_row_test'];
|
||||
|
||||
/**
|
||||
* Tests migration interruptions.
|
||||
*/
|
||||
public function testPrepareRowSkip() {
|
||||
// Run a simple little migration with two data rows which should be skipped
|
||||
// in different ways.
|
||||
$definition = [
|
||||
'migration_tags' => ['prepare_row test'],
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => [
|
||||
['id' => '1', 'data' => 'skip_and_record'],
|
||||
['id' => '2', 'data' => 'skip_and_dont_record'],
|
||||
],
|
||||
'ids' => [
|
||||
'id' => ['type' => 'string'],
|
||||
],
|
||||
],
|
||||
'process' => ['value' => 'data'],
|
||||
'destination' => [
|
||||
'plugin' => 'config',
|
||||
'config_name' => 'migrate_test.settings',
|
||||
],
|
||||
'load' => ['plugin' => 'null'],
|
||||
];
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$result = $executable->import();
|
||||
$this->assertEqual($result, MigrationInterface::RESULT_COMPLETED);
|
||||
|
||||
$id_map_plugin = $migration->getIdMap();
|
||||
// The first row is recorded in the map as ignored.
|
||||
$map_row = $id_map_plugin->getRowBySource(['id' => 1]);
|
||||
$this->assertEqual(MigrateIdMapInterface::STATUS_IGNORED, $map_row['source_row_status']);
|
||||
// The second row is not recorded in the map.
|
||||
$map_row = $id_map_plugin->getRowBySource(['id' => 2]);
|
||||
$this->assertFalse($map_row);
|
||||
|
||||
}
|
||||
|
||||
}
|
49
core/modules/migrate/tests/src/Kernel/MigrateStatusTest.php
Normal file
49
core/modules/migrate/tests/src/Kernel/MigrateStatusTest.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* Tests migration status tracking.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrateStatusTest extends MigrateTestBase {
|
||||
|
||||
/**
|
||||
* Tests different connection types.
|
||||
*/
|
||||
public function testStatus() {
|
||||
// Create a minimally valid migration.
|
||||
$definition = [
|
||||
'id' => 'migration_status_test',
|
||||
'migration_tags' => ['Testing'],
|
||||
'source' => ['plugin' => 'empty'],
|
||||
'destination' => [
|
||||
'plugin' => 'config',
|
||||
'config_name' => 'migrate_test.settings',
|
||||
],
|
||||
'process' => ['foo' => 'bar'],
|
||||
];
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
// Default status is idle.
|
||||
$status = $migration->getStatus();
|
||||
$this->assertIdentical($status, MigrationInterface::STATUS_IDLE);
|
||||
|
||||
// Test setting and retrieving all known status values.
|
||||
$status_list = array(
|
||||
MigrationInterface::STATUS_IDLE,
|
||||
MigrationInterface::STATUS_IMPORTING,
|
||||
MigrationInterface::STATUS_ROLLING_BACK,
|
||||
MigrationInterface::STATUS_STOPPING,
|
||||
MigrationInterface::STATUS_DISABLED,
|
||||
);
|
||||
foreach ($status_list as $status) {
|
||||
$migration->setStatus($status);
|
||||
$this->assertIdentical($migration->getStatus(), $status);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
237
core/modules/migrate/tests/src/Kernel/MigrateTestBase.php
Normal file
237
core/modules/migrate/tests/src/Kernel/MigrateTestBase.php
Normal file
|
@ -0,0 +1,237 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessageInterface;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Creates abstract base class for migration tests.
|
||||
*/
|
||||
abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageInterface {
|
||||
|
||||
/**
|
||||
* TRUE to collect messages instead of displaying them.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $collectMessages = FALSE;
|
||||
|
||||
/**
|
||||
* A two dimensional array of messages.
|
||||
*
|
||||
* The first key is the type of message, the second is just numeric. Values
|
||||
* are the messages.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $migrateMessages;
|
||||
|
||||
/**
|
||||
* The primary migration being tested.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* The source database connection.
|
||||
*
|
||||
* @var \Drupal\Core\Database\Connection
|
||||
*/
|
||||
protected $sourceDatabase;
|
||||
|
||||
public static $modules = array('migrate');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->createMigrationConnection();
|
||||
$this->sourceDatabase = Database::getConnection('default', 'migrate');
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the database connection to the prefixed one.
|
||||
*
|
||||
* @todo Remove when we don't use global. https://www.drupal.org/node/2552791
|
||||
*/
|
||||
private function createMigrationConnection() {
|
||||
// If the backup already exists, something went terribly wrong.
|
||||
// This case is possible, because database connection info is a static
|
||||
// global state construct on the Database class, which at least persists
|
||||
// for all test methods executed in one PHP process.
|
||||
if (Database::getConnectionInfo('simpletest_original_migrate')) {
|
||||
throw new \RuntimeException("Bad Database connection state: 'simpletest_original_migrate' connection key already exists. Broken test?");
|
||||
}
|
||||
|
||||
// Clone the current connection and replace the current prefix.
|
||||
$connection_info = Database::getConnectionInfo('migrate');
|
||||
if ($connection_info) {
|
||||
Database::renameConnection('migrate', 'simpletest_original_migrate');
|
||||
}
|
||||
$connection_info = Database::getConnectionInfo('default');
|
||||
foreach ($connection_info as $target => $value) {
|
||||
$prefix = is_array($value['prefix']) ? $value['prefix']['default'] : $value['prefix'];
|
||||
// Simpletest uses 7 character prefixes at most so this can't cause
|
||||
// collisions.
|
||||
$connection_info[$target]['prefix']['default'] = $prefix . '0';
|
||||
|
||||
// Add the original simpletest prefix so SQLite can attach its database.
|
||||
// @see \Drupal\Core\Database\Driver\sqlite\Connection::init()
|
||||
$connection_info[$target]['prefix'][$value['prefix']['default']] = $value['prefix']['default'];
|
||||
}
|
||||
Database::addConnectionInfo('migrate', 'default', $connection_info['default']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function tearDown() {
|
||||
$this->cleanupMigrateConnection();
|
||||
parent::tearDown();
|
||||
$this->databaseDumpFiles = [];
|
||||
$this->collectMessages = FALSE;
|
||||
unset($this->migration, $this->migrateMessages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up the test migrate connection.
|
||||
*
|
||||
* @todo Remove when we don't use global. https://www.drupal.org/node/2552791
|
||||
*/
|
||||
private function cleanupMigrateConnection() {
|
||||
Database::removeConnection('migrate');
|
||||
$original_connection_info = Database::getConnectionInfo('simpletest_original_migrate');
|
||||
if ($original_connection_info) {
|
||||
Database::renameConnection('simpletest_original_migrate', 'migrate');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare any dependent migrations.
|
||||
*
|
||||
* @param array $id_mappings
|
||||
* A list of ID mappings keyed by migration IDs. Each ID mapping is a list
|
||||
* of two arrays, the first are source IDs and the second are destination
|
||||
* IDs.
|
||||
*/
|
||||
protected function prepareMigrations(array $id_mappings) {
|
||||
$manager = $this->container->get('plugin.manager.migration');
|
||||
foreach ($id_mappings as $migration_id => $data) {
|
||||
foreach ($manager->createInstances($migration_id) as $migration) {
|
||||
$id_map = $migration->getIdMap();
|
||||
$id_map->setMessage($this);
|
||||
$source_ids = $migration->getSourcePlugin()->getIds();
|
||||
foreach ($data as $id_mapping) {
|
||||
$row = new Row(array_combine(array_keys($source_ids), $id_mapping[0]), $source_ids);
|
||||
$id_map->saveIdMapping($row, $id_mapping[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a single migration.
|
||||
*
|
||||
* @param string|\Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration to execute, or its ID.
|
||||
*/
|
||||
protected function executeMigration($migration) {
|
||||
if (is_string($migration)) {
|
||||
$this->migration = $this->getMigration($migration);
|
||||
}
|
||||
else {
|
||||
$this->migration = $migration;
|
||||
}
|
||||
if ($this instanceof MigrateDumpAlterInterface) {
|
||||
static::migrateDumpAlter($this);
|
||||
}
|
||||
(new MigrateExecutable($this->migration, $this))->import();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a set of migrations in dependency order.
|
||||
*
|
||||
* @param string[] $ids
|
||||
* Array of migration IDs, in any order.
|
||||
*/
|
||||
protected function executeMigrations(array $ids) {
|
||||
$manager = $this->container->get('plugin.manager.migration');
|
||||
array_walk($ids, function ($id) use ($manager) {
|
||||
// This is possibly a base plugin ID and we want to run all derivatives.
|
||||
$instances = $manager->createInstances($id);
|
||||
array_walk($instances, [$this, 'executeMigration']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function display($message, $type = 'status') {
|
||||
if ($this->collectMessages) {
|
||||
$this->migrateMessages[$type][] = $message;
|
||||
}
|
||||
else {
|
||||
$this->assert($type == 'status', $message, 'migrate');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start collecting messages and erase previous messages.
|
||||
*/
|
||||
public function startCollectingMessages() {
|
||||
$this->collectMessages = TRUE;
|
||||
$this->migrateMessages = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop collecting messages.
|
||||
*/
|
||||
public function stopCollectingMessages() {
|
||||
$this->collectMessages = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Records a failure in the map table of a specific migration.
|
||||
*
|
||||
* This is done in order to test scenarios which require a failed row.
|
||||
*
|
||||
* @param string|\Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration entity, or its ID.
|
||||
* @param array $row
|
||||
* The raw source row which "failed".
|
||||
* @param int $status
|
||||
* (optional) The failure status. Should be one of the
|
||||
* MigrateIdMapInterface::STATUS_* constants. Defaults to
|
||||
* MigrateIdMapInterface::STATUS_FAILED.
|
||||
*/
|
||||
protected function mockFailure($migration, array $row, $status = MigrateIdMapInterface::STATUS_FAILED) {
|
||||
if (is_string($migration)) {
|
||||
$migration = $this->getMigration($migration);
|
||||
}
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$destination = array_map(function() { return NULL; }, $migration->getDestinationPlugin()->getIds());
|
||||
$row = new Row($row, $migration->getSourcePlugin()->getIds());
|
||||
$migration->getIdMap()->saveIdMapping($row, $destination, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the migration plugin.
|
||||
*
|
||||
* @param $plugin_id
|
||||
* The plugin ID of the migration to get.
|
||||
*
|
||||
* @return \Drupal\migrate\Plugin\Migration
|
||||
* The migration plugin.
|
||||
*/
|
||||
protected function getMigration($plugin_id) {
|
||||
return $this->container->get('plugin.manager.migration')->createInstance($plugin_id);
|
||||
}
|
||||
|
||||
}
|
45
core/modules/migrate/tests/src/Kernel/MigrationTest.php
Normal file
45
core/modules/migrate/tests/src/Kernel/MigrationTest.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the migration plugin.
|
||||
*
|
||||
* @group migrate
|
||||
*
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\Migration
|
||||
*/
|
||||
class MigrationTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Enable field because we are using one of its source plugins.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['migrate', 'field'];
|
||||
|
||||
/**
|
||||
* Tests Migration::set().
|
||||
*
|
||||
* @covers ::set
|
||||
*/
|
||||
public function testSetInvalidation() {
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration([
|
||||
'source' => ['plugin' => 'empty'],
|
||||
'destination' => ['plugin' => 'entity:entity_view_mode'],
|
||||
]);
|
||||
$this->assertEqual('empty', $migration->getSourcePlugin()->getPluginId());
|
||||
$this->assertEqual('entity:entity_view_mode', $migration->getDestinationPlugin()->getPluginId());
|
||||
|
||||
// Test the source plugin is invalidated.
|
||||
$migration->set('source', ['plugin' => 'd6_field']);
|
||||
$this->assertEqual('d6_field', $migration->getSourcePlugin()->getPluginId());
|
||||
|
||||
// Test the destination plugin is invalidated.
|
||||
$migration->set('destination', ['plugin' => 'null']);
|
||||
$this->assertEqual('null', $migration->getDestinationPlugin()->getPluginId());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel\Plugin;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the migration plugin.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\Migration
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrationTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate'];
|
||||
|
||||
/**
|
||||
* Tests Migration::getProcessPlugins()
|
||||
*
|
||||
* @covers ::getProcessPlugins
|
||||
*/
|
||||
public function testGetProcessPlugins() {
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration([]);
|
||||
$this->assertEquals([], $migration->getProcessPlugins([]));
|
||||
}
|
||||
|
||||
}
|
138
core/modules/migrate/tests/src/Kernel/SqlBaseTest.php
Normal file
138
core/modules/migrate/tests/src/Kernel/SqlBaseTest.php
Normal file
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Kernel\SqlBaseTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\source\TestSqlBase;
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
/**
|
||||
* Tests the functionality of SqlBase.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class SqlBaseTest extends MigrateTestBase {
|
||||
|
||||
/**
|
||||
* Tests different connection types.
|
||||
*/
|
||||
public function testConnectionTypes() {
|
||||
$sql_base = new TestSqlBase();
|
||||
|
||||
// Check the default values.
|
||||
$sql_base->setConfiguration([]);
|
||||
$this->assertIdentical($sql_base->getDatabase()->getTarget(), 'default');
|
||||
$this->assertIdentical($sql_base->getDatabase()->getKey(), 'migrate');
|
||||
|
||||
$target = 'test_db_target';
|
||||
$key = 'test_migrate_connection';
|
||||
$config = array('target' => $target, 'key' => $key);
|
||||
$sql_base->setConfiguration($config);
|
||||
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);
|
||||
|
||||
// Now test we can have SqlBase create the connection from an info array.
|
||||
$sql_base = new TestSqlBase();
|
||||
|
||||
$target = 'test_db_target2';
|
||||
$key = 'test_migrate_connection2';
|
||||
$database = Database::getConnectionInfo('default')['default'];
|
||||
$config = array('target' => $target, 'key' => $key, 'database' => $database);
|
||||
$sql_base->setConfiguration($config);
|
||||
|
||||
// Call getDatabase() to get the connection defined.
|
||||
$sql_base->getDatabase();
|
||||
|
||||
// Validate the connection has been created with the right values.
|
||||
$this->assertIdentical(Database::getConnectionInfo($key)[$target], $database);
|
||||
|
||||
// Now, test this all works when using state to store db info.
|
||||
$target = 'test_state_db_target';
|
||||
$key = 'test_state_migrate_connection';
|
||||
$config = ['target' => $target, 'key' => $key];
|
||||
$database_state_key = 'migrate_sql_base_test';
|
||||
\Drupal::state()->set($database_state_key, $config);
|
||||
$sql_base->setConfiguration(['database_state_key' => $database_state_key]);
|
||||
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);
|
||||
|
||||
// Now test we can have SqlBase create the connection from an info array.
|
||||
$sql_base = new TestSqlBase();
|
||||
|
||||
$target = 'test_state_db_target2';
|
||||
$key = 'test_state_migrate_connection2';
|
||||
$database = Database::getConnectionInfo('default')['default'];
|
||||
$config = ['target' => $target, 'key' => $key, 'database' => $database];
|
||||
$database_state_key = 'migrate_sql_base_test2';
|
||||
\Drupal::state()->set($database_state_key, $config);
|
||||
$sql_base->setConfiguration(['database_state_key' => $database_state_key]);
|
||||
|
||||
// Call getDatabase() to get the connection defined.
|
||||
$sql_base->getDatabase();
|
||||
|
||||
// Validate the connection has been created with the right values.
|
||||
$this->assertIdentical(Database::getConnectionInfo($key)[$target], $database);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Drupal\migrate\Plugin\migrate\source;
|
||||
|
||||
/**
|
||||
* A dummy source to help with testing SqlBase.
|
||||
*
|
||||
* @package Drupal\migrate\Plugin\migrate\source
|
||||
*/
|
||||
class TestSqlBase extends SqlBase {
|
||||
|
||||
/**
|
||||
* Overrides the constructor so we can create one easily.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->state = \Drupal::state();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the database without caching it.
|
||||
*/
|
||||
public function getDatabase() {
|
||||
$this->database = NULL;
|
||||
return parent::getDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows us to set the configuration from a test.
|
||||
*
|
||||
* @param array $config
|
||||
* The config array.
|
||||
*/
|
||||
public function setConfiguration($config) {
|
||||
$this->configuration = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {}
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\Entity\MigrationTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\Entity;
|
||||
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* Tests the migrate entity.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\migrate\Entity\Migration
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrationTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests Migration::getProcessPlugins()
|
||||
*
|
||||
* @covers ::getProcessPlugins
|
||||
*/
|
||||
public function testGetProcessPlugins() {
|
||||
$migration = new Migration([], 'migration');
|
||||
$this->assertEquals([], $migration->getProcessPlugins([]));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\Exception\RequirementsExceptionTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\Exception;
|
||||
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\MigrateExecutableMemoryExceededTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
/**
|
||||
|
@ -17,7 +12,7 @@ class MigrateExecutableMemoryExceededTest extends MigrateTestCase {
|
|||
/**
|
||||
* The mocked migration entity.
|
||||
*
|
||||
* @var \Drupal\migrate\Entity\MigrationInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\MigrateExecutableTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Row;
|
||||
|
@ -22,7 +17,7 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
/**
|
||||
* The mocked migration entity.
|
||||
*
|
||||
* @var \Drupal\migrate\Entity\MigrationInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
/**
|
||||
* The migration entity.
|
||||
*
|
||||
* @var \Drupal\migrate\Entity\Migration
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
|
@ -371,7 +371,7 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
/**
|
||||
* Gets a mock executable for the test.
|
||||
*
|
||||
* @param \Drupal\migrate\Entity\MigrationInterface $migration
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration entity.
|
||||
*
|
||||
* @return \Drupal\migrate\MigrateExecutable
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\MigrateSqlIdMapEnsureTablesTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
use Drupal\Core\Database\Driver\sqlite\Connection;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Row;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\MigrateTestCase.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
use Drupal\Core\Database\Driver\sqlite\Connection;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
|
@ -34,18 +29,18 @@ abstract class MigrateTestCase extends UnitTestCase {
|
|||
/**
|
||||
* Local store for mocking setStatus()/getStatus().
|
||||
*
|
||||
* @var \Drupal\migrate\Entity\MigrationInterface::STATUS_*
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface::STATUS_*
|
||||
*/
|
||||
protected $migrationStatus = MigrationInterface::STATUS_IDLE;
|
||||
|
||||
/**
|
||||
* Retrieves a mocked migration.
|
||||
*
|
||||
* @return \Drupal\migrate\Entity\MigrationInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
* @return \Drupal\migrate\Plugin\MigrationInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
* The mocked migration.
|
||||
*/
|
||||
protected function getMigration() {
|
||||
$this->migrationConfiguration += ['migrationClass' => 'Drupal\migrate\Entity\Migration'];
|
||||
$this->migrationConfiguration += ['migrationClass' => 'Drupal\migrate\Plugin\Migration'];
|
||||
$this->idMap = $this->getMock('Drupal\migrate\Plugin\MigrateIdMapInterface');
|
||||
|
||||
$this->idMap
|
||||
|
@ -83,9 +78,9 @@ abstract class MigrateTestCase extends UnitTestCase {
|
|||
|
||||
$configuration = &$this->migrationConfiguration;
|
||||
|
||||
$migration->method('get')
|
||||
->willReturnCallback(function ($argument) use (&$configuration) {
|
||||
return isset($configuration[$argument]) ? $configuration[$argument] : '';
|
||||
$migration->method('getHighWaterProperty')
|
||||
->willReturnCallback(function () use ($configuration) {
|
||||
return isset($configuration['highWaterProperty']) ? $configuration['highWaterProperty'] : '';
|
||||
});
|
||||
|
||||
$migration->method('set')
|
||||
|
|
|
@ -7,16 +7,18 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\Migration;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\migrate\Plugin\MigrateDestinationInterface;
|
||||
use Drupal\migrate\Plugin\MigrateSourceInterface;
|
||||
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
|
||||
use Drupal\migrate\Plugin\RequirementsInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Entity\Migration
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\Migration
|
||||
*
|
||||
* @group Migration
|
||||
*/
|
||||
class MigrationTest extends UnitTestCase {
|
||||
|
@ -84,16 +86,16 @@ class MigrationTest extends UnitTestCase {
|
|||
$migration->setSourcePlugin($source_plugin);
|
||||
$migration->setDestinationPlugin($destination_plugin);
|
||||
|
||||
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$migration->setEntityManager($entity_manager);
|
||||
$plugin_manager = $this->getMock('Drupal\migrate\Plugin\MigrationPluginManagerInterface');
|
||||
$migration->setMigrationPluginManager($plugin_manager);
|
||||
|
||||
// We setup the requirements that test_a doesn't exist and test_c is not
|
||||
// completed yet.
|
||||
$migration->setRequirements(['test_a', 'test_b', 'test_c', 'test_d']);
|
||||
|
||||
$migration_b = $this->getMock('Drupal\migrate\Entity\MigrationInterface');
|
||||
$migration_c = $this->getMock('Drupal\migrate\Entity\MigrationInterface');
|
||||
$migration_d = $this->getMock('Drupal\migrate\Entity\MigrationInterface');
|
||||
$migration_b = $this->getMock(MigrationInterface::class);
|
||||
$migration_c = $this->getMock(MigrationInterface::class);
|
||||
$migration_d = $this->getMock(MigrationInterface::class);
|
||||
|
||||
$migration_b->expects($this->once())
|
||||
->method('allRowsProcessed')
|
||||
|
@ -105,15 +107,10 @@ class MigrationTest extends UnitTestCase {
|
|||
->method('allRowsProcessed')
|
||||
->willReturn(TRUE);
|
||||
|
||||
$migration_storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
|
||||
$migration_storage->expects($this->once())
|
||||
->method('loadMultiple')
|
||||
$plugin_manager->expects($this->once())
|
||||
->method('createInstances')
|
||||
->with(['test_a', 'test_b', 'test_c', 'test_d'])
|
||||
->willReturn(['test_b' => $migration_b, 'test_c' => $migration_c, 'test_d' => $migration_d]);
|
||||
$entity_manager->expects($this->once())
|
||||
->method('getStorage')
|
||||
->with('migration')
|
||||
->willReturn($migration_storage);
|
||||
|
||||
$migration->checkRequirements();
|
||||
}
|
||||
|
@ -162,13 +159,13 @@ class TestMigration extends Migration {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the entity manager service.
|
||||
* Sets the plugin manager service.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager service.
|
||||
* @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $plugin_manager
|
||||
* The plugin manager service.
|
||||
*/
|
||||
public function setEntityManager(EntityManagerInterface $entity_manager) {
|
||||
$this->entityManager = $entity_manager;
|
||||
public function setMigrationPluginManager(MigrationPluginManagerInterface $plugin_manager) {
|
||||
$this->migrationPluginManager = $plugin_manager;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use Drupal\Core\Entity\ContentEntityInterface;
|
|||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Row;
|
||||
|
@ -26,7 +26,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
class EntityContentBaseTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Entity\MigrationInterface
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\RowTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\source\SqlBase;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
|
@ -61,7 +62,7 @@ class SqlBaseTest extends UnitTestCase {
|
|||
->willReturn($idmap_connection);
|
||||
|
||||
// Setup a migration entity.
|
||||
$migration = $this->getMock('Drupal\migrate\Entity\MigrationInterface');
|
||||
$migration = $this->getMock(MigrationInterface::class);
|
||||
$migration->expects($with_id_map ? $this->once() : $this->never())
|
||||
->method('getIdMap')
|
||||
->willReturn($id_map_is_sql ? $sql : NULL);
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\TestMigrateExecutable.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
use Drupal\Core\StringTranslation\TranslationInterface;
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\TestSqlIdMap.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\migrate\id_map\Sql;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
@ -29,7 +24,7 @@ class TestSqlIdMap extends Sql implements \Iterator {
|
|||
* The plugin ID for the migration process to do.
|
||||
* @param mixed $plugin_definition
|
||||
* The configuration for the plugin.
|
||||
* @param \Drupal\migrate\Entity\MigrationInterface $migration
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration to do.
|
||||
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
|
||||
* The event dispatcher service.
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\destination\ConfigTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\destination;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\Config;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
|
@ -23,7 +19,7 @@ class ConfigTest extends UnitTestCase {
|
|||
$source = array(
|
||||
'test' => 'x',
|
||||
);
|
||||
$migration = $this->getMockBuilder('Drupal\migrate\Entity\Migration')
|
||||
$migration = $this->getMockBuilder('Drupal\migrate\Plugin\Migration')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$config = $this->getMockBuilder('Drupal\Core\Config\Config')
|
||||
|
@ -73,7 +69,7 @@ class ConfigTest extends UnitTestCase {
|
|||
$source = array(
|
||||
'langcode' => 'mi',
|
||||
);
|
||||
$migration = $this->getMockBuilder('Drupal\migrate\Entity\Migration')
|
||||
$migration = $this->getMockBuilder(MigrationInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$config = $this->getMockBuilder('Drupal\Core\Config\Config')
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Drupal\Tests\migrate\Unit\destination;
|
|||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityRevision as RealEntityRevision;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
@ -22,7 +23,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
class EntityRevisionTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Entity\MigrationInterface
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
|
@ -45,7 +46,7 @@ class EntityRevisionTest extends UnitTestCase {
|
|||
parent::setUp();
|
||||
|
||||
// Setup mocks to be used when creating a revision destination.
|
||||
$this->migration = $this->prophesize('\Drupal\migrate\Entity\MigrationInterface');
|
||||
$this->migration = $this->prophesize(MigrationInterface::class);
|
||||
$this->storage = $this->prophesize('\Drupal\Core\Entity\EntityStorageInterface');
|
||||
$this->entityManager = $this->prophesize('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->fieldTypeManager = $this->prophesize('\Drupal\Core\Field\FieldTypePluginManagerInterface');
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\process\DedupeEntityTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\process\ExplodeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\process\Explode;
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\process\ExtractTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\process\FlattenTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
use Drupal\migrate\Plugin\migrate\process\Flatten;
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\process\IteratorTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\process\MachineNameTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateTestCase;
|
||||
|
|
|
@ -1,20 +1,14 @@
|
|||
<?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\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 Drupal\migrate\Plugin\MigrationPluginManagerInterface;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
|
@ -27,26 +21,28 @@ class MigrationTest extends MigrateProcessTestCase {
|
|||
* @covers ::transform
|
||||
*/
|
||||
public function testTransformWithStubSkipping() {
|
||||
$migration_entity = $this->prophesize(MigrationInterface::class);
|
||||
$migration_storage = $this->prophesize(EntityStorageInterface::class);
|
||||
$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(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);
|
||||
|
||||
// Ensure the migration plugin manager returns our migration.
|
||||
$migration_plugin_manager->createInstances(Argument::exact(['destination_migration']))
|
||||
->willReturn(['destination_migration' => $destination_migration->reveal()]);
|
||||
|
||||
$configuration = [
|
||||
'no_stub' => TRUE,
|
||||
'migration' => 'destination_migration',
|
||||
];
|
||||
|
||||
$migration_entity->id()->willReturn('actual_migration');
|
||||
$migration_plugin->id()->willReturn('actual_migration');
|
||||
$destination_migration->getDestinationPlugin(TRUE)->shouldNotBeCalled();
|
||||
|
||||
$migration = new Migration($configuration, '', [], $migration_entity->reveal(), $migration_storage->reveal(), $process_plugin_manager->reveal());
|
||||
$migration = new Migration($configuration, '', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
|
||||
$result = $migration->transform(1, $this->migrateExecutable, $this->row, '');
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
@ -55,27 +51,28 @@ class MigrationTest extends MigrateProcessTestCase {
|
|||
* @covers ::transform
|
||||
*/
|
||||
public function testTransformWithStubbing() {
|
||||
$migration_entity = $this->prophesize(MigrationInterface::class);
|
||||
$migration_storage = $this->prophesize(EntityStorageInterface::class);
|
||||
$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(MigrationInterface::class);
|
||||
$destination_migration = $this->prophesize('Drupal\migrate\Plugin\Migration');
|
||||
$destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
|
||||
$migration_storage->loadMultiple(['destination_migration'])
|
||||
$migration_plugin_manager->createInstances(['destination_migration'])
|
||||
->willReturn(['destination_migration' => $destination_migration->reveal()]);
|
||||
$destination_id_map->lookupDestinationId([1])->willReturn(NULL);
|
||||
$destination_id_map->saveIdMapping(Argument::any(), Argument::any(), MigrateIdMapInterface::STATUS_NEEDS_UPDATE)->willReturn(NULL);
|
||||
|
||||
$configuration = [
|
||||
'no_stub' => FALSE,
|
||||
'migration' => 'destination_migration',
|
||||
];
|
||||
|
||||
$migration_entity->id()->willReturn('actual_migration');
|
||||
$migration_plugin->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([]);
|
||||
$destination_migration->getProcess()->willReturn([]);
|
||||
$destination_migration->getSourceConfiguration()->willReturn([]);
|
||||
|
||||
$source_plugin = $this->prophesize(MigrateSourceInterface::class);
|
||||
$source_plugin->getIds()->willReturn(['nid']);
|
||||
|
@ -84,7 +81,7 @@ class MigrationTest extends MigrateProcessTestCase {
|
|||
$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());
|
||||
$migration = new Migration($configuration, '', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
|
||||
$result = $migration->transform(1, $this->migrateExecutable, $this->row, '');
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\process\SkipOnEmptyTest.
|
||||
*/
|
||||
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
use Drupal\migrate\Plugin\migrate\process\SkipOnEmpty;
|
||||
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\process\StaticMapTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
|
|
Reference in a new issue