Skip to content
Permalink
Browse files

fixed configuration of 'enabled' setting in components inside a

component
  • Loading branch information...
bancer committed Oct 28, 2016
1 parent 1a58d15 commit 744b455de1e9a1684b7d79b22c39b0f3607f9b27
Showing with 18 additions and 2 deletions.
  1. +1 −1 lib/Cake/Controller/Component.php
  2. +17 −1 lib/Cake/Test/Case/Controller/ComponentTest.php
@@ -90,7 +90,7 @@ public function __construct(ComponentCollection $collection, $settings = array()
*/
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})) {
@@ -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 @@ public function testSomethingReferencingEmailComponent() {
$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']);
}
}

0 comments on commit 744b455

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