Skip to content

Commit

Permalink
Defect 11686
Browse files Browse the repository at this point in the history
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
Eugene Ritter committed Feb 10, 2018
1 parent 8ca5054 commit 6a50ccf
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Core/ObjectRegistry.php
Expand Up @@ -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;
Expand Down
77 changes: 77 additions & 0 deletions tests/TestCase/View/HelperRegistryTest.php
Expand Up @@ -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.