View source
<?php
namespace Drupal\migrate\Tests;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\Event\MigratePostRowSaveEvent;
use Drupal\migrate\MigrateMessage;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Event\MigrateEvents;
use Drupal\migrate\MigrateExecutable;
use Drupal\simpletest\KernelTestBase;
class MigrateInterruptionTest extends KernelTestBase {
public static $modules = [
'migrate',
'migrate_events_test',
];
public function setUp() {
parent::setUp();
\Drupal::service('event_dispatcher')
->addListener(MigrateEvents::POST_ROW_SAVE, array(
$this,
'postRowSaveEventRecorder',
));
}
public function testMigrateEvents() {
$config = [
'id' => 'sample_data',
'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 = Migration::create($config);
$executable = new MigrateExecutable($migration, new MigrateMessage());
$result = $executable
->import();
$this
->assertEqual($result, MigrationInterface::RESULT_INCOMPLETE);
$this
->assertEqual($migration
->getStatus(), MigrationInterface::STATUS_IDLE);
}
public function postRowSaveEventRecorder(MigratePostRowSaveEvent $event, $name) {
$event
->getMigration()
->interruptMigration(MigrationInterface::RESULT_INCOMPLETE);
}
}