Browse Source

Allow class alias for helper config.

mscherer 5 years ago
parent
commit
aee95ffc78
2 changed files with 9 additions and 1 deletions
  1. 1 1
      src/Core/ObjectRegistry.php
  2. 8 0
      tests/TestCase/View/HelperRegistryTest.php

+ 1 - 1
src/Core/ObjectRegistry.php

@@ -299,7 +299,7 @@ abstract class ObjectRegistry implements Countable, IteratorAggregate
             }
             [, $name] = pluginSplit($objectName);
             if (isset($config['class'])) {
-                $normal[$name] = $config;
+                $normal[$name] = $config + ['config' => []];
             } else {
                 $normal[$name] = ['class' => $objectName, 'config' => $config];
             }

+ 8 - 0
tests/TestCase/View/HelperRegistryTest.php

@@ -357,6 +357,7 @@ class HelperRegistryTest extends TestCase
     public function testArrayIsNormalized()
     {
         $config = [
+            'SomeHelper',
             'SomeHelper' => [
                 'value' => 1,
                 'value2' => 2,
@@ -403,6 +404,9 @@ class HelperRegistryTest extends TestCase
                 'value' => 1,
                 'value2' => 2,
             ],
+            'SomeAliasesHelper' => [
+                'class' => 'Plugin.SomeHelper',
+            ],
         ];
 
         $result1 = $this->Helpers->normalizeArray($config);
@@ -422,6 +426,10 @@ class HelperRegistryTest extends TestCase
                     'value2' => 2,
                 ],
             ],
+            'SomeAliasesHelper' => [
+                'class' => 'Plugin.SomeHelper',
+                'config' => [],
+            ],
         ];
         $this->assertEquals($expected, $result2);
     }