3 namespace Drupal\Tests\migrate\Kernel;
5 use Drupal\KernelTests\KernelTestBase;
8 * Tests the EmbeddedDataSource plugin.
12 class MigrateEmbeddedDataTest extends KernelTestBase {
19 public static $modules = ['migrate'];
22 * Tests the embedded_data source plugin.
24 public function testEmbeddedData() {
26 ['key' => '1', 'field1' => 'f1value1', 'field2' => 'f2value1'],
27 ['key' => '2', 'field1' => 'f1value2', 'field2' => 'f2value2'],
29 $ids = ['key' => ['type' => 'integer']];
31 'migration_tags' => ['Embedded data test'],
33 'plugin' => 'embedded_data',
34 'data_rows' => $data_rows,
38 'destination' => ['plugin' => 'null'],
41 $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
42 $source = $migration->getSourcePlugin();
44 // Validate the plugin returns the source data that was provided.
46 /** @var \Drupal\migrate\Row $row */
47 foreach ($source as $row) {
48 // The plugin should not mark any rows as stubs. We need to use
49 // assertSame() here because assertFalse() will pass falsy values (e.g.,
51 $this->assertSame(FALSE, $row->isStub());
53 $data_row = $row->getSource();
54 // The "data" row returned by getSource() also includes all source
55 // configuration - we remove it so we see only the data itself.
56 unset($data_row['plugin']);
57 unset($data_row['data_rows']);
58 unset($data_row['ids']);
59 $results[] = $data_row;
61 $this->assertIdentical($results, $data_rows);
63 // Validate the public APIs.
64 $this->assertIdentical($source->count(), count($data_rows));
65 $this->assertIdentical($source->getIds(), $ids);
71 $this->assertIdentical($source->fields(), $expected_fields);