Chris@0: ['prepare_row test'], Chris@0: 'source' => [ Chris@0: 'plugin' => 'embedded_data', Chris@0: 'data_rows' => [ Chris@0: ['id' => '1', 'data' => 'skip_and_record'], Chris@0: ['id' => '2', 'data' => 'skip_and_dont_record'], Chris@0: ], Chris@0: 'ids' => [ Chris@0: 'id' => ['type' => 'string'], Chris@0: ], Chris@0: ], Chris@0: 'process' => ['value' => 'data'], Chris@0: 'destination' => [ Chris@0: 'plugin' => 'config', Chris@0: 'config_name' => 'migrate_test.settings', Chris@0: ], Chris@0: 'load' => ['plugin' => 'null'], Chris@0: ]; Chris@0: Chris@0: $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition); Chris@0: Chris@14: $executable = new MigrateExecutable($migration); Chris@0: $result = $executable->import(); Chris@0: $this->assertEqual($result, MigrationInterface::RESULT_COMPLETED); Chris@0: Chris@0: /** @var \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map_plugin */ Chris@0: $id_map_plugin = $migration->getIdMap(); Chris@0: // The first row is recorded in the map as ignored. Chris@0: $map_row = $id_map_plugin->getRowBySource(['id' => 1]); Chris@0: $this->assertEqual(MigrateIdMapInterface::STATUS_IGNORED, $map_row['source_row_status']); Chris@0: // Check that no message has been logged for the first exception. Chris@0: $messages = $id_map_plugin->getMessageIterator(['id' => 1])->fetchAll(); Chris@0: $this->assertEmpty($messages); Chris@0: Chris@0: // The second row is not recorded in the map. Chris@0: $map_row = $id_map_plugin->getRowBySource(['id' => 2]); Chris@0: $this->assertFalse($map_row); Chris@0: // Check that the correct message has been logged for the second exception. Chris@0: $messages = $id_map_plugin->getMessageIterator(['id' => 2])->fetchAll(); Chris@0: $this->assertCount(1, $messages); Chris@0: $message = reset($messages); Chris@0: $this->assertEquals('skip_and_dont_record message', $message->message); Chris@0: $this->assertEquals(MigrationInterface::MESSAGE_INFORMATIONAL, $message->level); Chris@0: Chris@0: // Insert a custom processor in the process flow. Chris@0: $definition['process']['value'] = [ Chris@0: 'source' => 'data', Chris@0: 'plugin' => 'test_skip_row_process', Chris@0: ]; Chris@0: // Change data to avoid triggering again hook_migrate_prepare_row(). Chris@0: $definition['source']['data_rows'] = [ Chris@0: ['id' => '1', 'data' => 'skip_and_record (use plugin)'], Chris@0: ['id' => '2', 'data' => 'skip_and_dont_record (use plugin)'], Chris@0: ]; Chris@0: $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition); Chris@0: Chris@14: $executable = new MigrateExecutable($migration); Chris@0: $result = $executable->import(); Chris@0: $this->assertEquals($result, MigrationInterface::RESULT_COMPLETED); Chris@0: Chris@0: $id_map_plugin = $migration->getIdMap(); Chris@0: Chris@0: // The first row is recorded in the map as ignored. Chris@0: $map_row = $id_map_plugin->getRowBySource(['id' => 1]); Chris@0: $this->assertEquals(MigrateIdMapInterface::STATUS_IGNORED, $map_row['source_row_status']); Chris@0: // The second row is not recorded in the map. Chris@0: $map_row = $id_map_plugin->getRowBySource(['id' => 2]); Chris@0: $this->assertFalse($map_row); Chris@0: } Chris@0: Chris@0: }