MustacheTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Framework\WebBundle\Util;
  11. use Symfony\Framework\WebBundle\Util\Mustache;
  12. use Symfony\Framework\WebBundle\Util\Filesystem;
  13. class MustacheTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected $dir;
  16. public function setUp()
  17. {
  18. $dir = __DIR__.'/../../../../../fixtures/Symfony/Framework/WebBundle/Util';
  19. $this->dir = sys_get_temp_dir().'/mustache';
  20. $filesystem = new Filesystem();
  21. $filesystem->mirror($dir, $this->dir);
  22. }
  23. public function tearDown()
  24. {
  25. $filesystem = new Filesystem();
  26. $filesystem->remove($this->dir);
  27. }
  28. public function testRenderString()
  29. {
  30. $template = 'Hi {{ you }}, my name is {{ me }}!';
  31. $expected = 'Hi {{ you }}, my name is Kris!';
  32. $this->assertEquals(Mustache::renderString($template, array('me' => 'Kris')), $expected, '::renderString() does not modify unknown parameters');
  33. }
  34. public function testRenderFile()
  35. {
  36. Mustache::renderFile($this->dir.'/template.txt', array('me' => 'Fabien'));
  37. $this->assertEquals('Hello Fabien', file_get_contents($this->dir.'/template.txt'), '::renderFile() renders a file');
  38. }
  39. public function testRenderDir()
  40. {
  41. Mustache::renderDir($this->dir, array('me' => 'Fabien'));
  42. $this->assertEquals('Hello Fabien', file_get_contents($this->dir.'/template.txt'), '::renderDir() renders a directory');
  43. $this->assertEquals('Hello Fabien', file_get_contents($this->dir.'/foo/bar.txt'), '::renderDir() renders a directory');
  44. }
  45. }