ProductionFilesystemLoaderTest.php 3.2 KB

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