@@ -331,6 +331,15 @@ class Mustache_Test_EngineTest extends Mustache_Test_FunctionalTestCase
|
||||
));
|
||||
}
|
||||
|
||||
public function testCompileFromMustacheSourceInstance()
|
||||
{
|
||||
$baseDir = realpath(dirname(__FILE__) . '/../../fixtures/templates');
|
||||
$mustache = new Mustache_Engine(array(
|
||||
'loader' => new Mustache_Loader_ProductionFilesystemLoader($baseDir),
|
||||
));
|
||||
$this->assertEquals('one contents', $mustache->render('one'));
|
||||
}
|
||||
|
||||
private function getLoggedMustache($level = Mustache_Logger::ERROR)
|
||||
{
|
||||
$name = tempnam(sys_get_temp_dir(), 'mustache-test');
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Mustache.php.
|
||||
*
|
||||
* (c) 2010-2015 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
*/
|
||||
class Mustache_Test_Loader_ProductionFilesystemLoaderTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
|
||||
$loader = new Mustache_Loader_ProductionFilesystemLoader($baseDir, array('extension' => '.ms'));
|
||||
$this->assertInstanceOf('Mustache_Source', $loader->load('alpha'));
|
||||
$this->assertEquals('alpha contents', $loader->load('alpha')->getSource());
|
||||
$this->assertInstanceOf('Mustache_Source', $loader->load('beta.ms'));
|
||||
$this->assertEquals('beta contents', $loader->load('beta.ms')->getSource());
|
||||
}
|
||||
|
||||
public function testTrailingSlashes()
|
||||
{
|
||||
$baseDir = dirname(__FILE__) . '/../../../fixtures/templates/';
|
||||
$loader = new Mustache_Loader_ProductionFilesystemLoader($baseDir);
|
||||
$this->assertEquals('one contents', $loader->load('one')->getSource());
|
||||
}
|
||||
|
||||
public function testConstructorWithProtocol()
|
||||
{
|
||||
$baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
|
||||
|
||||
$loader = new Mustache_Loader_ProductionFilesystemLoader('file://' . $baseDir, array('extension' => '.ms'));
|
||||
$this->assertEquals('alpha contents', $loader->load('alpha')->getSource());
|
||||
$this->assertEquals('beta contents', $loader->load('beta.ms')->getSource());
|
||||
}
|
||||
|
||||
public function testLoadTemplates()
|
||||
{
|
||||
$baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
|
||||
$loader = new Mustache_Loader_ProductionFilesystemLoader($baseDir);
|
||||
$this->assertEquals('one contents', $loader->load('one')->getSource());
|
||||
$this->assertEquals('two contents', $loader->load('two.mustache')->getSource());
|
||||
}
|
||||
|
||||
public function testEmptyExtensionString()
|
||||
{
|
||||
$baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
|
||||
|
||||
$loader = new Mustache_Loader_ProductionFilesystemLoader($baseDir, array('extension' => ''));
|
||||
$this->assertEquals('one contents', $loader->load('one.mustache')->getSource());
|
||||
$this->assertEquals('alpha contents', $loader->load('alpha.ms')->getSource());
|
||||
|
||||
$loader = new Mustache_Loader_ProductionFilesystemLoader($baseDir, array('extension' => null));
|
||||
$this->assertEquals('two contents', $loader->load('two.mustache')->getSource());
|
||||
$this->assertEquals('beta contents', $loader->load('beta.ms')->getSource());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Mustache_Exception_RuntimeException
|
||||
*/
|
||||
public function testMissingBaseDirThrowsException()
|
||||
{
|
||||
new Mustache_Loader_ProductionFilesystemLoader(dirname(__FILE__) . '/not_a_directory');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Mustache_Exception_UnknownTemplateException
|
||||
*/
|
||||
public function testMissingTemplateThrowsException()
|
||||
{
|
||||
$baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
|
||||
$loader = new Mustache_Loader_ProductionFilesystemLoader($baseDir);
|
||||
|
||||
$loader->load('fake');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user