function SubProcessTest::testSubProcess

Same name in other branches
  1. 8.9.x core/modules/migrate/tests/src/Unit/process/SubProcessTest.php \Drupal\Tests\migrate\Unit\process\SubProcessTest::testSubProcess()
  2. 10 core/modules/migrate/tests/src/Unit/process/SubProcessTest.php \Drupal\Tests\migrate\Unit\process\SubProcessTest::testSubProcess()
  3. 11.x core/modules/migrate/tests/src/Unit/process/SubProcessTest.php \Drupal\Tests\migrate\Unit\process\SubProcessTest::testSubProcess()

Tests the sub_process process plugin.

@dataProvider providerTestSubProcess

File

core/modules/migrate/tests/src/Unit/process/SubProcessTest.php, line 41

Class

SubProcessTest
Tests the sub_process process plugin.

Namespace

Drupal\Tests\migrate\Unit\process

Code

public function testSubProcess($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', []);
    }
    // Set up the key plugins.
    $key_plugin['key'][] = new Get([
        'source' => '@id',
    ], 'get', []);
    $migration->expects($this->exactly(2))
        ->method('getProcessPlugins')
        ->willReturnOnConsecutiveCalls($sub_process_plugins, $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->assertSameSize($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']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.