Merge pull request #9667 from bancer/components-enabled-setting

fixed configuration of 'enabled' setting in components inside a
This commit is contained in:
Mark Story 2016-10-28 22:09:37 -04:00 committed by GitHub
commit 7f0b0739a8
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']);
}
}