Skip to content
Permalink
Browse files

Make View::addHelper() set the loaded helper as View's property.

Also updated test cases to properly test various helper loading methods.
  • Loading branch information...
ADmad committed Sep 14, 2014
1 parent aac0693 commit 3efd9d1db6b2647aebe71258e39772ef9ce4c782
Showing with 17 additions and 7 deletions.
  1. +3 −3 src/View/View.php
  2. +14 −4 tests/TestCase/View/ViewTest.php
@@ -674,8 +674,7 @@ public function loadHelpers() {
$registry = $this->helpers();
$helpers = $registry->normalizeArray($this->helpers);
foreach ($helpers as $properties) {
list(, $class) = pluginSplit($properties['class']);
$this->{$class} = $registry->load($properties['class'], $properties['config']);
$this->addHelper($properties['class'], $properties['config']);
}
}
@@ -764,7 +763,8 @@ public function helpers() {
* @see HelperRegistry::load()
*/
public function addHelper($helperName, array $config = []) {
return $this->helpers()->load($helperName, $config);
list(, $class) = pluginSplit($helperName);
return $this->{$class} = $this->helpers()->load($helperName, $config);
}
/**
@@ -906,14 +906,18 @@ public function testViewEvent() {
}
/**
* Test __get allowing access to helpers.
* Test loading helper using addHelper().
*
* @return void
*/
public function testMagicGetAndAddHelper() {
public function testAddHelper() {
$View = new View();
$View->addHelper('Html');
$View->addHelper('Html', ['foo' => 'bar']);
$this->assertInstanceOf('Cake\View\Helper\HtmlHelper', $View->Html);
$config = $View->Html->config();
$this->assertEquals('bar', $config['foo']);
}
/**
@@ -924,11 +928,17 @@ public function testMagicGetAndAddHelper() {
public function testLoadHelpers() {
$View = new View();
$View->helpers = array('Html', 'Form');
$View->helpers = ['Html' => ['foo' => 'bar'], 'Form' => ['foo' => 'baz']];
$View->loadHelpers();
$this->assertInstanceOf('Cake\View\Helper\HtmlHelper', $View->Html, 'Object type is wrong.');
$this->assertInstanceOf('Cake\View\Helper\FormHelper', $View->Form, 'Object type is wrong.');
$config = $View->Html->config();
$this->assertEquals('bar', $config['foo']);
$config = $View->Form->config();
$this->assertEquals('baz', $config['foo']);
}
/**

0 comments on commit 3efd9d1

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