mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-05-03 18:43:07 +03:00
add more test
This commit is contained in:
parent
fa65e99dfe
commit
ff503a90a2
@ -77,16 +77,16 @@ class Autoloader
|
|||||||
*/
|
*/
|
||||||
public function autoload($class)
|
public function autoload($class)
|
||||||
{
|
{
|
||||||
if ($class[0] === '\\') {
|
if ($class[0] !== '\\') {
|
||||||
$class = substr($class, 1);
|
$class = '\\' . $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($class, 'Handlebars') !== 0) {
|
if (strpos($class, 'Handlebars') !== 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = sprintf(
|
$file = sprintf(
|
||||||
'%s/%s.php',
|
'%s%s.php',
|
||||||
$this->_baseDir,
|
$this->_baseDir,
|
||||||
str_replace('\\', '/', $class)
|
str_replace('\\', '/', $class)
|
||||||
);
|
);
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Handlebars\Loader;
|
namespace Handlebars\Loader;
|
||||||
|
|
||||||
use Handlebars\Loader;
|
use Handlebars\Loader;
|
||||||
use Handlebars\String;
|
use Handlebars\String;
|
||||||
|
|
||||||
@ -64,7 +65,8 @@ class FilesystemLoader implements Loader
|
|||||||
} else {
|
} else {
|
||||||
foreach ($baseDirs as &$dir) {
|
foreach ($baseDirs as &$dir) {
|
||||||
$dir = rtrim(realpath($dir), '/');
|
$dir = rtrim(realpath($dir), '/');
|
||||||
} unset( $dir );
|
}
|
||||||
|
unset($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_baseDir = $baseDirs;
|
$this->_baseDir = $baseDirs;
|
||||||
|
@ -19,6 +19,10 @@
|
|||||||
*/
|
*/
|
||||||
class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
\Handlebars\Autoloader::register();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Test handlebars autoloader
|
* Test handlebars autoloader
|
||||||
*
|
*
|
||||||
@ -29,7 +33,10 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
|||||||
Handlebars\Autoloader::register(realpath(__DIR__ . '/../fixture/'));
|
Handlebars\Autoloader::register(realpath(__DIR__ . '/../fixture/'));
|
||||||
|
|
||||||
$this->assertTrue(class_exists('Handlebars\\Test'));
|
$this->assertTrue(class_exists('Handlebars\\Test'));
|
||||||
|
$this->assertTrue(class_exists('\\Handlebars\\Test'));
|
||||||
$this->assertTrue(class_exists('Handlebars\\Example\\Test'));
|
$this->assertTrue(class_exists('Handlebars\\Example\\Test'));
|
||||||
|
$this->assertTrue(class_exists('\\Handlebars\\Example\\Test'));
|
||||||
|
$this->assertFalse(class_exists('\\Another\\Example\\Test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -326,6 +333,46 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
|||||||
$engine->setLoader($loader);
|
$engine->setLoader($loader);
|
||||||
$this->assertEquals('test', $engine->render('loader', array()));
|
$this->assertEquals('test', $engine->render('loader', array()));
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Test file system loader
|
||||||
|
*/
|
||||||
|
public function testFileSystemLoaderMultipleFolder()
|
||||||
|
{
|
||||||
|
$paths = array(
|
||||||
|
realpath(__DIR__ . '/../fixture/data'),
|
||||||
|
realpath(__DIR__ . '/../fixture/another')
|
||||||
|
);
|
||||||
|
|
||||||
|
$options = array(
|
||||||
|
'prefix' => '__',
|
||||||
|
'extension' => 'hb'
|
||||||
|
);
|
||||||
|
$loader = new \Handlebars\Loader\FilesystemLoader($paths, $options);
|
||||||
|
$engine = new \Handlebars\Handlebars();
|
||||||
|
$engine->setLoader($loader);
|
||||||
|
$this->assertEquals('test_extra', $engine->render('loader', array()));
|
||||||
|
$this->assertEquals('another_extra', $engine->render('another', array()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test file system loader
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testFileSystemLoaderNotFound()
|
||||||
|
{
|
||||||
|
$loader = new \Handlebars\Loader\FilesystemLoader(realpath(__DIR__ . '/../fixture/data'));
|
||||||
|
$engine = new \Handlebars\Handlebars();
|
||||||
|
$engine->setLoader($loader);
|
||||||
|
$engine->render('invalid_file', array());
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Test file system loader
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
*/
|
||||||
|
public function testFileSystemLoaderInvalidFolder()
|
||||||
|
{
|
||||||
|
new \Handlebars\Loader\FilesystemLoader(realpath(__DIR__ . '/../fixture/') . 'invalid/path');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test partial loader
|
* Test partial loader
|
||||||
|
@ -1,4 +1,2 @@
|
|||||||
<?php
|
<?php
|
||||||
include __DIR__ . "/../src/Handlebars/Autoloader.php";
|
include __DIR__ . "/../src/Handlebars/Autoloader.php";
|
||||||
$base = __DIR__ . "/../src";
|
|
||||||
$loader = \Handlebars\Autoloader::register();
|
|
1
tests/fixture/another/__another.hb
Normal file
1
tests/fixture/another/__another.hb
Normal file
@ -0,0 +1 @@
|
|||||||
|
another_extra
|
1
tests/fixture/another/another.handlebars
Normal file
1
tests/fixture/another/another.handlebars
Normal file
@ -0,0 +1 @@
|
|||||||
|
another
|
1
tests/fixture/data/__loader.hb
Normal file
1
tests/fixture/data/__loader.hb
Normal file
@ -0,0 +1 @@
|
|||||||
|
test_extra
|
Loading…
Reference in New Issue
Block a user