FilesystemLoaderTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 testTrailingSlashes()
  23. {
  24. $baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates/');
  25. $loader = new Mustache_Loader_FilesystemLoader($baseDir);
  26. $this->assertEquals('one contents', $loader->load('one'));
  27. }
  28. public function testLoadTemplates()
  29. {
  30. $baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
  31. $loader = new Mustache_Loader_FilesystemLoader($baseDir);
  32. $this->assertEquals('one contents', $loader->load('one'));
  33. $this->assertEquals('two contents', $loader->load('two.mustache'));
  34. }
  35. public function testEmptyExtensionString()
  36. {
  37. $baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
  38. $loader = new Mustache_Loader_FilesystemLoader($baseDir, array('extension' => ''));
  39. $this->assertEquals('one contents', $loader->load('one.mustache'));
  40. $this->assertEquals('alpha contents', $loader->load('alpha.ms'));
  41. $loader = new Mustache_Loader_FilesystemLoader($baseDir, array('extension' => null));
  42. $this->assertEquals('two contents', $loader->load('two.mustache'));
  43. $this->assertEquals('beta contents', $loader->load('beta.ms'));
  44. }
  45. /**
  46. * @expectedException Mustache_Exception_RuntimeException
  47. */
  48. public function testMissingBaseDirThrowsException()
  49. {
  50. $loader = new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/not_a_directory');
  51. }
  52. /**
  53. * @expectedException Mustache_Exception_UnknownTemplateException
  54. */
  55. public function testMissingTemplateThrowsException()
  56. {
  57. $baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
  58. $loader = new Mustache_Loader_FilesystemLoader($baseDir);
  59. $loader->load('fake');
  60. }
  61. }