3 namespace Drupal\Tests\migrate\Kernel;
5 use Drupal\migrate\Event\MigratePostRowSaveEvent;
6 use Drupal\migrate\Plugin\MigrationInterface;
7 use Drupal\migrate\Event\MigrateEvents;
8 use Drupal\migrate\MigrateExecutable;
9 use Drupal\KernelTests\KernelTestBase;
12 * Tests interruptions triggered during migrations.
16 class MigrateInterruptionTest extends KernelTestBase {
23 public static $modules = ['migrate', 'migrate_events_test'];
28 protected function setUp() {
30 \Drupal::service('event_dispatcher')->addListener(MigrateEvents::POST_ROW_SAVE,
31 [$this, 'postRowSaveEventRecorder']);
35 * Tests migration interruptions.
37 public function testMigrateEvents() {
38 // Run a simple little migration, which should trigger one of each event
39 // other than map_delete.
41 'migration_tags' => ['Interruption test'],
43 'plugin' => 'embedded_data',
45 ['data' => 'dummy value'],
46 ['data' => 'dummy value2'],
49 'data' => ['type' => 'string'],
52 'process' => ['value' => 'data'],
53 'destination' => ['plugin' => 'dummy'],
56 $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
58 $executable = new MigrateExecutable($migration);
59 // When the import runs, the first row imported will trigger an
61 $result = $executable->import();
63 $this->assertEqual($result, MigrationInterface::RESULT_INCOMPLETE);
65 // The status should have been reset to IDLE.
66 $this->assertEqual($migration->getStatus(), MigrationInterface::STATUS_IDLE);
70 * Reacts to post-row-save event.
72 * @param \Drupal\Migrate\Event\MigratePostRowSaveEvent $event
73 * The migration event.
77 public function postRowSaveEventRecorder(MigratePostRowSaveEvent $event, $name) {
78 $event->getMigration()->interruptMigration(MigrationInterface::RESULT_INCOMPLETE);