public function ConfigDifferTest::testDiff in Configuration Update Manager 8
@covers \Drupal\config_update\ConfigDiffer::diff
File
- tests/
src/ Unit/ ConfigDifferTest.php, line 247
Class
- ConfigDifferTest
- Tests the \Drupal\config_update\ConfigDiffer class.
Namespace
Drupal\Tests\config_update\UnitCode
public function testDiff() {
$configOne = [
'uuid' => '1234-5678-90',
'id' => 'test.config.id',
'id_to_remove' => 'test.remove.id',
'type' => 'old_type',
'true_value' => TRUE,
'null_value' => NULL,
'nested_array' => [
'flat_array' => [
'value2',
'value1',
'value3',
],
'custom_key' => 'value',
],
];
$configTwo = [
'uuid' => '09-8765-4321',
'id' => 'test.config.id',
'type' => 'new_type',
'true_value' => FALSE,
'null_value' => FALSE,
'nested_array' => [
'flat_array' => [
'value2',
'value3',
],
'custom_key' => 'value',
'custom_key_2' => 'value2',
],
];
$edits = $this->configDiffer
->diff($configOne, $configTwo)
->getEdits();
$expectedEdits = [
[
'copy' => [
'orig' => [
'id : test.config.id',
],
'closing' => [
'id : test.config.id',
],
],
],
[
'delete' => [
'orig' => [
'id_to_remove : test.remove.id',
],
'closing' => FALSE,
],
],
[
'copy' => [
'orig' => [
'nested_array',
'nested_array::custom_key : value',
],
'closing' => [
'nested_array',
'nested_array::custom_key : value',
],
],
],
[
'add' => [
'orig' => FALSE,
'closing' => [
'nested_array::custom_key_2 : value2',
],
],
],
[
'copy' => [
'orig' => [
'nested_array::flat_array',
'nested_array::flat_array::0 : value2',
],
'closing' => [
'nested_array::flat_array',
'nested_array::flat_array::0 : value2',
],
],
],
[
'change' => [
'orig' => [
'nested_array::flat_array::1 : value1',
'nested_array::flat_array::2 : value3',
'null_value : null',
'true_value : true',
'type : old_type',
],
'closing' => [
'nested_array::flat_array::1 : value3',
'null_value : false',
'true_value : false',
'type : new_type',
],
],
],
];
$this
->assertEquals(count($expectedEdits), count($edits));
/** @var \Drupal\Component\Diff\Engine\DiffOp $diffOp */
foreach ($edits as $index => $diffOp) {
$this
->assertEquals($expectedEdits[$index][$diffOp->type]['orig'], $diffOp->orig);
$this
->assertEquals($expectedEdits[$index][$diffOp->type]['closing'], $diffOp->closing);
}
}