Skip to content
Permalink
Browse files

Defect 11686

ObjectRegistry::normalizedArray normalizes the array the first time. When passing an array already normalized it continues trying to normalize producing a nested effect. This should resolve the issue.
  • Loading branch information...
T0mats0 committed Feb 10, 2018
1 parent 8ca5054 commit 6a50ccfa2501f4b94af529c0f29e80bf87a8b4fe
Showing with 82 additions and 1 deletion.
  1. +5 −1 src/Core/ObjectRegistry.php
  2. +77 −0 tests/TestCase/View/HelperRegistryTest.php
@@ -278,7 +278,11 @@ public function normalizeArray($objects)
$objectName = $i;
}
list(, $name) = pluginSplit($objectName);
$normal[$name] = ['class' => $objectName, 'config' => $config];
if (isset($config['class'])) {
$normal[$name] = $config;
} else {
$normal[$name] = ['class' => $objectName, 'config' => $config];
}
}
return $normal;
@@ -351,4 +351,81 @@ public function testLoadMultipleTimesDifferentConfigValues()
$this->Helpers->load('Html', ['key' => 'value']);
$this->Helpers->load('Html', ['key' => 'new value']);
}
/**
* Test ObjectRegistry normalizeArray
*
* @return void
*/
public function testArrayIsNormalized()
{
$config = [
'SomeHelper' => [
'value' => 1,
'value2' => 2
],
'Plugin.SomeOtherHelper' => [
'value' => 1,
'value2' => 2
]
];
$result = $this->Helpers->normalizeArray($config);
$expected = [
'SomeHelper' => [
'class' => 'SomeHelper',
'config' => [
'value' => 1,
'value2' => 2
]
],
'SomeOtherHelper' => [
'class' => 'Plugin.SomeOtherHelper',
'config' => [
'value' => 1,
'value2' => 2
]
],
];
$this->assertEquals($expected, $result);
}
/**
* Test that calling normalizeArray multiple times does
* not nest the configuration.
*
* @return void
*/
public function testArrayIsNormalizedAfterMultipleCalls()
{
$config = [
'SomeHelper' => [
'value' => 1,
'value2' => 2
],
'Plugin.SomeOtherHelper' => [
'value' => 1,
'value2' => 2
]
];
$result1 = $this->Helpers->normalizeArray($config);
$result2 = $this->Helpers->normalizeArray($result1);
$expected = [
'SomeHelper' => [
'class' => 'SomeHelper',
'config' => [
'value' => 1,
'value2' => 2
]
],
'SomeOtherHelper' => [
'class' => 'Plugin.SomeOtherHelper',
'config' => [
'value' => 1,
'value2' => 2
]
],
];
$this->assertEquals($expected, $result2);
}
}

0 comments on commit 6a50ccf

Please sign in to comment.
You can’t perform that action at this time.