comparison core/modules/migrate/tests/src/Kernel/MigrateEmbeddedDataTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Tests\migrate\Kernel;
4
5 use Drupal\KernelTests\KernelTestBase;
6
7 /**
8 * Tests the EmbeddedDataSource plugin.
9 *
10 * @group migrate
11 */
12 class MigrateEmbeddedDataTest extends KernelTestBase {
13
14 /**
15 * Modules to enable.
16 *
17 * @var array
18 */
19 public static $modules = ['migrate'];
20
21 /**
22 * Tests the embedded_data source plugin.
23 */
24 public function testEmbeddedData() {
25 $data_rows = [
26 ['key' => '1', 'field1' => 'f1value1', 'field2' => 'f2value1'],
27 ['key' => '2', 'field1' => 'f1value2', 'field2' => 'f2value2'],
28 ];
29 $ids = ['key' => ['type' => 'integer']];
30 $definition = [
31 'migration_tags' => ['Embedded data test'],
32 'source' => [
33 'plugin' => 'embedded_data',
34 'data_rows' => $data_rows,
35 'ids' => $ids,
36 ],
37 'process' => [],
38 'destination' => ['plugin' => 'null'],
39 ];
40
41 $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
42 $source = $migration->getSourcePlugin();
43
44 // Validate the plugin returns the source data that was provided.
45 $results = [];
46 /** @var \Drupal\migrate\Row $row */
47 foreach ($source as $row) {
48 $data_row = $row->getSource();
49 // The "data" row returned by getSource() also includes all source
50 // configuration - we remove it so we see only the data itself.
51 unset($data_row['plugin']);
52 unset($data_row['data_rows']);
53 unset($data_row['ids']);
54 $results[] = $data_row;
55 }
56 $this->assertIdentical($results, $data_rows);
57
58 // Validate the public APIs.
59 $this->assertIdentical($source->count(), count($data_rows));
60 $this->assertIdentical($source->getIds(), $ids);
61 $expected_fields = [
62 'key' => 'key',
63 'field1' => 'field1',
64 'field2' => 'field2',
65 ];
66 $this->assertIdentical($source->fields(), $expected_fields);
67 }
68
69 }