function MigrateEmbeddedDataTest::testEmbeddedData
Same name in other branches
- 9 core/modules/migrate/tests/src/Kernel/MigrateEmbeddedDataTest.php \Drupal\Tests\migrate\Kernel\MigrateEmbeddedDataTest::testEmbeddedData()
- 10 core/modules/migrate/tests/src/Kernel/MigrateEmbeddedDataTest.php \Drupal\Tests\migrate\Kernel\MigrateEmbeddedDataTest::testEmbeddedData()
- 11.x core/modules/migrate/tests/src/Kernel/MigrateEmbeddedDataTest.php \Drupal\Tests\migrate\Kernel\MigrateEmbeddedDataTest::testEmbeddedData()
Tests the embedded_data source plugin.
File
-
core/
modules/ migrate/ tests/ src/ Kernel/ MigrateEmbeddedDataTest.php, line 24
Class
- MigrateEmbeddedDataTest
- Tests the EmbeddedDataSource plugin.
Namespace
Drupal\Tests\migrate\KernelCode
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();
// Validate the plugin returns the source data that was provided.
$results = [];
/** @var \Drupal\migrate\Row $row */
foreach ($source as $row) {
// The plugin should not mark any rows as stubs. We need to use
// assertSame() here because assertFalse() will pass falsy values (e.g.,
// empty arrays).
$this->assertSame(FALSE, $row->isStub());
$data_row = $row->getSource();
// The "data" row returned by getSource() also includes all source
// configuration - we remove it so we see only the data itself.
unset($data_row['plugin']);
unset($data_row['data_rows']);
unset($data_row['ids']);
$results[] = $data_row;
}
$this->assertIdentical($results, $data_rows);
// Validate the public APIs.
$this->assertIdentical($source->count(), count($data_rows));
$this->assertIdentical($source->getIds(), $ids);
$expected_fields = [
'key' => 'key',
'field1' => 'field1',
'field2' => 'field2',
];
$this->assertIdentical($source->fields(), $expected_fields);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.