LambdaHelperTest.php 962 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /*
  3. * This file is part of Mustache.php.
  4. *
  5. * (c) 2012 Justin Hileman
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * @group lambdas
  12. * @group functional
  13. */
  14. class Mustache_Test_FiveThree_Functional_LambdaHelperTest extends PHPUnit_Framework_TestCase
  15. {
  16. private $mustache;
  17. public function setUp()
  18. {
  19. $this->mustache = new Mustache_Engine;
  20. }
  21. public function testSectionLambdaHelper()
  22. {
  23. $one = $this->mustache->loadTemplate('{{name}}');
  24. $two = $this->mustache->loadTemplate('{{#lambda}}{{name}}{{/lambda}}');
  25. $foo = new StdClass;
  26. $foo->name = 'Mario';
  27. $foo->lambda = function($text, $mustache) {
  28. return strtoupper($mustache->render($text));
  29. };
  30. $this->assertEquals('Mario', $one->render($foo));
  31. $this->assertEquals('MARIO', $two->render($foo));
  32. }
  33. }