Implement {{% FILTERS }} pragma.

This commit is contained in:
Justin Hileman
2012-10-01 14:51:14 -07:00
parent f73df2af68
commit d209d1aea9
3 changed files with 93 additions and 4 deletions
@@ -0,0 +1,53 @@
<?php
/*
* This file is part of Mustache.php.
*
* (c) 2012 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @group filters
* @group functional
*/
class Mustache_Test_FiveThree_Functional_FiltersTest extends PHPUnit_Framework_TestCase {
private $mustache;
public function setUp() {
$this->mustache = new Mustache_Engine;
}
public function testSingleFilter() {
$tpl = $this->mustache->loadTemplate('{{% FILTERS }}{{ date | longdate }}');
$this->mustache->addHelper('longdate', function(\DateTime $value) {
return $value->format('Y-m-d h:m:s');
});
$foo = new \StdClass;
$foo->date = new DateTime('1/1/2000');
$this->assertEquals('2000-01-01 12:01:00', $tpl->render($foo));
}
public function testChainedFilters() {
$tpl = $this->mustache->loadTemplate('{{% FILTERS }}{{ date | longdate | withbrackets }}');
$this->mustache->addHelper('longdate', function(\DateTime $value) {
return $value->format('Y-m-d h:m:s');
});
$this->mustache->addHelper('withbrackets', function($value) {
return sprintf('[[%s]]', $value);
});
$foo = new \StdClass;
$foo->date = new DateTime('1/1/2000');
$this->assertEquals('[[2000-01-01 12:01:00]]', $tpl->render($foo));
}
}