class SubProcessWithSkipTest
Same name and namespace in other branches
- 11.x core/modules/migrate/tests/src/Kernel/process/SubProcessWithSkipTest.php \Drupal\Tests\migrate\Kernel\process\SubProcessWithSkipTest
Tests process pipelines when a sub_process skips a row or process.
@group migrate
Hierarchy
- class \Drupal\Tests\migrate\Kernel\process\SubProcessWithSkipTest
Expanded class hierarchy of SubProcessWithSkipTest
File
-
core/
modules/ migrate/ tests/ src/ Kernel/ process/ SubProcessWithSkipTest.php, line 16
Namespace
Drupal\Tests\migrate\Kernel\processView source
class SubProcessWithSkipTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'migrate',
];
/**
* Provides the test migration definition.
*
* @return array
*/
public function getDefinition() {
return [
'source' => [
'plugin' => 'embedded_data',
'data_rows' => [
[
'id' => 'skip_test',
'my_array_of_arrays' => [
[
'key_1' => 'foo',
'key_2' => 'bar',
],
[
'key_1' => NULL,
'key_2' => 'baz',
],
],
],
],
'ids' => [
'id' => [
'type' => 'string',
],
],
],
'process' => [
'first' => [
'plugin' => 'default_value',
'default_value' => 'something outside of sub_process',
],
'second' => [
'plugin' => 'sub_process',
'source' => 'my_array_of_arrays',
'process' => [
'prop_1' => [
[
'plugin' => 'skip_on_empty',
'source' => 'key_1',
],
// We put a process after skip_on_empty to better test skipping
// a process.
[
'plugin' => 'get',
'source' => 'key_2',
],
],
'prop_2' => 'key_2',
],
],
],
'destination' => [
'plugin' => 'config',
'config_name' => 'migrate_test.settings',
],
];
}
/**
* Test use of skip_on_empty within sub_process.
*
* @dataProvider providerTestSubProcessSkip
*
* @param string $method
* The method to use with skip_on_empty (row or process).
* @param array $expected_data
* The expected result of the migration.
*/
public function testSubProcessSkip(string $method, array $expected_data) : void {
$definition = $this->getDefinition();
$definition['process']['second']['process']['prop_1'][0]['method'] = $method;
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
$executable = new MigrateExecutable($migration);
$result = $executable->import();
// Migration needs to succeed before further assertions are made.
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $result);
// Compare with expected data.
$this->assertEquals($expected_data, \Drupal::config('migrate_test.settings')->get());
}
/**
* Data provider for testNotFoundSubProcess().
*
* @return array
*/
public static function providerTestSubProcessSkip() : array {
return [
'skip row' => [
'method' => 'row',
'expected_data' => [
'first' => 'something outside of sub_process',
'second' => [
[
'prop_1' => 'bar',
'prop_2' => 'bar',
],
],
],
],
'skip process' => [
'method' => 'process',
'expected_data' => [
'first' => 'something outside of sub_process',
'second' => [
[
'prop_1' => 'bar',
'prop_2' => 'bar',
],
[
'prop_2' => 'baz',
],
],
],
],
];
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary |
---|---|---|---|---|
ConfigTestTrait::configImporter | protected | function | Returns a ConfigImporter object to import test configuration. | |
ConfigTestTrait::copyConfig | protected | function | Copies configuration objects from source storage to target storage. | |
ExtensionListTestTrait::getModulePath | protected | function | Gets the path for the specified module. | |
ExtensionListTestTrait::getThemePath | protected | function | Gets the path for the specified theme. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. |
StorageCopyTrait::replaceStorageContents | protected static | function | Copy the configuration from one storage to another and remove stale items. | |
SubProcessWithSkipTest::$modules | protected static | property | Modules to install. | |
SubProcessWithSkipTest::getDefinition | public | function | Provides the test migration definition. | |
SubProcessWithSkipTest::providerTestSubProcessSkip | public static | function | Data provider for testNotFoundSubProcess(). | |
SubProcessWithSkipTest::testSubProcessSkip | public | function | Test use of skip_on_empty within sub_process. | |
TestRequirementsTrait::checkModuleRequirements | Deprecated | private | function | Checks missing module requirements. |
TestRequirementsTrait::checkRequirements | Deprecated | protected | function | Check module requirements for the Drupal use case. |
TestRequirementsTrait::getDrupalRoot | protected static | function | Returns the Drupal root directory. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.