Skip to content
Permalink
Browse files

Adding a way to load helpers in a disabled state. Updating tests and …

…subclasses.
  • Loading branch information...
markstory committed Jul 3, 2010
1 parent d0de468 commit 16d5b2655c83a838b768d00e96d09cdc080c3478
@@ -268,9 +268,10 @@ public function attach($behavior, $config = array()) {
*
* @param string $behavior CamelCased name of the behavior to load
* @param array $config Behavior configuration parameters
* @param boolean $enable Whether or not this helper should be enabled by default
* @return boolean True on success, false on failure
*/
public function load($behavior, $config = array()) {
public function load($behavior, $config = array(), $enable = true) {
list($plugin, $name) = pluginSplit($behavior);
$class = $name . 'Behavior';
@@ -40,9 +40,10 @@ abstract class ObjectCollection {
*
* @param string $name Name of object to load.
* @param array $options Array of configuration options for the object to be constructed.
* @param boolean $enable Whether or not this helper should be enabled by default
* @return object the constructed object
*/
abstract public function load($name, $options = array());
abstract public function load($name, $options = array(), $enable = true);
/**
* Unloads/deletes an object from the collection.
@@ -41,10 +41,11 @@ public function __construct(View $view) {
*
* @param string $helper Helper name to load
* @param array $settings Settings for the helper.
* @param boolean $enable Whether or not this helper should be enabled by default
* @return Helper A helper object, Either the existing loaded helper or a new one.
* @throws MissingHelperFileException, MissingHelperClassException when the helper could not be found
*/
public function load($helper, $settings = array()) {
public function load($helper, $settings = array(), $enable = true) {
list($plugin, $name) = pluginSplit($helper, true);
if (isset($this->{$name})) {
@@ -63,6 +64,9 @@ public function load($helper, $settings = array()) {
if (!in_array($name, $this->_attached)) {
$this->_attached[] = $name;
}
if ($enable === false) {
$this->_disabled[] = $name;
}
return $this->{$name};
}
@@ -57,6 +57,18 @@ function testLoad() {
$this->assertTrue($this->Helpers->enabled('Html'));
}
/**
* test load and enable = false
*
* @return void
*/
function testLoadWithEnableFalse() {
$result = $this->Helpers->load('Html', array(), false);
$this->assertType('HtmlHelper', $result);
$this->assertType('HtmlHelper', $this->Helpers->Html);
$this->assertFalse($this->Helpers->enabled('Html'), 'Html should be disabled');
}
/**
* test missinghelper exception
*

0 comments on commit 16d5b26

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