class SubProcessTest in Drupal 8
Tests the sub_process process plugin.
@group migrate
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\migrate\Unit\process\SubProcessTest
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of SubProcessTest
File
- core/
modules/ migrate/ tests/ src/ Unit/ process/ SubProcessTest.php, line 18
Namespace
Drupal\Tests\migrate\Unit\processView source
class SubProcessTest extends MigrateTestCase {
/**
* The sub_process plugin being tested.
*
* @var \Drupal\migrate\Plugin\migrate\process\SubProcess
*/
protected $plugin;
/**
* @var array
*/
protected $migrationConfiguration = [
'id' => 'test',
];
/**
* Tests the sub_process process plugin.
*
* @dataProvider providerTestSubProcess
*/
public function testSubProcess($process_configuration, $source_values = []) {
$migration = $this
->getMigration($process_configuration);
// Set up the properties for the sub_process.
$plugin = new SubProcess($process_configuration, 'sub_process', []);
// Manually create the plugins. Migration::getProcessPlugins does this
// normally but the plugin system is not available.
foreach ($process_configuration['process'] as $destination => $source) {
$sub_process_plugins[$destination][] = new Get([
'source' => $source,
], 'get', []);
}
$migration
->expects($this
->at(1))
->method('getProcessPlugins')
->willReturn($sub_process_plugins);
// Set up the key plugins.
$key_plugin['key'][] = new Get([
'source' => '@id',
], 'get', []);
$migration
->expects($this
->at(2))
->method('getProcessPlugins')
->will($this
->returnValue($key_plugin));
$event_dispatcher = $this
->createMock(EventDispatcherInterface::class);
$migrate_executable = new MigrateExecutable($migration, $this
->createMock(MigrateMessageInterface::class), $event_dispatcher);
// The current value of the pipeline.
$current_value = [
[
'source_foo' => 'test',
'source_id' => 42,
] + $source_values,
];
// This is not used but the interface requires it, so create an empty row.
$row = new Row($source_values);
// After transformation, check to make sure that source_foo and source_id's
// values ended up in the proper destinations, and that the value of the
// key (@id) is the same as the destination ID (42).
$new_value = $plugin
->transform($current_value, $migrate_executable, $row, 'test');
$this
->assertCount(1, $new_value);
$this
->assertCount(count($process_configuration['process']), $new_value[42]);
$this
->assertSame('test', $new_value[42]['foo']);
if ($source_values) {
$this
->assertSame('source_baz', $new_value[42]['baaa']);
}
$this
->assertSame(42, $new_value[42]['id']);
}
/**
* Data provider for testSubProcess().
*/
public function providerTestSubProcess() {
return [
'no source context' => [
'process configuration' => [
'process' => [
'foo' => 'source_foo',
'id' => 'source_id',
],
'key' => '@id',
],
],
'default source key' => [
'process configuration' => [
'process' => [
'foo' => 'source_foo',
'id' => 'source_id',
'baaa' => 'source/baf',
],
'key' => '@id',
'include_source' => TRUE,
],
'source values' => [
'baf' => 'source_baz',
],
],
'renamed source key' => [
'process configuration' => [
'process' => [
'foo' => 'source_foo',
'id' => 'source_id',
'baaa' => 'my_source/baf',
],
'key' => '@id',
'include_source' => TRUE,
'source_key' => 'my_source',
],
'source values' => [
'baf' => 'source_baz',
],
],
];
}
/**
* Tests the sub_process process plugin.
*
* @dataProvider providerTestNotFoundSubProcess
*/
public function testNotFoundSubProcess($process_configuration, $source_values = []) {
$migration = $this
->getMigration();
// Set up the properties for the sub_process.
$plugin = new SubProcess($process_configuration, 'sub_process', []);
// Manually create the plugins. Migration::getProcessPlugins does this
// normally but the plugin system is not available.
foreach ($process_configuration['process'] as $destination => $source) {
$sub_process_plugins[$destination][] = new Get([
'source' => $source,
], 'get', []);
}
$migration
->expects($this
->at(1))
->method('getProcessPlugins')
->willReturn($sub_process_plugins);
// Set up the key plugins.
if (array_key_exists('key', $process_configuration)) {
$key_plugin['key'][] = new Get([
'source' => '@id',
], 'get', []);
$migration
->expects($this
->at(2))
->method('getProcessPlugins')
->will($this
->returnValue($key_plugin));
}
$event_dispatcher = $this
->createMock(EventDispatcherInterface::class);
$migrate_executable = new MigrateExecutable($migration, $this
->createMock(MigrateMessageInterface::class), $event_dispatcher);
// The current value of the pipeline.
$current_value = [
[
'source_foo' => 'test',
'source_id' => NULL,
] + $source_values,
];
// This is not used but the interface requires it, so create an empty row.
$row = new Row($source_values);
// After transformation, check to make sure that source_foo and source_id's
// values ended up in the proper destinations, and that the value of the
// key (@id) is the same as the destination ID (42).
$new_value = $plugin
->transform($current_value, $migrate_executable, $row, 'test');
$this
->assertArrayEquals([], $new_value);
}
/**
* Data provider for testNotFoundSubProcess().
*/
public function providerTestNotFoundSubProcess() {
return [
'no key' => [
'process configuration' => [
'process' => [
'foo' => 'source_foo',
],
'key' => '@id',
],
],
'lookup returns NULL' => [
'process configuration' => [
'process' => [
'foo' => 'source_foo',
'id' => 'source_id',
],
'key' => '@id',
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateTestCase:: |
protected | property | The migration ID map. | |
MigrateTestCase:: |
protected | property | Local store for mocking setStatus()/getStatus(). | |
MigrateTestCase:: |
protected | function | Generates a table schema from a row. | |
MigrateTestCase:: |
protected | function | Gets an SQLite database connection object for use in tests. | |
MigrateTestCase:: |
protected | function | Retrieves a mocked migration. | 1 |
MigrateTestCase:: |
protected | function | Gets the value on a row for a given key. | 1 |
MigrateTestCase:: |
public | function | Tests a query. | |
MigrateTestCase:: |
protected | function | Asserts tested values during test retrieval. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
SubProcessTest:: |
protected | property |
Overrides MigrateTestCase:: |
|
SubProcessTest:: |
protected | property | The sub_process plugin being tested. | |
SubProcessTest:: |
public | function | Data provider for testNotFoundSubProcess(). | |
SubProcessTest:: |
public | function | Data provider for testSubProcess(). | |
SubProcessTest:: |
public | function | Tests the sub_process process plugin. | |
SubProcessTest:: |
public | function | Tests the sub_process process plugin. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |