3 namespace Drupal\Tests\migrate\Kernel\process;
5 use Drupal\KernelTests\KernelTestBase;
6 use Drupal\migrate\MigrateExecutable;
7 use Drupal\migrate\MigrateMessage;
8 use Drupal\migrate\Plugin\MigrationInterface;
11 * Tests the extract process plugin.
15 class ExtractTest extends KernelTestBase {
20 public static $modules = ['migrate'];
23 * Returns test migration definition.
27 public function getDefinition() {
30 'plugin' => 'embedded_data',
33 'id' => ['type' => 'string'],
38 'plugin' => 'extract',
40 'source' => 'simple_array',
43 'plugin' => 'extract',
45 'source' => 'complex_array',
50 'config_name' => 'migrate_test.settings',
56 * Tests multiple value handling.
58 * @dataProvider multipleValueProviderSource
60 * @param array $source_data
61 * @param array $expected_data
63 public function testMultipleValueExplode(array $source_data, array $expected_data) {
64 $definition = $this->getDefinition();
65 $definition['source']['data_rows'] = [$source_data];
67 $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
69 $executable = new MigrateExecutable($migration, new MigrateMessage());
70 $result = $executable->import();
72 // Migration needs to succeed before further assertions are made.
73 $this->assertSame(MigrationInterface::RESULT_COMPLETED, $result);
75 // Compare with expected data.
76 $this->assertEquals($expected_data, \Drupal::config('migrate_test.settings')->get());
80 * Provides multiple source data for "extract" process plugin test.
82 public function multipleValueProviderSource() {
87 'simple_array' => ['alpha', 'beta'],
88 'complex_array' => [['alpha', 'beta'], ['psi', 'omega']],
92 'second' => ['psi', 'omega'],
98 'simple_array' => ['one'],
99 'complex_array' => [0, 1],