FilesystemLoaderTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 unit
  12. */
  13. class Mustache_Test_Loader_FilesystemLoaderTest extends PHPUnit_Framework_TestCase
  14. {
  15. public function testConstructor()
  16. {
  17. $baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
  18. $loader = new Mustache_Loader_FilesystemLoader($baseDir, array('extension' => '.ms'));
  19. $this->assertEquals('alpha contents', $loader->load('alpha'));
  20. $this->assertEquals('beta contents', $loader->load('beta.ms'));
  21. }
  22. public function testLoadTemplates()
  23. {
  24. $baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
  25. $loader = new Mustache_Loader_FilesystemLoader($baseDir);
  26. $this->assertEquals('one contents', $loader->load('one'));
  27. $this->assertEquals('two contents', $loader->load('two.mustache'));
  28. }
  29. /**
  30. * @expectedException RuntimeException
  31. */
  32. public function testMissingBaseDirThrowsException()
  33. {
  34. $loader = new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/not_a_directory');
  35. }
  36. /**
  37. * @expectedException InvalidArgumentException
  38. */
  39. public function testMissingTemplateThrowsException()
  40. {
  41. $baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
  42. $loader = new Mustache_Loader_FilesystemLoader($baseDir);
  43. $loader->load('fake');
  44. }
  45. }