From 744b455de1e9a1684b7d79b22c39b0f3607f9b27 Mon Sep 17 00:00:00 2001 From: Val Bancer Date: Fri, 28 Oct 2016 22:14:20 +0200 Subject: [PATCH] fixed configuration of 'enabled' setting in components inside a component --- lib/Cake/Controller/Component.php | 2 +- .../Test/Case/Controller/ComponentTest.php | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Controller/Component.php b/lib/Cake/Controller/Component.php index 4de6d9f06..d58cbd3d5 100644 --- a/lib/Cake/Controller/Component.php +++ b/lib/Cake/Controller/Component.php @@ -90,7 +90,7 @@ class Component extends CakeObject { */ public function __get($name) { if (isset($this->_componentMap[$name]) && !isset($this->{$name})) { - $settings = array('enabled' => false) + (array)$this->_componentMap[$name]['settings']; + $settings = (array)$this->_componentMap[$name]['settings'] + array('enabled' => false); $this->{$name} = $this->_Collection->load($this->_componentMap[$name]['class'], $settings); } if (isset($this->{$name})) { diff --git a/lib/Cake/Test/Case/Controller/ComponentTest.php b/lib/Cake/Test/Case/Controller/ComponentTest.php index 8dbbfa537..e40833f61 100644 --- a/lib/Cake/Test/Case/Controller/ComponentTest.php +++ b/lib/Cake/Test/Case/Controller/ComponentTest.php @@ -31,7 +31,10 @@ class ParamTestComponent extends Component { * * @var array */ - public $components = array('Banana' => array('config' => 'value')); + public $components = array( + 'Apple' => array('enabled' => true), + 'Banana' => array('config' => 'value'), + ); } /** @@ -286,4 +289,17 @@ class ComponentTest extends CakeTestCase { $this->assertInstanceOf('EmailComponent', $Controller->SomethingWithEmail->Email); } +/** + * Test lazy loading of components inside components and both explicit and + * implicit 'enabled' setting. + * + * @return void + */ + public function testGet() { + $Collection = new ComponentCollection(); + $ParamTest = $Collection->load('ParamTest'); + $this->assertTrue($ParamTest->Apple->settings['enabled']); + $this->assertFalse($ParamTest->Banana->settings['enabled']); + } + }