Pull merge.
[yaffs-website] / web / core / modules / migrate / tests / src / Kernel / MigrateEmbeddedDataTest.php
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       // The plugin should not mark any rows as stubs. We need to use
49       // assertSame() here because assertFalse() will pass falsy values (e.g.,
50       // empty arrays).
51       $this->assertSame(FALSE, $row->isStub());
52
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;
60     }
61     $this->assertIdentical($results, $data_rows);
62
63     // Validate the public APIs.
64     $this->assertIdentical($source->count(), count($data_rows));
65     $this->assertIdentical($source->getIds(), $ids);
66     $expected_fields = [
67       'key' => 'key',
68       'field1' => 'field1',
69       'field2' => 'field2',
70     ];
71     $this->assertIdentical($source->fields(), $expected_fields);
72   }
73
74 }