diff --git a/src/Core/ObjectRegistry.php b/src/Core/ObjectRegistry.php index 4b6272def9a..cc019a7db5a 100644 --- a/src/Core/ObjectRegistry.php +++ b/src/Core/ObjectRegistry.php @@ -69,7 +69,12 @@ abstract class ObjectRegistry */ public function load($objectName, $config = []) { - list(, $name) = pluginSplit($objectName); + if (empty($config) && !isset($this->_loaded[$objectName])) { + list(, $name) = pluginSplit($objectName); + } else { + $name = $objectName; + } + $loaded = isset($this->_loaded[$name]); if ($loaded && !empty($config)) { $this->_checkDuplicate($name, $config); diff --git a/tests/TestCase/Cache/CacheTest.php b/tests/TestCase/Cache/CacheTest.php index ff9d120e755..beccd574d5c 100644 --- a/tests/TestCase/Cache/CacheTest.php +++ b/tests/TestCase/Cache/CacheTest.php @@ -250,6 +250,26 @@ public function testConfigRead() $this->assertEquals($expected, Cache::config('tests')); } + /** + * test config() with dotted name + * + * @return void + */ + public function testConfigDottedAlias() + { + Cache::config('cache.dotted', [ + 'className' => 'File', + 'path' => TMP, + 'prefix' => 'cache_value_' + ]); + + $engine = Cache::engine('cache.dotted'); + $this->assertContains('cache.dotted', Cache::configured()); + $this->assertNotContains('dotted', Cache::configured()); + $this->assertInstanceOf('Cake\Cache\Engine\FileEngine', $engine); + Cache::drop('cache.dotted'); + } + /** * testGroupConfigs method */ diff --git a/tests/TestCase/View/HelperRegistryTest.php b/tests/TestCase/View/HelperRegistryTest.php index 62f266df983..5ddda084f06 100644 --- a/tests/TestCase/View/HelperRegistryTest.php +++ b/tests/TestCase/View/HelperRegistryTest.php @@ -195,6 +195,32 @@ public function testLoadPluginHelper() $this->assertInstanceOf('TestPlugin\View\Helper\OtherHelperHelper', $this->Helpers->OtherHelper, 'Class is wrong'); } + /** + * test loading helpers with dotted aliases + * + * @return void + */ + public function testLoadPluginHelperDottedAlias() + { + Plugin::load(['TestPlugin']); + + $result = $this->Helpers->load('thing.helper', [ + 'className' => 'TestPlugin.OtherHelper', + ]); + $this->assertInstanceOf('TestPlugin\View\Helper\OtherHelperHelper', $result, 'Helper class is wrong.'); + $this->assertInstanceOf( + 'TestPlugin\View\Helper\OtherHelperHelper', + $this->Helpers->get('thing.helper'), + 'Class is wrong' + ); + $this->assertTrue($this->Helpers->has('thing.helper')); + $this->assertFalse($this->Helpers->has('thing')); + $this->assertFalse($this->Helpers->has('helper')); + + $this->Helpers->unload('thing.helper'); + $this->assertFalse($this->Helpers->has('thing.helper'), 'Should be gone now.'); + } + /** * Test reset. *