View source
<?php
namespace Drupal\Tests\migrate\Kernel;
use Drupal\KernelTests\KernelTestBase;
class MigrateEmbeddedDataTest extends KernelTestBase {
protected static $modules = [
'migrate',
];
public function testEmbeddedData() {
$data_rows = [
[
'key' => '1',
'field1' => 'f1value1',
'field2' => 'f2value1',
],
[
'key' => '2',
'field1' => 'f1value2',
'field2' => 'f2value2',
],
];
$ids = [
'key' => [
'type' => 'integer',
],
];
$definition = [
'migration_tags' => [
'Embedded data test',
],
'source' => [
'plugin' => 'embedded_data',
'data_rows' => $data_rows,
'ids' => $ids,
],
'process' => [],
'destination' => [
'plugin' => 'null',
],
];
$migration = \Drupal::service('plugin.manager.migration')
->createStubMigration($definition);
$source = $migration
->getSourcePlugin();
$results = [];
foreach ($source as $row) {
$this
->assertFalse($row
->isStub());
$data_row = $row
->getSource();
unset($data_row['plugin']);
unset($data_row['data_rows']);
unset($data_row['ids']);
$results[] = $data_row;
}
$this
->assertSame($data_rows, $results);
$this
->assertSame(count($data_rows), $source
->count());
$this
->assertSame($ids, $source
->getIds());
$expected_fields = [
'key' => 'key',
'field1' => 'field1',
'field2' => 'field2',
];
$this
->assertSame($expected_fields, $source
->fields());
}
}