fixed configuration of 'enabled' setting in components inside a

component
This commit is contained in:
Val Bancer 2016-10-28 22:14:20 +02:00
parent 1a58d15632
commit 744b455de1
2 changed files with 18 additions and 2 deletions

View file

@ -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})) {

View file

@ -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']);
}
}