Ejemplo n.º 1
0
 public function testHelpers()
 {
     $foo = array($this, 'getFoo');
     $bar = 'BAR';
     $mustache = new Mustache_Engine(array('helpers' => array('foo' => $foo, 'bar' => $bar)));
     $helpers = $mustache->getHelpers();
     $this->assertTrue($mustache->hasHelper('foo'));
     $this->assertTrue($mustache->hasHelper('bar'));
     $this->assertTrue($helpers->has('foo'));
     $this->assertTrue($helpers->has('bar'));
     $this->assertSame($foo, $mustache->getHelper('foo'));
     $this->assertSame($bar, $mustache->getHelper('bar'));
     $mustache->removeHelper('bar');
     $this->assertFalse($mustache->hasHelper('bar'));
     $mustache->addHelper('bar', $bar);
     $this->assertSame($bar, $mustache->getHelper('bar'));
     $baz = array($this, 'wrapWithUnderscores');
     $this->assertFalse($mustache->hasHelper('baz'));
     $this->assertFalse($helpers->has('baz'));
     $mustache->addHelper('baz', $baz);
     $this->assertTrue($mustache->hasHelper('baz'));
     $this->assertTrue($helpers->has('baz'));
     // ... and a functional test
     $tpl = $mustache->loadTemplate('{{foo}} - {{bar}} - {{#baz}}qux{{/baz}}');
     $this->assertEquals('foo - BAR - __qux__', $tpl->render());
     $this->assertEquals('foo - BAR - __qux__', $tpl->render(array('qux' => "won't mess things up")));
 }