FilesystemLoaderTest.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /*
  3. * This file is part of Mustache.php.
  4. *
  5. * (c) 2010-2016 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 = dirname(__FILE__) . '/../../../fixtures/templates/';
  25. $loader = new Mustache_Loader_FilesystemLoader($baseDir);
  26. $this->assertEquals('one contents', $loader->load('one'));
  27. }
  28. public function testConstructorWithProtocol()
  29. {
  30. $baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
  31. $loader = new Mustache_Loader_FilesystemLoader('test://' . $baseDir, array('extension' => '.ms'));
  32. $this->assertEquals('alpha contents', $loader->load('alpha'));
  33. $this->assertEquals('beta contents', $loader->load('beta.ms'));
  34. }
  35. public function testLoadTemplates()
  36. {
  37. $baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
  38. $loader = new Mustache_Loader_FilesystemLoader($baseDir);
  39. $this->assertEquals('one contents', $loader->load('one'));
  40. $this->assertEquals('two contents', $loader->load('two.mustache'));
  41. }
  42. public function testEmptyExtensionString()
  43. {
  44. $baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
  45. $loader = new Mustache_Loader_FilesystemLoader($baseDir, array('extension' => ''));
  46. $this->assertEquals('one contents', $loader->load('one.mustache'));
  47. $this->assertEquals('alpha contents', $loader->load('alpha.ms'));
  48. $loader = new Mustache_Loader_FilesystemLoader($baseDir, array('extension' => null));
  49. $this->assertEquals('two contents', $loader->load('two.mustache'));
  50. $this->assertEquals('beta contents', $loader->load('beta.ms'));
  51. }
  52. /**
  53. * @expectedException Mustache_Exception_RuntimeException
  54. */
  55. public function testMissingBaseDirThrowsException()
  56. {
  57. new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/not_a_directory');
  58. }
  59. /**
  60. * @expectedException Mustache_Exception_UnknownTemplateException
  61. */
  62. public function testMissingTemplateThrowsException()
  63. {
  64. $baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
  65. $loader = new Mustache_Loader_FilesystemLoader($baseDir);
  66. $loader->load('fake');
  67. }
  68. }