3 namespace Drupal\Tests\migrate\Kernel;
5 use Drupal\migrate\Event\MigratePostRowSaveEvent;
6 use Drupal\migrate\MigrateMessage;
7 use Drupal\migrate\Plugin\MigrationInterface;
8 use Drupal\migrate\Event\MigrateEvents;
9 use Drupal\migrate\MigrateExecutable;
10 use Drupal\KernelTests\KernelTestBase;
13 * Tests interruptions triggered during migrations.
17 class MigrateInterruptionTest extends KernelTestBase {
24 public static $modules = ['migrate', 'migrate_events_test'];
29 protected function setUp() {
31 \Drupal::service('event_dispatcher')->addListener(MigrateEvents::POST_ROW_SAVE,
32 [$this, 'postRowSaveEventRecorder']);
36 * Tests migration interruptions.
38 public function testMigrateEvents() {
39 // Run a simple little migration, which should trigger one of each event
40 // other than map_delete.
42 'migration_tags' => ['Interruption test'],
44 'plugin' => 'embedded_data',
46 ['data' => 'dummy value'],
47 ['data' => 'dummy value2'],
50 'data' => ['type' => 'string'],
53 'process' => ['value' => 'data'],
54 'destination' => ['plugin' => 'dummy'],
57 $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
59 $executable = new MigrateExecutable($migration, new MigrateMessage());
60 // When the import runs, the first row imported will trigger an
62 $result = $executable->import();
64 $this->assertEqual($result, MigrationInterface::RESULT_INCOMPLETE);
66 // The status should have been reset to IDLE.
67 $this->assertEqual($migration->getStatus(), MigrationInterface::STATUS_IDLE);
71 * Reacts to post-row-save event.
73 * @param \Drupal\Migrate\Event\MigratePostRowSaveEvent $event
74 * The migration event.
78 public function postRowSaveEventRecorder(MigratePostRowSaveEvent $event, $name) {
79 $event->getMigration()->interruptMigration(MigrationInterface::RESULT_INCOMPLETE);