Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\migrate\Kernel;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\KernelTests\KernelTestBase;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Tests the EmbeddedDataSource plugin.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @group migrate
|
Chris@0
|
11 */
|
Chris@0
|
12 class MigrateEmbeddedDataTest extends KernelTestBase {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Modules to enable.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @var array
|
Chris@0
|
18 */
|
Chris@0
|
19 public static $modules = ['migrate'];
|
Chris@0
|
20
|
Chris@0
|
21 /**
|
Chris@0
|
22 * Tests the embedded_data source plugin.
|
Chris@0
|
23 */
|
Chris@0
|
24 public function testEmbeddedData() {
|
Chris@0
|
25 $data_rows = [
|
Chris@0
|
26 ['key' => '1', 'field1' => 'f1value1', 'field2' => 'f2value1'],
|
Chris@0
|
27 ['key' => '2', 'field1' => 'f1value2', 'field2' => 'f2value2'],
|
Chris@0
|
28 ];
|
Chris@0
|
29 $ids = ['key' => ['type' => 'integer']];
|
Chris@0
|
30 $definition = [
|
Chris@0
|
31 'migration_tags' => ['Embedded data test'],
|
Chris@0
|
32 'source' => [
|
Chris@0
|
33 'plugin' => 'embedded_data',
|
Chris@0
|
34 'data_rows' => $data_rows,
|
Chris@0
|
35 'ids' => $ids,
|
Chris@0
|
36 ],
|
Chris@0
|
37 'process' => [],
|
Chris@0
|
38 'destination' => ['plugin' => 'null'],
|
Chris@0
|
39 ];
|
Chris@0
|
40
|
Chris@0
|
41 $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
Chris@0
|
42 $source = $migration->getSourcePlugin();
|
Chris@0
|
43
|
Chris@0
|
44 // Validate the plugin returns the source data that was provided.
|
Chris@0
|
45 $results = [];
|
Chris@0
|
46 /** @var \Drupal\migrate\Row $row */
|
Chris@0
|
47 foreach ($source as $row) {
|
Chris@17
|
48 // The plugin should not mark any rows as stubs. We need to use
|
Chris@17
|
49 // assertSame() here because assertFalse() will pass falsy values (e.g.,
|
Chris@17
|
50 // empty arrays).
|
Chris@17
|
51 $this->assertSame(FALSE, $row->isStub());
|
Chris@17
|
52
|
Chris@0
|
53 $data_row = $row->getSource();
|
Chris@0
|
54 // The "data" row returned by getSource() also includes all source
|
Chris@0
|
55 // configuration - we remove it so we see only the data itself.
|
Chris@0
|
56 unset($data_row['plugin']);
|
Chris@0
|
57 unset($data_row['data_rows']);
|
Chris@0
|
58 unset($data_row['ids']);
|
Chris@0
|
59 $results[] = $data_row;
|
Chris@0
|
60 }
|
Chris@0
|
61 $this->assertIdentical($results, $data_rows);
|
Chris@0
|
62
|
Chris@0
|
63 // Validate the public APIs.
|
Chris@0
|
64 $this->assertIdentical($source->count(), count($data_rows));
|
Chris@0
|
65 $this->assertIdentical($source->getIds(), $ids);
|
Chris@0
|
66 $expected_fields = [
|
Chris@0
|
67 'key' => 'key',
|
Chris@0
|
68 'field1' => 'field1',
|
Chris@0
|
69 'field2' => 'field2',
|
Chris@0
|
70 ];
|
Chris@0
|
71 $this->assertIdentical($source->fields(), $expected_fields);
|
Chris@0
|
72 }
|
Chris@0
|
73
|
Chris@0
|
74 }
|