public function ReversibleConfigDifferTest::testDiff in Update helper 2.x
Same name and namespace in other branches
- 8 tests/src/Kernel/ReversibleConfigDifferTest.php \Drupal\Tests\update_helper\Kernel\ReversibleConfigDifferTest::testDiff()
@covers \Drupal\update_helper\ReversibleConfigDiffer::diff
File
- tests/
src/ Kernel/ ReversibleConfigDifferTest.php, line 159
Class
- ReversibleConfigDifferTest
- Automated tests for ReversibleConfigDiffer class.
Namespace
Drupal\Tests\update_helper\KernelCode
public function testDiff() {
/** @var \Drupal\update_helper\ReversibleConfigDiffer $configDiffer */
$configDiffer = \Drupal::service('update_helper.config_differ');
$configOne = [
'uuid' => '1234-5678-90',
'_core' => 'core_id_1',
'id' => 'test.config.id',
'short_text' => 'en',
'true_value' => TRUE,
'nested_array' => [
'flat_array' => [
'value2',
'value1',
'value3',
],
'custom_key' => 'value',
],
'main_data' => [
'uuid' => '1234-5678-90',
],
];
$configTwo = [
'uuid' => '09-8765-4321',
'_core' => 'core_id_2',
'id' => 'test.config.id',
'short_text' => 'en',
'true_value' => TRUE,
'nested_array' => [
'flat_array' => [
'value2',
'value3',
],
'custom_key' => 'value',
'new_custom_key' => 'value',
],
'main_data' => [
'uuid' => '09-8765-4321',
],
];
$edits = $configDiffer
->diff($configOne, $configTwo)
->getEdits();
$expectedEdits = [
[
'copy' => [
'orig' => [
'id : s:14:"test.config.id";',
'main_data',
],
'closing' => [
'id : s:14:"test.config.id";',
'main_data',
],
],
],
[
'change' => [
'orig' => [
'main_data::uuid : s:12:"1234-5678-90";',
],
'closing' => [
'main_data::uuid : s:12:"09-8765-4321";',
],
],
],
[
'copy' => [
'orig' => [
'nested_array',
'nested_array::custom_key : s:5:"value";',
'nested_array::flat_array',
'nested_array::flat_array::- : s:6:"value2";',
],
'closing' => [
'nested_array',
'nested_array::custom_key : s:5:"value";',
'nested_array::flat_array',
'nested_array::flat_array::- : s:6:"value2";',
],
],
],
[
'delete' => [
'orig' => [
'nested_array::flat_array::- : s:6:"value1";',
],
'closing' => FALSE,
],
],
[
'copy' => [
'orig' => [
'nested_array::flat_array::- : s:6:"value3";',
],
'closing' => [
'nested_array::flat_array::- : s:6:"value3";',
],
],
],
[
'add' => [
'orig' => FALSE,
'closing' => [
'nested_array::new_custom_key : s:5:"value";',
],
],
],
[
'copy' => [
'orig' => [
'short_text : s:2:"en";',
'true_value : b:1;',
],
'closing' => [
'short_text : s:2:"en";',
'true_value : b:1;',
],
],
],
];
$this
->assertEquals(count($expectedEdits), count($edits));
foreach ($edits as $index => $diffOp) {
/** @var \Drupal\Component\Diff\Engine\DiffOp $diffOp */
$this
->assertEquals($expectedEdits[$index][$diffOp->type]['orig'], $diffOp->orig);
$this
->assertEquals($expectedEdits[$index][$diffOp->type]['closing'], $diffOp->closing);
}
}