Implement {{% FILTERS }} pragma.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user