| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- /*
- * This file is part of Mustache.php.
- *
- * (c) 2010-2017 Justin Hileman
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- /**
- * @group lambdas
- * @group functional
- */
- class Mustache_Test_FiveThree_Functional_LambdaHelperTest extends PHPUnit_Framework_TestCase
- {
- private $mustache;
- public function setUp()
- {
- $this->mustache = new Mustache_Engine();
- }
- public function testSectionLambdaHelper()
- {
- $one = $this->mustache->loadTemplate('{{name}}');
- $two = $this->mustache->loadTemplate('{{#lambda}}{{name}}{{/lambda}}');
- $foo = new StdClass();
- $foo->name = 'Mario';
- $foo->lambda = function ($text, $mustache) {
- return strtoupper($mustache->render($text));
- };
- $this->assertEquals('Mario', $one->render($foo));
- $this->assertEquals('MARIO', $two->render($foo));
- }
- public function testSectionLambdaHelperRespectsDelimiterChanges()
- {
- $tpl = $this->mustache->loadTemplate("{{=<% %>=}}\n<%# bang %><% value %><%/ bang %>");
- $data = new StdClass();
- $data->value = 'hello world';
- $data->bang = function ($text, $mustache) {
- return $mustache->render($text) . '!';
- };
- $this->assertEquals('hello world!', $tpl->render($data));
- }
- public function testLambdaHelperIsInvokable()
- {
- $one = $this->mustache->loadTemplate('{{name}}');
- $two = $this->mustache->loadTemplate('{{#lambda}}{{name}}{{/lambda}}');
- $foo = new StdClass();
- $foo->name = 'Mario';
- $foo->lambda = function ($text, $render) {
- return strtoupper($render($text));
- };
- $this->assertEquals('Mario', $one->render($foo));
- $this->assertEquals('MARIO', $two->render($foo));
- }
- }
|