Adding settings['callbacks'] as a way to define enabled/disabled state of helpers in settings arrays. This should replace the separate parameter.

Tests updated.
This commit is contained in:
mark_story 2010-11-06 14:58:27 -04:00
parent 92fec4588a
commit 1ba28c246b
2 changed files with 18 additions and 1 deletions

View file

@ -38,6 +38,9 @@ class HelperCollection extends ObjectCollection {
/**
* Loads/constructs a helper. Will return the instance in the registry if it already exists.
* By setting `$enable` to false you can disable callbacks for a helper. Alternatively you
* can set `$settings['callbacks'] = false` to disable callbacks. This alias is provided so that when
* declaring $helpers arrays you can disable callbacks on helpers.
*
* @param string $helper Helper name to load
* @param array $settings Settings for the helper.
@ -72,7 +75,7 @@ class HelperCollection extends ObjectCollection {
foreach ($vars as $var) {
$this->_loaded[$name]->{$var} = $this->_View->{$var};
}
$enable = isset($settings['callbacks']) ? $settings['callbacks'] : $enable;
if ($enable === true) {
$this->_enabled[] = $name;
}

View file

@ -69,6 +69,20 @@ class HelperCollectionTest extends CakeTestCase {
$this->assertFalse($this->Helpers->enabled('Html'), 'Html should be disabled');
}
/**
* test that the callbacks setting disables the helper.
*
* @return void
*/
function testLoadWithCallbacksFalse() {
$result = $this->Helpers->load('Html', array('callbacks' => false));
$this->assertType('HtmlHelper', $result);
$this->assertType('HtmlHelper', $this->Helpers->Html);
$this->assertFalse($this->Helpers->enabled('Html'), 'Html should be disabled');
}
/**
* test missinghelper exception
*