fix a bug with helpers and add a test for that

This commit is contained in:
fzerorubigd 2013-11-08 19:00:54 +03:30
parent 8938fdc5c3
commit 25190010e1
No known key found for this signature in database
GPG Key ID: D6EE858AF9D2999A
2 changed files with 15 additions and 2 deletions

View File

@ -47,7 +47,7 @@ class Helpers
* Create new helper container class * Create new helper container class
* *
* @param array $helpers array of name=>$value helpers * @param array $helpers array of name=>$value helpers
* @param array|bool $defaults add defaults helper (if, unless, each,with) * @param array|bool $defaults add defaults helper (if, unless, each,with, bindAttr)
* *
* @throws \InvalidArgumentException when $helpers is not an array * @throws \InvalidArgumentException when $helpers is not an array
* (or traversable) or helper is not a callable * (or traversable) or helper is not a callable
@ -64,7 +64,7 @@ class Helpers
); );
} }
foreach ($helpers as $name => $helper) { foreach ($helpers as $name => $helper) {
$this->add($name, $helpers); $this->add($name, $helper);
} }
} }
} }

View File

@ -113,4 +113,17 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
), ),
); );
} }
/**
* Management helpers
*/
public function testHelpersManagement()
{
$helpers = new \Handlebars\Helpers(array('test'=> function(){}), false);
$engine = new \Handlebars\Handlebars(['helpers' => $helpers]);
$this->assertTrue(is_callable($engine->getHelper('test')));
$this->assertTrue($engine->hasHelper('test'));
$engine->removeHelper('test');
$this->assertFalse($engine->hasHelper('test'));
}
} }