Update to proposed PSR-1 coding standard.

* 4 space (no tab) indent
 * K&R-style braces
This commit is contained in:
Justin Hileman
2012-05-01 22:03:39 -07:00
parent be5cfb3e9e
commit 2448992cc8
57 changed files with 3283 additions and 3009 deletions
+17 -14
View File
@@ -12,22 +12,25 @@
/**
* @group unit
*/
class Mustache_Test_AutoloaderTest extends PHPUnit_Framework_TestCase {
public function testRegister() {
$loader = Mustache_Autoloader::register();
$this->assertTrue(spl_autoload_unregister(array($loader, 'autoload')));
}
class Mustache_Test_AutoloaderTest extends PHPUnit_Framework_TestCase
{
public function testRegister()
{
$loader = Mustache_Autoloader::register();
$this->assertTrue(spl_autoload_unregister(array($loader, 'autoload')));
}
public function testAutoloader() {
$loader = new Mustache_Autoloader(dirname(__FILE__).'/../../fixtures/autoloader');
public function testAutoloader()
{
$loader = new Mustache_Autoloader(dirname(__FILE__).'/../../fixtures/autoloader');
$this->assertNull($loader->autoload('NonMustacheClass'));
$this->assertFalse(class_exists('NonMustacheClass'));
$this->assertNull($loader->autoload('NonMustacheClass'));
$this->assertFalse(class_exists('NonMustacheClass'));
$loader->autoload('Mustache_Foo');
$this->assertTrue(class_exists('Mustache_Foo'));
$loader->autoload('Mustache_Foo');
$this->assertTrue(class_exists('Mustache_Foo'));
$loader->autoload('\Mustache_Bar');
$this->assertTrue(class_exists('Mustache_Bar'));
}
$loader->autoload('\Mustache_Bar');
$this->assertTrue(class_exists('Mustache_Bar'));
}
}
+80 -75
View File
@@ -12,87 +12,92 @@
/**
* @group unit
*/
class Mustache_Test_CompilerTest extends PHPUnit_Framework_TestCase {
class Mustache_Test_CompilerTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider getCompileValues
*/
public function testCompile($source, array $tree, $name, $customEscaper, $charset, $expected) {
$compiler = new Mustache_Compiler;
/**
* @dataProvider getCompileValues
*/
public function testCompile($source, array $tree, $name, $customEscaper, $charset, $expected)
{
$compiler = new Mustache_Compiler;
$compiled = $compiler->compile($source, $tree, $name, $customEscaper, $charset);
foreach ($expected as $contains) {
$this->assertContains($contains, $compiled);
}
}
$compiled = $compiler->compile($source, $tree, $name, $customEscaper, $charset);
foreach ($expected as $contains) {
$this->assertContains($contains, $compiled);
}
}
public function getCompileValues() {
return array(
array('', array(), 'Banana', false, 'ISO-8859-1', array(
"\nclass Banana extends Mustache_Template",
'return htmlspecialchars($buffer, ENT_COMPAT, \'ISO-8859-1\');',
'return $buffer;',
)),
public function getCompileValues()
{
return array(
array('', array(), 'Banana', false, 'ISO-8859-1', array(
"\nclass Banana extends Mustache_Template",
'return htmlspecialchars($buffer, ENT_COMPAT, \'ISO-8859-1\');',
'return $buffer;',
)),
array('', array($this->createTextToken('TEXT')), 'Monkey', false, 'UTF-8', array(
"\nclass Monkey extends Mustache_Template",
'return htmlspecialchars($buffer, ENT_COMPAT, \'UTF-8\');',
'$buffer .= $indent . \'TEXT\';',
'return $buffer;',
)),
array('', array($this->createTextToken('TEXT')), 'Monkey', false, 'UTF-8', array(
"\nclass Monkey extends Mustache_Template",
'return htmlspecialchars($buffer, ENT_COMPAT, \'UTF-8\');',
'$buffer .= $indent . \'TEXT\';',
'return $buffer;',
)),
array('', array($this->createTextToken('TEXT')), 'Monkey', true, 'ISO-8859-1', array(
"\nclass Monkey extends Mustache_Template",
'$buffer .= $indent . \'TEXT\';',
'return call_user_func($this->mustache->getEscape(), $buffer);',
'return $buffer;',
)),
array('', array($this->createTextToken('TEXT')), 'Monkey', true, 'ISO-8859-1', array(
"\nclass Monkey extends Mustache_Template",
'$buffer .= $indent . \'TEXT\';',
'return call_user_func($this->mustache->getEscape(), $buffer);',
'return $buffer;',
)),
array(
'',
array(
$this->createTextToken('foo'),
$this->createTextToken("\n"),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name',
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => '.',
),
$this->createTextToken("'bar'"),
),
'Monkey',
false,
'UTF-8',
array(
"\nclass Monkey extends Mustache_Template",
'$buffer .= $indent . \'foo\'',
'$buffer .= "\n"',
'$value = $context->find(\'name\');',
'$buffer .= htmlspecialchars($value, ENT_COMPAT, \'UTF-8\');',
'$value = $context->last();',
'$buffer .= \'\\\'bar\\\'\';',
'return htmlspecialchars($buffer, ENT_COMPAT, \'UTF-8\');',
'return $buffer;',
)
),
);
}
array(
'',
array(
$this->createTextToken('foo'),
$this->createTextToken("\n"),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name',
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => '.',
),
$this->createTextToken("'bar'"),
),
'Monkey',
false,
'UTF-8',
array(
"\nclass Monkey extends Mustache_Template",
'$buffer .= $indent . \'foo\'',
'$buffer .= "\n"',
'$value = $context->find(\'name\');',
'$buffer .= htmlspecialchars($value, ENT_COMPAT, \'UTF-8\');',
'$value = $context->last();',
'$buffer .= \'\\\'bar\\\'\';',
'return htmlspecialchars($buffer, ENT_COMPAT, \'UTF-8\');',
'return $buffer;',
)
),
);
}
/**
* @expectedException InvalidArgumentException
*/
public function testCompilerThrowsUnknownNodeTypeException() {
$compiler = new Mustache_Compiler;
$compiler->compile('', array(array(Mustache_Tokenizer::TYPE => 'invalid')), 'SomeClass');
}
/**
* @expectedException InvalidArgumentException
*/
public function testCompilerThrowsUnknownNodeTypeException()
{
$compiler = new Mustache_Compiler;
$compiler->compile('', array(array(Mustache_Tokenizer::TYPE => 'invalid')), 'SomeClass');
}
private function createTextToken($value) {
return array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => $value,
);
}
private function createTextToken($value)
{
return array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => $value,
);
}
}
+82 -74
View File
@@ -12,100 +12,108 @@
/**
* @group unit
*/
class Mustache_Test_ContextTest extends PHPUnit_Framework_TestCase {
public function testConstructor() {
$one = new Mustache_Context;
$this->assertSame('', $one->find('foo'));
$this->assertSame('', $one->find('bar'));
class Mustache_Test_ContextTest extends PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$one = new Mustache_Context;
$this->assertSame('', $one->find('foo'));
$this->assertSame('', $one->find('bar'));
$two = new Mustache_Context(array(
'foo' => 'FOO',
'bar' => '<BAR>'
));
$this->assertEquals('FOO', $two->find('foo'));
$this->assertEquals('<BAR>', $two->find('bar'));
$two = new Mustache_Context(array(
'foo' => 'FOO',
'bar' => '<BAR>'
));
$this->assertEquals('FOO', $two->find('foo'));
$this->assertEquals('<BAR>', $two->find('bar'));
$obj = new StdClass;
$obj->name = 'NAME';
$three = new Mustache_Context($obj);
$this->assertSame($obj, $three->last());
$this->assertEquals('NAME', $three->find('name'));
}
$obj = new StdClass;
$obj->name = 'NAME';
$three = new Mustache_Context($obj);
$this->assertSame($obj, $three->last());
$this->assertEquals('NAME', $three->find('name'));
}
public function testPushPopAndLast() {
$context = new Mustache_Context;
$this->assertFalse($context->last());
public function testPushPopAndLast()
{
$context = new Mustache_Context;
$this->assertFalse($context->last());
$dummy = new Mustache_Test_TestDummy;
$context->push($dummy);
$this->assertSame($dummy, $context->last());
$this->assertSame($dummy, $context->pop());
$this->assertFalse($context->last());
$dummy = new Mustache_Test_TestDummy;
$context->push($dummy);
$this->assertSame($dummy, $context->last());
$this->assertSame($dummy, $context->pop());
$this->assertFalse($context->last());
$obj = new StdClass;
$context->push($dummy);
$this->assertSame($dummy, $context->last());
$context->push($obj);
$this->assertSame($obj, $context->last());
$this->assertSame($obj, $context->pop());
$this->assertSame($dummy, $context->pop());
$this->assertFalse($context->last());
}
$obj = new StdClass;
$context->push($dummy);
$this->assertSame($dummy, $context->last());
$context->push($obj);
$this->assertSame($obj, $context->last());
$this->assertSame($obj, $context->pop());
$this->assertSame($dummy, $context->pop());
$this->assertFalse($context->last());
}
public function testFind() {
$context = new Mustache_Context;
public function testFind()
{
$context = new Mustache_Context;
$dummy = new Mustache_Test_TestDummy;
$dummy = new Mustache_Test_TestDummy;
$obj = new StdClass;
$obj->name = 'obj';
$obj = new StdClass;
$obj->name = 'obj';
$arr = array(
'a' => array('b' => array('c' => 'see')),
'b' => 'bee',
);
$arr = array(
'a' => array('b' => array('c' => 'see')),
'b' => 'bee',
);
$string = 'some arbitrary string';
$string = 'some arbitrary string';
$context->push($dummy);
$this->assertEquals('dummy', $context->find('name'));
$context->push($dummy);
$this->assertEquals('dummy', $context->find('name'));
$context->push($obj);
$this->assertEquals('obj', $context->find('name'));
$context->push($obj);
$this->assertEquals('obj', $context->find('name'));
$context->pop();
$this->assertEquals('dummy', $context->find('name'));
$context->pop();
$this->assertEquals('dummy', $context->find('name'));
$dummy->name = 'dummyer';
$this->assertEquals('dummyer', $context->find('name'));
$dummy->name = 'dummyer';
$this->assertEquals('dummyer', $context->find('name'));
$context->push($arr);
$this->assertEquals('bee', $context->find('b'));
$this->assertEquals('see', $context->findDot('a.b.c'));
$context->push($arr);
$this->assertEquals('bee', $context->find('b'));
$this->assertEquals('see', $context->findDot('a.b.c'));
$dummy->name = 'dummy';
$dummy->name = 'dummy';
$context->push($string);
$this->assertSame($string, $context->last());
$this->assertEquals('dummy', $context->find('name'));
$this->assertEquals('see', $context->findDot('a.b.c'));
$this->assertEquals('<foo>', $context->find('foo'));
$this->assertEquals('<bar>', $context->findDot('bar'));
}
$context->push($string);
$this->assertSame($string, $context->last());
$this->assertEquals('dummy', $context->find('name'));
$this->assertEquals('see', $context->findDot('a.b.c'));
$this->assertEquals('<foo>', $context->find('foo'));
$this->assertEquals('<bar>', $context->findDot('bar'));
}
}
class Mustache_Test_TestDummy {
public $name = 'dummy';
class Mustache_Test_TestDummy
{
public $name = 'dummy';
public function __invoke() {
// nothing
}
public function __invoke()
{
// nothing
}
public static function foo() {
return '<foo>';
}
public static function foo()
{
return '<foo>';
}
public function bar() {
return '<bar>';
}
public function bar()
{
return '<bar>';
}
}
+202 -186
View File
@@ -12,229 +12,245 @@
/**
* @group unit
*/
class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase {
class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase
{
private static $tempDir;
private static $tempDir;
public static function setUpBeforeClass() {
self::$tempDir = sys_get_temp_dir() . '/mustache_test';
if (file_exists(self::$tempDir)) {
self::rmdir(self::$tempDir);
}
}
public static function setUpBeforeClass()
{
self::$tempDir = sys_get_temp_dir() . '/mustache_test';
if (file_exists(self::$tempDir)) {
self::rmdir(self::$tempDir);
}
}
public function testConstructor() {
$loader = new Mustache_Loader_StringLoader;
$partialsLoader = new Mustache_Loader_ArrayLoader;
$mustache = new Mustache_Engine(array(
'template_class_prefix' => '__whot__',
'cache' => self::$tempDir,
'loader' => $loader,
'partials_loader' => $partialsLoader,
'partials' => array(
'foo' => '{{ foo }}',
),
'helpers' => array(
'foo' => array($this, 'getFoo'),
'bar' => 'BAR',
),
'escape' => 'strtoupper',
'charset' => 'ISO-8859-1',
));
public function testConstructor()
{
$loader = new Mustache_Loader_StringLoader;
$partialsLoader = new Mustache_Loader_ArrayLoader;
$mustache = new Mustache_Engine(array(
'template_class_prefix' => '__whot__',
'cache' => self::$tempDir,
'loader' => $loader,
'partials_loader' => $partialsLoader,
'partials' => array(
'foo' => '{{ foo }}',
),
'helpers' => array(
'foo' => array($this, 'getFoo'),
'bar' => 'BAR',
),
'escape' => 'strtoupper',
'charset' => 'ISO-8859-1',
));
$this->assertSame($loader, $mustache->getLoader());
$this->assertSame($partialsLoader, $mustache->getPartialsLoader());
$this->assertEquals('{{ foo }}', $partialsLoader->load('foo'));
$this->assertContains('__whot__', $mustache->getTemplateClassName('{{ foo }}'));
$this->assertEquals('strtoupper', $mustache->getEscape());
$this->assertEquals('ISO-8859-1', $mustache->getCharset());
$this->assertTrue($mustache->hasHelper('foo'));
$this->assertTrue($mustache->hasHelper('bar'));
$this->assertFalse($mustache->hasHelper('baz'));
}
$this->assertSame($loader, $mustache->getLoader());
$this->assertSame($partialsLoader, $mustache->getPartialsLoader());
$this->assertEquals('{{ foo }}', $partialsLoader->load('foo'));
$this->assertContains('__whot__', $mustache->getTemplateClassName('{{ foo }}'));
$this->assertEquals('strtoupper', $mustache->getEscape());
$this->assertEquals('ISO-8859-1', $mustache->getCharset());
$this->assertTrue($mustache->hasHelper('foo'));
$this->assertTrue($mustache->hasHelper('bar'));
$this->assertFalse($mustache->hasHelper('baz'));
}
public static function getFoo() {
return 'foo';
}
public static function getFoo()
{
return 'foo';
}
public function testRender() {
$source = '{{ foo }}';
$data = array('bar' => 'baz');
$output = 'TEH OUTPUT';
public function testRender()
{
$source = '{{ foo }}';
$data = array('bar' => 'baz');
$output = 'TEH OUTPUT';
$template = $this->getMockBuilder('Mustache_Template')
->disableOriginalConstructor()
->getMock();
$template = $this->getMockBuilder('Mustache_Template')
->disableOriginalConstructor()
->getMock();
$mustache = new MustacheStub;
$mustache->template = $template;
$mustache = new MustacheStub;
$mustache->template = $template;
$template->expects($this->once())
->method('render')
->with($data)
->will($this->returnValue($output));
$template->expects($this->once())
->method('render')
->with($data)
->will($this->returnValue($output));
$this->assertEquals($output, $mustache->render($source, $data));
$this->assertEquals($source, $mustache->source);
}
$this->assertEquals($output, $mustache->render($source, $data));
$this->assertEquals($source, $mustache->source);
}
public function testSettingServices() {
$loader = new Mustache_Loader_StringLoader;
$tokenizer = new Mustache_Tokenizer;
$parser = new Mustache_Parser;
$compiler = new Mustache_Compiler;
$mustache = new Mustache_Engine;
public function testSettingServices()
{
$loader = new Mustache_Loader_StringLoader;
$tokenizer = new Mustache_Tokenizer;
$parser = new Mustache_Parser;
$compiler = new Mustache_Compiler;
$mustache = new Mustache_Engine;
$this->assertNotSame($loader, $mustache->getLoader());
$mustache->setLoader($loader);
$this->assertSame($loader, $mustache->getLoader());
$this->assertNotSame($loader, $mustache->getLoader());
$mustache->setLoader($loader);
$this->assertSame($loader, $mustache->getLoader());
$this->assertNotSame($loader, $mustache->getPartialsLoader());
$mustache->setPartialsLoader($loader);
$this->assertSame($loader, $mustache->getPartialsLoader());
$this->assertNotSame($loader, $mustache->getPartialsLoader());
$mustache->setPartialsLoader($loader);
$this->assertSame($loader, $mustache->getPartialsLoader());
$this->assertNotSame($tokenizer, $mustache->getTokenizer());
$mustache->setTokenizer($tokenizer);
$this->assertSame($tokenizer, $mustache->getTokenizer());
$this->assertNotSame($tokenizer, $mustache->getTokenizer());
$mustache->setTokenizer($tokenizer);
$this->assertSame($tokenizer, $mustache->getTokenizer());
$this->assertNotSame($parser, $mustache->getParser());
$mustache->setParser($parser);
$this->assertSame($parser, $mustache->getParser());
$this->assertNotSame($parser, $mustache->getParser());
$mustache->setParser($parser);
$this->assertSame($parser, $mustache->getParser());
$this->assertNotSame($compiler, $mustache->getCompiler());
$mustache->setCompiler($compiler);
$this->assertSame($compiler, $mustache->getCompiler());
}
$this->assertNotSame($compiler, $mustache->getCompiler());
$mustache->setCompiler($compiler);
$this->assertSame($compiler, $mustache->getCompiler());
}
/**
* @group functional
*/
public function testCache() {
$mustache = new Mustache_Engine(array(
'template_class_prefix' => '__whot__',
'cache' => self::$tempDir,
));
/**
* @group functional
*/
public function testCache()
{
$mustache = new Mustache_Engine(array(
'template_class_prefix' => '__whot__',
'cache' => self::$tempDir,
));
$source = '{{ foo }}';
$template = $mustache->loadTemplate($source);
$className = $mustache->getTemplateClassName($source);
$fileName = self::$tempDir . '/' . $className . '.php';
$this->assertInstanceOf($className, $template);
$this->assertFileExists($fileName);
$this->assertContains("\nclass $className extends Mustache_Template", file_get_contents($fileName));
}
$source = '{{ foo }}';
$template = $mustache->loadTemplate($source);
$className = $mustache->getTemplateClassName($source);
$fileName = self::$tempDir . '/' . $className . '.php';
$this->assertInstanceOf($className, $template);
$this->assertFileExists($fileName);
$this->assertContains("\nclass $className extends Mustache_Template", file_get_contents($fileName));
}
/**
* @expectedException InvalidArgumentException
* @dataProvider getBadEscapers
*/
public function testNonCallableEscapeThrowsException($escape) {
new Mustache_Engine(array('escape' => $escape));
}
/**
* @expectedException InvalidArgumentException
* @dataProvider getBadEscapers
*/
public function testNonCallableEscapeThrowsException($escape)
{
new Mustache_Engine(array('escape' => $escape));
}
public function getBadEscapers() {
return array(
array('nothing'),
array('foo', 'bar'),
);
}
public function getBadEscapers()
{
return array(
array('nothing'),
array('foo', 'bar'),
);
}
/**
* @expectedException RuntimeException
*/
public function testImmutablePartialsLoadersThrowException() {
$mustache = new Mustache_Engine(array(
'partials_loader' => new Mustache_Loader_StringLoader,
));
/**
* @expectedException RuntimeException
*/
public function testImmutablePartialsLoadersThrowException()
{
$mustache = new Mustache_Engine(array(
'partials_loader' => new Mustache_Loader_StringLoader,
));
$mustache->setPartials(array('foo' => '{{ foo }}'));
}
$mustache->setPartials(array('foo' => '{{ foo }}'));
}
public function testMissingPartialsTreatedAsEmptyString() {
$mustache = new Mustache_Engine(array(
'partials_loader' => new Mustache_Loader_ArrayLoader(array(
'foo' => 'FOO',
'baz' => 'BAZ',
))
));
public function testMissingPartialsTreatedAsEmptyString()
{
$mustache = new Mustache_Engine(array(
'partials_loader' => new Mustache_Loader_ArrayLoader(array(
'foo' => 'FOO',
'baz' => 'BAZ',
))
));
$this->assertEquals('FOOBAZ', $mustache->render('{{>foo}}{{>bar}}{{>baz}}', array()));
}
$this->assertEquals('FOOBAZ', $mustache->render('{{>foo}}{{>bar}}{{>baz}}', array()));
}
public function testHelpers() {
$foo = array($this, 'getFoo');
$bar = 'BAR';
$mustache = new Mustache_Engine(array('helpers' => array(
'foo' => $foo,
'bar' => $bar,
)));
public function testHelpers()
{
$foo = array($this, 'getFoo');
$bar = 'BAR';
$mustache = new Mustache_Engine(array('helpers' => array(
'foo' => $foo,
'bar' => $bar,
)));
$helpers = $mustache->getHelpers();
$this->assertTrue($mustache->hasHelper('foo'));
$this->assertTrue($mustache->hasHelper('bar'));
$this->assertTrue($helpers->has('foo'));
$this->assertTrue($helpers->has('bar'));
$this->assertSame($foo, $mustache->getHelper('foo'));
$this->assertSame($bar, $mustache->getHelper('bar'));
$helpers = $mustache->getHelpers();
$this->assertTrue($mustache->hasHelper('foo'));
$this->assertTrue($mustache->hasHelper('bar'));
$this->assertTrue($helpers->has('foo'));
$this->assertTrue($helpers->has('bar'));
$this->assertSame($foo, $mustache->getHelper('foo'));
$this->assertSame($bar, $mustache->getHelper('bar'));
$mustache->removeHelper('bar');
$this->assertFalse($mustache->hasHelper('bar'));
$mustache->addHelper('bar', $bar);
$this->assertSame($bar, $mustache->getHelper('bar'));
$mustache->removeHelper('bar');
$this->assertFalse($mustache->hasHelper('bar'));
$mustache->addHelper('bar', $bar);
$this->assertSame($bar, $mustache->getHelper('bar'));
$baz = array($this, 'wrapWithUnderscores');
$this->assertFalse($mustache->hasHelper('baz'));
$this->assertFalse($helpers->has('baz'));
$baz = array($this, 'wrapWithUnderscores');
$this->assertFalse($mustache->hasHelper('baz'));
$this->assertFalse($helpers->has('baz'));
$mustache->addHelper('baz', $baz);
$this->assertTrue($mustache->hasHelper('baz'));
$this->assertTrue($helpers->has('baz'));
$mustache->addHelper('baz', $baz);
$this->assertTrue($mustache->hasHelper('baz'));
$this->assertTrue($helpers->has('baz'));
// ... and a functional test
$tpl = $mustache->loadTemplate('{{foo}} - {{bar}} - {{#baz}}qux{{/baz}}');
$this->assertEquals('foo - BAR - __qux__', $tpl->render());
$this->assertEquals('foo - BAR - __qux__', $tpl->render(array('qux' => "won't mess things up")));
}
// ... and a functional test
$tpl = $mustache->loadTemplate('{{foo}} - {{bar}} - {{#baz}}qux{{/baz}}');
$this->assertEquals('foo - BAR - __qux__', $tpl->render());
$this->assertEquals('foo - BAR - __qux__', $tpl->render(array('qux' => "won't mess things up")));
}
public static function wrapWithUnderscores($text) {
return '__'.$text.'__';
}
public static function wrapWithUnderscores($text)
{
return '__'.$text.'__';
}
/**
* @expectedException InvalidArgumentException
*/
public function testSetHelpersThrowsExceptions() {
$mustache = new Mustache_Engine;
$mustache->setHelpers('monkeymonkeymonkey');
}
/**
* @expectedException InvalidArgumentException
*/
public function testSetHelpersThrowsExceptions()
{
$mustache = new Mustache_Engine;
$mustache->setHelpers('monkeymonkeymonkey');
}
private static function rmdir($path) {
$path = rtrim($path, '/').'/';
$handle = opendir($path);
while (($file = readdir($handle)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
private static function rmdir($path)
{
$path = rtrim($path, '/').'/';
$handle = opendir($path);
while (($file = readdir($handle)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
$fullpath = $path.$file;
if (is_dir($fullpath)) {
self::rmdir($fullpath);
} else {
unlink($fullpath);
}
}
$fullpath = $path.$file;
if (is_dir($fullpath)) {
self::rmdir($fullpath);
} else {
unlink($fullpath);
}
}
closedir($handle);
rmdir($path);
}
closedir($handle);
rmdir($path);
}
}
class MustacheStub extends Mustache_Engine {
public $source;
public $template;
public function loadTemplate($source) {
$this->source = $source;
public $source;
public $template;
public function loadTemplate($source)
{
$this->source = $source;
return $this->template;
}
return $this->template;
}
}
+18 -14
View File
@@ -13,24 +13,28 @@
* @group magic_methods
* @group functional
*/
class Mustache_Test_Functional_CallTest extends PHPUnit_Framework_TestCase {
class Mustache_Test_Functional_CallTest extends PHPUnit_Framework_TestCase
{
public function testCallEatsContext() {
$m = new Mustache_Engine;
$tpl = $m->loadTemplate('{{# foo }}{{ label }}: {{ name }}{{/ foo }}');
public function testCallEatsContext()
{
$m = new Mustache_Engine;
$tpl = $m->loadTemplate('{{# foo }}{{ label }}: {{ name }}{{/ foo }}');
$foo = new Mustache_Test_Functional_ClassWithCall();
$foo->name = 'Bob';
$foo = new Mustache_Test_Functional_ClassWithCall();
$foo->name = 'Bob';
$data = array('label' => 'name', 'foo' => $foo);
$data = array('label' => 'name', 'foo' => $foo);
$this->assertEquals('name: Bob', $tpl->render($data));
}
$this->assertEquals('name: Bob', $tpl->render($data));
}
}
class Mustache_Test_Functional_ClassWithCall {
public $name;
public function __call($method, $args) {
return 'unknown value';
}
class Mustache_Test_Functional_ClassWithCall
{
public $name;
public function __call($method, $args)
{
return 'unknown value';
}
}
+110 -105
View File
@@ -13,125 +13,130 @@
* @group examples
* @group functional
*/
class Mustache_Test_Functional_ExamplesTest extends PHPUnit_Framework_TestCase {
class Mustache_Test_Functional_ExamplesTest extends PHPUnit_Framework_TestCase
{
/**
* Test everything in the `examples` directory.
*
* @dataProvider getExamples
*
* @param string $context
* @param string $source
* @param array $partials
* @param string $expected
*/
public function testExamples($context, $source, $partials, $expected) {
$mustache = new Mustache_Engine(array(
'partials' => $partials
));
$this->assertEquals($expected, $mustache->loadTemplate($source)->render($context));
}
/**
* Test everything in the `examples` directory.
*
* @dataProvider getExamples
*
* @param string $context
* @param string $source
* @param array $partials
* @param string $expected
*/
public function testExamples($context, $source, $partials, $expected)
{
$mustache = new Mustache_Engine(array(
'partials' => $partials
));
$this->assertEquals($expected, $mustache->loadTemplate($source)->render($context));
}
/**
* Data provider for testExamples method.
*
* Loads examples from the test fixtures directory.
*
* This examples directory should contain any number of subdirectories, each of which contains
* three files: one Mustache class (.php), one Mustache template (.mustache), and one output file
* (.txt). Optionally, the directory may contain a folder full of partials.
*
* @return array
*/
public function getExamples() {
$path = realpath(dirname(__FILE__).'/../../../fixtures/examples');
$examples = array();
/**
* Data provider for testExamples method.
*
* Loads examples from the test fixtures directory.
*
* This examples directory should contain any number of subdirectories, each of which contains
* three files: one Mustache class (.php), one Mustache template (.mustache), and one output file
* (.txt). Optionally, the directory may contain a folder full of partials.
*
* @return array
*/
public function getExamples()
{
$path = realpath(dirname(__FILE__).'/../../../fixtures/examples');
$examples = array();
$handle = opendir($path);
while (($file = readdir($handle)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
$handle = opendir($path);
while (($file = readdir($handle)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
$fullpath = $path.'/'.$file;
if (is_dir($fullpath)) {
$examples[$file] = $this->loadExample($fullpath);
}
}
closedir($handle);
$fullpath = $path.'/'.$file;
if (is_dir($fullpath)) {
$examples[$file] = $this->loadExample($fullpath);
}
}
closedir($handle);
return $examples;
}
return $examples;
}
/**
* Helper method to load an example given the full path.
*
* @param string $path
*
* @return array arguments for testExamples
*/
private function loadExample($path) {
$context = null;
$source = null;
$partials = array();
$expected = null;
/**
* Helper method to load an example given the full path.
*
* @param string $path
*
* @return array arguments for testExamples
*/
private function loadExample($path)
{
$context = null;
$source = null;
$partials = array();
$expected = null;
$handle = opendir($path);
while (($file = readdir($handle)) !== false) {
$fullpath = $path.'/'.$file;
$info = pathinfo($fullpath);
$handle = opendir($path);
while (($file = readdir($handle)) !== false) {
$fullpath = $path.'/'.$file;
$info = pathinfo($fullpath);
if (is_dir($fullpath) && $info['basename'] == 'partials') {
// load partials
$partials = $this->loadPartials($fullpath);
} elseif (is_file($fullpath)) {
// load other files
switch ($info['extension']) {
case 'php':
require_once($fullpath);
$context = new $info['filename'];
break;
if (is_dir($fullpath) && $info['basename'] == 'partials') {
// load partials
$partials = $this->loadPartials($fullpath);
} elseif (is_file($fullpath)) {
// load other files
switch ($info['extension']) {
case 'php':
require_once($fullpath);
$context = new $info['filename'];
break;
case 'mustache':
$source = file_get_contents($fullpath);
break;
case 'mustache':
$source = file_get_contents($fullpath);
break;
case 'txt':
$expected = file_get_contents($fullpath);
break;
}
}
}
closedir($handle);
case 'txt':
$expected = file_get_contents($fullpath);
break;
}
}
}
closedir($handle);
return array($context, $source, $partials, $expected);
}
return array($context, $source, $partials, $expected);
}
/**
* Helper method to load partials given an example directory.
*
* @param string $path
*
* @return array $partials
*/
private function loadPartials($path) {
$partials = array();
/**
* Helper method to load partials given an example directory.
*
* @param string $path
*
* @return array $partials
*/
private function loadPartials($path)
{
$partials = array();
$handle = opendir($path);
while (($file = readdir($handle)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
$handle = opendir($path);
while (($file = readdir($handle)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
$fullpath = $path.'/'.$file;
$info = pathinfo($fullpath);
$fullpath = $path.'/'.$file;
$info = pathinfo($fullpath);
if ($info['extension'] === 'mustache') {
$partials[$info['filename']] = file_get_contents($fullpath);
}
}
closedir($handle);
if ($info['extension'] === 'mustache') {
$partials[$info['filename']] = file_get_contents($fullpath);
}
}
closedir($handle);
return $partials;
}
return $partials;
}
}
@@ -13,82 +13,94 @@
* @group lambdas
* @group functional
*/
class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework_TestCase {
class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework_TestCase
{
private $mustache;
private $mustache;
public function setUp() {
$this->mustache = new Mustache_Engine;
}
public function setUp()
{
$this->mustache = new Mustache_Engine;
}
public function testRuntimeSectionCallback() {
$tpl = $this->mustache->loadTemplate('{{#doublewrap}}{{name}}{{/doublewrap}}');
public function testRuntimeSectionCallback()
{
$tpl = $this->mustache->loadTemplate('{{#doublewrap}}{{name}}{{/doublewrap}}');
$foo = new Mustache_Test_Functional_Foo;
$foo->doublewrap = array($foo, 'wrapWithBoth');
$foo = new Mustache_Test_Functional_Foo;
$foo->doublewrap = array($foo, 'wrapWithBoth');
$this->assertEquals(sprintf('<strong><em>%s</em></strong>', $foo->name), $tpl->render($foo));
}
$this->assertEquals(sprintf('<strong><em>%s</em></strong>', $foo->name), $tpl->render($foo));
}
public function testStaticSectionCallback() {
$tpl = $this->mustache->loadTemplate('{{#trimmer}} {{name}} {{/trimmer}}');
public function testStaticSectionCallback()
{
$tpl = $this->mustache->loadTemplate('{{#trimmer}} {{name}} {{/trimmer}}');
$foo = new Mustache_Test_Functional_Foo;
$foo->trimmer = array(get_class($foo), 'staticTrim');
$foo = new Mustache_Test_Functional_Foo;
$foo->trimmer = array(get_class($foo), 'staticTrim');
$this->assertEquals($foo->name, $tpl->render($foo));
}
$this->assertEquals($foo->name, $tpl->render($foo));
}
public function testViewArraySectionCallback() {
$tpl = $this->mustache->loadTemplate('{{#trim}} {{name}} {{/trim}}');
public function testViewArraySectionCallback()
{
$tpl = $this->mustache->loadTemplate('{{#trim}} {{name}} {{/trim}}');
$foo = new Mustache_Test_Functional_Foo;
$foo = new Mustache_Test_Functional_Foo;
$data = array(
'name' => 'Bob',
'trim' => array(get_class($foo), 'staticTrim'),
);
$data = array(
'name' => 'Bob',
'trim' => array(get_class($foo), 'staticTrim'),
);
$this->assertEquals($data['name'], $tpl->render($data));
}
$this->assertEquals($data['name'], $tpl->render($data));
}
public function testMonsters() {
$tpl = $this->mustache->loadTemplate('{{#title}}{{title}} {{/title}}{{name}}');
public function testMonsters()
{
$tpl = $this->mustache->loadTemplate('{{#title}}{{title}} {{/title}}{{name}}');
$frank = new Mustache_Test_Functional_Monster();
$frank->title = 'Dr.';
$frank->name = 'Frankenstein';
$this->assertEquals('Dr. Frankenstein', $tpl->render($frank));
$frank = new Mustache_Test_Functional_Monster();
$frank->title = 'Dr.';
$frank->name = 'Frankenstein';
$this->assertEquals('Dr. Frankenstein', $tpl->render($frank));
$dracula = new Mustache_Test_Functional_Monster();
$dracula->title = 'Count';
$dracula->name = 'Dracula';
$this->assertEquals('Count Dracula', $tpl->render($dracula));
}
$dracula = new Mustache_Test_Functional_Monster();
$dracula->title = 'Count';
$dracula->name = 'Dracula';
$this->assertEquals('Count Dracula', $tpl->render($dracula));
}
}
class Mustache_Test_Functional_Foo {
public $name = 'Justin';
public $lorem = 'Lorem ipsum dolor sit amet,';
class Mustache_Test_Functional_Foo
{
public $name = 'Justin';
public $lorem = 'Lorem ipsum dolor sit amet,';
public function wrapWithEm($text) {
return sprintf('<em>%s</em>', $text);
}
public function wrapWithEm($text)
{
return sprintf('<em>%s</em>', $text);
}
public function wrapWithStrong($text) {
return sprintf('<strong>%s</strong>', $text);
}
public function wrapWithStrong($text)
{
return sprintf('<strong>%s</strong>', $text);
}
public function wrapWithBoth($text) {
return self::wrapWithStrong(self::wrapWithEm($text));
}
public function wrapWithBoth($text)
{
return self::wrapWithStrong(self::wrapWithEm($text));
}
public static function staticTrim($text) {
return trim($text);
}
public static function staticTrim($text)
{
return trim($text);
}
}
class Mustache_Test_Functional_Monster {
public $title;
public $name;
class Mustache_Test_Functional_Monster
{
public $title;
public $name;
}
@@ -13,128 +13,140 @@
* @group mustache_injection
* @group functional
*/
class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_TestCase {
class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_TestCase
{
private $mustache;
private $mustache;
public function setUp() {
$this->mustache = new Mustache_Engine;
}
public function setUp()
{
$this->mustache = new Mustache_Engine;
}
// interpolation
// interpolation
public function testInterpolationInjection() {
$tpl = $this->mustache->loadTemplate('{{ a }}');
public function testInterpolationInjection()
{
$tpl = $this->mustache->loadTemplate('{{ a }}');
$data = array(
'a' => '{{ b }}',
'b' => 'FAIL'
);
$data = array(
'a' => '{{ b }}',
'b' => 'FAIL'
);
$this->assertEquals('{{ b }}', $tpl->render($data));
}
$this->assertEquals('{{ b }}', $tpl->render($data));
}
public function testUnescapedInterpolationInjection() {
$tpl = $this->mustache->loadTemplate('{{{ a }}}');
public function testUnescapedInterpolationInjection()
{
$tpl = $this->mustache->loadTemplate('{{{ a }}}');
$data = array(
'a' => '{{ b }}',
'b' => 'FAIL'
);
$data = array(
'a' => '{{ b }}',
'b' => 'FAIL'
);
$this->assertEquals('{{ b }}', $tpl->render($data));
}
$this->assertEquals('{{ b }}', $tpl->render($data));
}
// sections
// sections
public function testSectionInjection() {
$tpl = $this->mustache->loadTemplate('{{# a }}{{ b }}{{/ a }}');
public function testSectionInjection()
{
$tpl = $this->mustache->loadTemplate('{{# a }}{{ b }}{{/ a }}');
$data = array(
'a' => true,
'b' => '{{ c }}',
'c' => 'FAIL'
);
$data = array(
'a' => true,
'b' => '{{ c }}',
'c' => 'FAIL'
);
$this->assertEquals('{{ c }}', $tpl->render($data));
}
$this->assertEquals('{{ c }}', $tpl->render($data));
}
public function testUnescapedSectionInjection() {
$tpl = $this->mustache->loadTemplate('{{# a }}{{{ b }}}{{/ a }}');
public function testUnescapedSectionInjection()
{
$tpl = $this->mustache->loadTemplate('{{# a }}{{{ b }}}{{/ a }}');
$data = array(
'a' => true,
'b' => '{{ c }}',
'c' => 'FAIL'
);
$data = array(
'a' => true,
'b' => '{{ c }}',
'c' => 'FAIL'
);
$this->assertEquals('{{ c }}', $tpl->render($data));
}
$this->assertEquals('{{ c }}', $tpl->render($data));
}
// partials
// partials
public function testPartialInjection() {
$tpl = $this->mustache->loadTemplate('{{> partial }}');
$this->mustache->setPartials(array(
'partial' => '{{ a }}',
));
public function testPartialInjection()
{
$tpl = $this->mustache->loadTemplate('{{> partial }}');
$this->mustache->setPartials(array(
'partial' => '{{ a }}',
));
$data = array(
'a' => '{{ b }}',
'b' => 'FAIL'
);
$data = array(
'a' => '{{ b }}',
'b' => 'FAIL'
);
$this->assertEquals('{{ b }}', $tpl->render($data));
}
$this->assertEquals('{{ b }}', $tpl->render($data));
}
public function testPartialUnescapedInjection() {
$tpl = $this->mustache->loadTemplate('{{> partial }}');
$this->mustache->setPartials(array(
'partial' => '{{{ a }}}',
));
public function testPartialUnescapedInjection()
{
$tpl = $this->mustache->loadTemplate('{{> partial }}');
$this->mustache->setPartials(array(
'partial' => '{{{ a }}}',
));
$data = array(
'a' => '{{ b }}',
'b' => 'FAIL'
);
$data = array(
'a' => '{{ b }}',
'b' => 'FAIL'
);
$this->assertEquals('{{ b }}', $tpl->render($data));
}
$this->assertEquals('{{ b }}', $tpl->render($data));
}
// lambdas
// lambdas
public function testLambdaInterpolationInjection() {
$tpl = $this->mustache->loadTemplate('{{ a }}');
public function testLambdaInterpolationInjection()
{
$tpl = $this->mustache->loadTemplate('{{ a }}');
$data = array(
'a' => array($this, 'lambdaInterpolationCallback'),
'b' => '{{ c }}',
'c' => 'FAIL'
);
$data = array(
'a' => array($this, 'lambdaInterpolationCallback'),
'b' => '{{ c }}',
'c' => 'FAIL'
);
$this->assertEquals('{{ c }}', $tpl->render($data));
}
$this->assertEquals('{{ c }}', $tpl->render($data));
}
public static function lambdaInterpolationCallback() {
return '{{ b }}';
}
public static function lambdaInterpolationCallback()
{
return '{{ b }}';
}
public function testLambdaSectionInjection() {
$tpl = $this->mustache->loadTemplate('{{# a }}b{{/ a }}');
public function testLambdaSectionInjection()
{
$tpl = $this->mustache->loadTemplate('{{# a }}b{{/ a }}');
$data = array(
'a' => array($this, 'lambdaSectionCallback'),
'b' => '{{ c }}',
'c' => 'FAIL'
);
$data = array(
'a' => array($this, 'lambdaSectionCallback'),
'b' => '{{ c }}',
'c' => 'FAIL'
);
$this->assertEquals('{{ c }}', $tpl->render($data));
}
$this->assertEquals('{{ c }}', $tpl->render($data));
}
public static function lambdaSectionCallback($text) {
return '{{ ' . $text . ' }}';
}
public static function lambdaSectionCallback($text)
{
return '{{ ' . $text . ' }}';
}
}
+134 -117
View File
@@ -15,144 +15,161 @@
* @group mustache-spec
* @group functional
*/
class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCase {
class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCase
{
private static $mustache;
private static $mustache;
public static function setUpBeforeClass() {
self::$mustache = new Mustache_Engine;
}
public static function setUpBeforeClass()
{
self::$mustache = new Mustache_Engine;
}
/**
* For some reason data providers can't mark tests skipped, so this test exists
* simply to provide a 'skipped' test if the `spec` submodule isn't initialized.
*/
public function testSpecInitialized() {
if (!file_exists(dirname(__FILE__).'/../../../../vendor/spec/specs/')) {
$this->markTestSkipped('Mustache spec submodule not initialized: run "git submodule update --init"');
}
}
/**
* For some reason data providers can't mark tests skipped, so this test exists
* simply to provide a 'skipped' test if the `spec` submodule isn't initialized.
*/
public function testSpecInitialized()
{
if (!file_exists(dirname(__FILE__).'/../../../../vendor/spec/specs/')) {
$this->markTestSkipped('Mustache spec submodule not initialized: run "git submodule update --init"');
}
}
/**
* @group comments
* @dataProvider loadCommentSpec
*/
public function testCommentSpec($desc, $source, $partials, $data, $expected) {
$template = self::loadTemplate($source, $partials);
$this->assertEquals($expected, $template->render($data), $desc);
}
/**
* @group comments
* @dataProvider loadCommentSpec
*/
public function testCommentSpec($desc, $source, $partials, $data, $expected)
{
$template = self::loadTemplate($source, $partials);
$this->assertEquals($expected, $template->render($data), $desc);
}
public function loadCommentSpec() {
return $this->loadSpec('comments');
}
public function loadCommentSpec()
{
return $this->loadSpec('comments');
}
/**
* @group delimiters
* @dataProvider loadDelimitersSpec
*/
public function testDelimitersSpec($desc, $source, $partials, $data, $expected) {
$template = self::loadTemplate($source, $partials);
$this->assertEquals($expected, $template->render($data), $desc);
}
/**
* @group delimiters
* @dataProvider loadDelimitersSpec
*/
public function testDelimitersSpec($desc, $source, $partials, $data, $expected)
{
$template = self::loadTemplate($source, $partials);
$this->assertEquals($expected, $template->render($data), $desc);
}
public function loadDelimitersSpec() {
return $this->loadSpec('delimiters');
}
public function loadDelimitersSpec()
{
return $this->loadSpec('delimiters');
}
/**
* @group interpolation
* @dataProvider loadInterpolationSpec
*/
public function testInterpolationSpec($desc, $source, $partials, $data, $expected) {
$template = self::loadTemplate($source, $partials);
$this->assertEquals($expected, $template->render($data), $desc);
}
/**
* @group interpolation
* @dataProvider loadInterpolationSpec
*/
public function testInterpolationSpec($desc, $source, $partials, $data, $expected)
{
$template = self::loadTemplate($source, $partials);
$this->assertEquals($expected, $template->render($data), $desc);
}
public function loadInterpolationSpec() {
return $this->loadSpec('interpolation');
}
public function loadInterpolationSpec()
{
return $this->loadSpec('interpolation');
}
/**
* @group inverted
* @group inverted-sections
* @dataProvider loadInvertedSpec
*/
public function testInvertedSpec($desc, $source, $partials, $data, $expected) {
$template = self::loadTemplate($source, $partials);
$this->assertEquals($expected, $template->render($data), $desc);
}
/**
* @group inverted
* @group inverted-sections
* @dataProvider loadInvertedSpec
*/
public function testInvertedSpec($desc, $source, $partials, $data, $expected)
{
$template = self::loadTemplate($source, $partials);
$this->assertEquals($expected, $template->render($data), $desc);
}
public function loadInvertedSpec() {
return $this->loadSpec('inverted');
}
public function loadInvertedSpec()
{
return $this->loadSpec('inverted');
}
/**
* @group partials
* @dataProvider loadPartialsSpec
*/
public function testPartialsSpec($desc, $source, $partials, $data, $expected) {
$template = self::loadTemplate($source, $partials);
$this->assertEquals($expected, $template->render($data), $desc);
}
/**
* @group partials
* @dataProvider loadPartialsSpec
*/
public function testPartialsSpec($desc, $source, $partials, $data, $expected)
{
$template = self::loadTemplate($source, $partials);
$this->assertEquals($expected, $template->render($data), $desc);
}
public function loadPartialsSpec() {
return $this->loadSpec('partials');
}
public function loadPartialsSpec()
{
return $this->loadSpec('partials');
}
/**
* @group sections
* @dataProvider loadSectionsSpec
*/
public function testSectionsSpec($desc, $source, $partials, $data, $expected) {
$template = self::loadTemplate($source, $partials);
$this->assertEquals($expected, $template->render($data), $desc);
}
/**
* @group sections
* @dataProvider loadSectionsSpec
*/
public function testSectionsSpec($desc, $source, $partials, $data, $expected)
{
$template = self::loadTemplate($source, $partials);
$this->assertEquals($expected, $template->render($data), $desc);
}
public function loadSectionsSpec() {
return $this->loadSpec('sections');
}
public function loadSectionsSpec()
{
return $this->loadSpec('sections');
}
/**
* Data provider for the mustache spec test.
*
* Loads YAML files from the spec and converts them to PHPisms.
*
* @access public
* @return array
*/
private function loadSpec($name) {
$filename = dirname(__FILE__) . '/../../../../vendor/spec/specs/' . $name . '.yml';
if (!file_exists($filename)) {
return array();
}
/**
* Data provider for the mustache spec test.
*
* Loads YAML files from the spec and converts them to PHPisms.
*
* @access public
* @return array
*/
private function loadSpec($name)
{
$filename = dirname(__FILE__) . '/../../../../vendor/spec/specs/' . $name . '.yml';
if (!file_exists($filename)) {
return array();
}
$data = array();
$yaml = new sfYamlParser;
$file = file_get_contents($filename);
$data = array();
$yaml = new sfYamlParser;
$file = file_get_contents($filename);
// @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain.
if ($name === '~lambdas') {
$file = str_replace(" !code\n", "\n", $file);
}
// @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain.
if ($name === '~lambdas') {
$file = str_replace(" !code\n", "\n", $file);
}
$spec = $yaml->parse($file);
$spec = $yaml->parse($file);
foreach ($spec['tests'] as $test) {
$data[] = array(
$test['name'] . ': ' . $test['desc'],
$test['template'],
isset($test['partials']) ? $test['partials'] : array(),
$test['data'],
$test['expected'],
);
}
foreach ($spec['tests'] as $test) {
$data[] = array(
$test['name'] . ': ' . $test['desc'],
$test['template'],
isset($test['partials']) ? $test['partials'] : array(),
$test['data'],
$test['expected'],
);
}
return $data;
}
return $data;
}
private static function loadTemplate($source, $partials) {
self::$mustache->setPartials($partials);
private static function loadTemplate($source, $partials)
{
self::$mustache->setPartials($partials);
return self::$mustache->loadTemplate($source);
}
return self::$mustache->loadTemplate($source);
}
}
@@ -13,82 +13,98 @@
* @group sections
* @group functional
*/
class Mustache_Test_Functional_ObjectSectionTest extends PHPUnit_Framework_TestCase {
private $mustache;
class Mustache_Test_Functional_ObjectSectionTest extends PHPUnit_Framework_TestCase
{
private $mustache;
public function setUp() {
$this->mustache = new Mustache_Engine;
}
public function setUp()
{
$this->mustache = new Mustache_Engine;
}
public function testBasicObject() {
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Alpha));
}
public function testBasicObject()
{
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Alpha));
}
/**
* @group magic_methods
*/
public function testObjectWithGet() {
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Beta));
}
/**
* @group magic_methods
*/
public function testObjectWithGet()
{
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Beta));
}
/**
* @group magic_methods
*/
public function testSectionObjectWithGet() {
$tpl = $this->mustache->loadTemplate('{{#bar}}{{#foo}}{{name}}{{/foo}}{{/bar}}');
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Gamma));
}
/**
* @group magic_methods
*/
public function testSectionObjectWithGet()
{
$tpl = $this->mustache->loadTemplate('{{#bar}}{{#foo}}{{name}}{{/foo}}{{/bar}}');
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Gamma));
}
public function testSectionObjectWithFunction() {
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
$alpha = new Mustache_Test_Functional_Alpha;
$alpha->foo = new Mustache_Test_Functional_Delta;
$this->assertEquals('Foo', $tpl->render($alpha));
}
public function testSectionObjectWithFunction()
{
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
$alpha = new Mustache_Test_Functional_Alpha;
$alpha->foo = new Mustache_Test_Functional_Delta;
$this->assertEquals('Foo', $tpl->render($alpha));
}
}
class Mustache_Test_Functional_Alpha {
public $foo;
class Mustache_Test_Functional_Alpha
{
public $foo;
public function __construct() {
$this->foo = new StdClass();
$this->foo->name = 'Foo';
$this->foo->number = 1;
}
public function __construct()
{
$this->foo = new StdClass();
$this->foo->name = 'Foo';
$this->foo->number = 1;
}
}
class Mustache_Test_Functional_Beta {
protected $_data = array();
class Mustache_Test_Functional_Beta
{
protected $_data = array();
public function __construct() {
$this->_data['foo'] = new StdClass();
$this->_data['foo']->name = 'Foo';
$this->_data['foo']->number = 1;
}
public function __construct()
{
$this->_data['foo'] = new StdClass();
$this->_data['foo']->name = 'Foo';
$this->_data['foo']->number = 1;
}
public function __isset($name) {
return array_key_exists($name, $this->_data);
}
public function __isset($name)
{
return array_key_exists($name, $this->_data);
}
public function __get($name) {
return $this->_data[$name];
}
public function __get($name)
{
return $this->_data[$name];
}
}
class Mustache_Test_Functional_Gamma {
public $bar;
class Mustache_Test_Functional_Gamma
{
public $bar;
public function __construct() {
$this->bar = new Mustache_Test_Functional_Beta;
}
public function __construct()
{
$this->bar = new Mustache_Test_Functional_Beta;
}
}
class Mustache_Test_Functional_Delta {
protected $_name = 'Foo';
class Mustache_Test_Functional_Delta
{
protected $_name = 'Foo';
public function name() {
return $this->_name;
}
public function name()
{
return $this->_name;
}
}
+25 -18
View File
@@ -9,27 +9,31 @@
* file that was distributed with this source code.
*/
class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
public function testConstructor() {
$foo = array($this, 'getFoo');
$bar = 'BAR';
class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$foo = array($this, 'getFoo');
$bar = 'BAR';
$helpers = new Mustache_HelperCollection(array(
'foo' => $foo,
'bar' => $bar,
));
$helpers = new Mustache_HelperCollection(array(
'foo' => $foo,
'bar' => $bar,
));
$this->assertSame($foo, $helpers->get('foo'));
$this->assertSame($bar, $helpers->get('bar'));
}
$this->assertSame($foo, $helpers->get('foo'));
$this->assertSame($bar, $helpers->get('bar'));
}
public static function getFoo() {
public static function getFoo()
{
echo 'foo';
}
public function testAccessorsAndMutators() {
$foo = array($this, 'getFoo');
$bar = 'BAR';
public function testAccessorsAndMutators()
{
$foo = array($this, 'getFoo');
$bar = 'BAR';
$helpers = new Mustache_HelperCollection;
$this->assertTrue($helpers->isEmpty());
@@ -52,7 +56,8 @@ class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
$this->assertTrue($helpers->has('bar'));
}
public function testMagicMethods() {
public function testMagicMethods()
{
$foo = array($this, 'getFoo');
$bar = 'BAR';
@@ -88,7 +93,8 @@ class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
/**
* @dataProvider getInvalidHelperArguments
*/
public function testHelperCollectionIsntAfraidToThrowExceptions($helpers = array(), $actions = array(), $exception = null) {
public function testHelperCollectionIsntAfraidToThrowExceptions($helpers = array(), $actions = array(), $exception = null)
{
if ($exception) {
$this->setExpectedException($exception);
}
@@ -100,7 +106,8 @@ class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
}
}
public function getInvalidHelperArguments() {
public function getInvalidHelperArguments()
{
return array(
array(
'not helpers',
+32 -28
View File
@@ -12,37 +12,41 @@
/**
* @group unit
*/
class Mustache_Test_Loader_ArrayLoaderTest extends PHPUnit_Framework_TestCase {
public function testConstructor() {
$loader = new Mustache_Loader_ArrayLoader(array(
'foo' => 'bar'
));
class Mustache_Test_Loader_ArrayLoaderTest extends PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$loader = new Mustache_Loader_ArrayLoader(array(
'foo' => 'bar'
));
$this->assertEquals('bar', $loader->load('foo'));
}
$this->assertEquals('bar', $loader->load('foo'));
}
public function testSetAndLoadTemplates() {
$loader = new Mustache_Loader_ArrayLoader(array(
'foo' => 'bar'
));
$this->assertEquals('bar', $loader->load('foo'));
public function testSetAndLoadTemplates()
{
$loader = new Mustache_Loader_ArrayLoader(array(
'foo' => 'bar'
));
$this->assertEquals('bar', $loader->load('foo'));
$loader->setTemplate('baz', 'qux');
$this->assertEquals('qux', $loader->load('baz'));
$loader->setTemplate('baz', 'qux');
$this->assertEquals('qux', $loader->load('baz'));
$loader->setTemplates(array(
'foo' => 'FOO',
'baz' => 'BAZ',
));
$this->assertEquals('FOO', $loader->load('foo'));
$this->assertEquals('BAZ', $loader->load('baz'));
}
$loader->setTemplates(array(
'foo' => 'FOO',
'baz' => 'BAZ',
));
$this->assertEquals('FOO', $loader->load('foo'));
$this->assertEquals('BAZ', $loader->load('baz'));
}
/**
* @expectedException InvalidArgumentException
*/
public function testMissingTemplatesThrowExceptions() {
$loader = new Mustache_Loader_ArrayLoader;
$loader->load('not_a_real_template');
}
/**
* @expectedException InvalidArgumentException
*/
public function testMissingTemplatesThrowExceptions()
{
$loader = new Mustache_Loader_ArrayLoader;
$loader->load('not_a_real_template');
}
}
@@ -12,35 +12,40 @@
/**
* @group unit
*/
class Mustache_Test_Loader_FilesystemLoaderTest extends PHPUnit_Framework_TestCase {
public function testConstructor() {
$baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
$loader = new Mustache_Loader_FilesystemLoader($baseDir, array('extension' => '.ms'));
$this->assertEquals('alpha contents', $loader->load('alpha'));
$this->assertEquals('beta contents', $loader->load('beta.ms'));
}
class Mustache_Test_Loader_FilesystemLoaderTest extends PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
$loader = new Mustache_Loader_FilesystemLoader($baseDir, array('extension' => '.ms'));
$this->assertEquals('alpha contents', $loader->load('alpha'));
$this->assertEquals('beta contents', $loader->load('beta.ms'));
}
public function testLoadTemplates() {
$baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
$loader = new Mustache_Loader_FilesystemLoader($baseDir);
$this->assertEquals('one contents', $loader->load('one'));
$this->assertEquals('two contents', $loader->load('two.mustache'));
}
public function testLoadTemplates()
{
$baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
$loader = new Mustache_Loader_FilesystemLoader($baseDir);
$this->assertEquals('one contents', $loader->load('one'));
$this->assertEquals('two contents', $loader->load('two.mustache'));
}
/**
* @expectedException RuntimeException
*/
public function testMissingBaseDirThrowsException() {
$loader = new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/not_a_directory');
}
/**
* @expectedException RuntimeException
*/
public function testMissingBaseDirThrowsException()
{
$loader = new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/not_a_directory');
}
/**
* @expectedException InvalidArgumentException
*/
public function testMissingTemplateThrowsException() {
$baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
$loader = new Mustache_Loader_FilesystemLoader($baseDir);
/**
* @expectedException InvalidArgumentException
*/
public function testMissingTemplateThrowsException()
{
$baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
$loader = new Mustache_Loader_FilesystemLoader($baseDir);
$loader->load('fake');
}
$loader->load('fake');
}
}
@@ -12,12 +12,14 @@
/**
* @group unit
*/
class Mustache_Test_Loader_StringLoaderTest extends PHPUnit_Framework_TestCase {
public function testLoadTemplates() {
$loader = new Mustache_Loader_StringLoader;
class Mustache_Test_Loader_StringLoaderTest extends PHPUnit_Framework_TestCase
{
public function testLoadTemplates()
{
$loader = new Mustache_Loader_StringLoader;
$this->assertEquals('foo', $loader->load('foo'));
$this->assertEquals('{{ bar }}', $loader->load('{{ bar }}'));
$this->assertEquals("\n{{! comment }}\n", $loader->load("\n{{! comment }}\n"));
}
$this->assertEquals('foo', $loader->load('foo'));
$this->assertEquals('{{ bar }}', $loader->load('{{ bar }}'));
$this->assertEquals("\n{{! comment }}\n", $loader->load("\n{{! comment }}\n"));
}
}
+156 -153
View File
@@ -12,168 +12,171 @@
/**
* @group unit
*/
class Mustache_Test_ParserTest extends PHPUnit_Framework_TestCase {
class Mustache_Test_ParserTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider getTokenSets
*/
public function testParse($tokens, $expected)
{
$parser = new Mustache_Parser;
$this->assertEquals($expected, $parser->parse($tokens));
}
/**
* @dataProvider getTokenSets
*/
public function testParse($tokens, $expected)
{
$parser = new Mustache_Parser;
$this->assertEquals($expected, $parser->parse($tokens));
}
public function getTokenSets()
{
return array(
array(
array(),
array()
),
public function getTokenSets()
{
return array(
array(
array(),
array()
),
array(
array(array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'text'
)),
array(array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'text'
)),
),
array(
array(array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'text'
)),
array(array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'text'
)),
),
array(
array(array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name'
)),
array(array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name'
)),
),
array(
array(array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name'
)),
array(array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name'
)),
),
array(
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'foo'
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_INVERTED,
Mustache_Tokenizer::INDEX => 123,
Mustache_Tokenizer::NAME => 'parent'
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name'
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
Mustache_Tokenizer::INDEX => 456,
Mustache_Tokenizer::NAME => 'parent'
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'bar'
),
),
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'foo'
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_INVERTED,
Mustache_Tokenizer::NAME => 'parent',
Mustache_Tokenizer::INDEX => 123,
Mustache_Tokenizer::END => 456,
Mustache_Tokenizer::NODES => array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name'
),
),
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'bar'
),
),
),
array(
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'foo'
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_INVERTED,
Mustache_Tokenizer::INDEX => 123,
Mustache_Tokenizer::NAME => 'parent'
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name'
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
Mustache_Tokenizer::INDEX => 456,
Mustache_Tokenizer::NAME => 'parent'
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'bar'
),
),
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'foo'
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_INVERTED,
Mustache_Tokenizer::NAME => 'parent',
Mustache_Tokenizer::INDEX => 123,
Mustache_Tokenizer::END => 456,
Mustache_Tokenizer::NODES => array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name'
),
),
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'bar'
),
),
),
);
}
);
}
/**
* @dataProvider getBadParseTrees
* @expectedException LogicException
*/
public function testParserThrowsExceptions($tokens) {
$parser = new Mustache_Parser;
$parser->parse($tokens);
}
/**
* @dataProvider getBadParseTrees
* @expectedException LogicException
*/
public function testParserThrowsExceptions($tokens)
{
$parser = new Mustache_Parser;
$parser->parse($tokens);
}
public function getBadParseTrees() {
return array(
// no close
array(
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_SECTION,
Mustache_Tokenizer::NAME => 'parent',
Mustache_Tokenizer::INDEX => 123,
),
),
),
public function getBadParseTrees()
{
return array(
// no close
array(
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_SECTION,
Mustache_Tokenizer::NAME => 'parent',
Mustache_Tokenizer::INDEX => 123,
),
),
),
// no close inverted
array(
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_INVERTED,
Mustache_Tokenizer::NAME => 'parent',
Mustache_Tokenizer::INDEX => 123,
),
),
),
// no close inverted
array(
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_INVERTED,
Mustache_Tokenizer::NAME => 'parent',
Mustache_Tokenizer::INDEX => 123,
),
),
),
// no opening inverted
array(
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
Mustache_Tokenizer::NAME => 'parent',
Mustache_Tokenizer::INDEX => 123,
),
),
),
// no opening inverted
array(
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
Mustache_Tokenizer::NAME => 'parent',
Mustache_Tokenizer::INDEX => 123,
),
),
),
// weird nesting
array(
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_SECTION,
Mustache_Tokenizer::NAME => 'parent',
Mustache_Tokenizer::INDEX => 123,
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_SECTION,
Mustache_Tokenizer::NAME => 'child',
Mustache_Tokenizer::INDEX => 123,
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
Mustache_Tokenizer::NAME => 'parent',
Mustache_Tokenizer::INDEX => 123,
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
Mustache_Tokenizer::NAME => 'child',
Mustache_Tokenizer::INDEX => 123,
),
),
),
);
}
// weird nesting
array(
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_SECTION,
Mustache_Tokenizer::NAME => 'parent',
Mustache_Tokenizer::INDEX => 123,
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_SECTION,
Mustache_Tokenizer::NAME => 'child',
Mustache_Tokenizer::INDEX => 123,
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
Mustache_Tokenizer::NAME => 'parent',
Mustache_Tokenizer::INDEX => 123,
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
Mustache_Tokenizer::NAME => 'child',
Mustache_Tokenizer::INDEX => 123,
),
),
),
);
}
}
+33 -27
View File
@@ -12,38 +12,44 @@
/**
* @group unit
*/
class Mustache_Test_TemplateTest extends PHPUnit_Framework_TestCase {
public function testConstructor() {
$mustache = new Mustache_Engine;
$template = new Mustache_Test_TemplateStub($mustache);
$this->assertSame($mustache, $template->getMustache());
}
class Mustache_Test_TemplateTest extends PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$mustache = new Mustache_Engine;
$template = new Mustache_Test_TemplateStub($mustache);
$this->assertSame($mustache, $template->getMustache());
}
public function testRendering() {
$rendered = '<< wheee >>';
$mustache = new Mustache_Engine;
$template = new Mustache_Test_TemplateStub($mustache);
$template->rendered = $rendered;
$context = new Mustache_Context;
public function testRendering()
{
$rendered = '<< wheee >>';
$mustache = new Mustache_Engine;
$template = new Mustache_Test_TemplateStub($mustache);
$template->rendered = $rendered;
$context = new Mustache_Context;
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
$this->assertEquals($rendered, $template());
}
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
$this->assertEquals($rendered, $template());
}
$this->assertEquals($rendered, $template->render());
$this->assertEquals($rendered, $template->renderInternal($context));
$this->assertEquals($rendered, $template->render(array('foo' => 'bar')));
}
$this->assertEquals($rendered, $template->render());
$this->assertEquals($rendered, $template->renderInternal($context));
$this->assertEquals($rendered, $template->render(array('foo' => 'bar')));
}
}
class Mustache_Test_TemplateStub extends Mustache_Template {
public $rendered;
class Mustache_Test_TemplateStub extends Mustache_Template
{
public $rendered;
public function getMustache() {
return $this->mustache;
}
public function getMustache()
{
return $this->mustache;
}
public function renderInternal(Mustache_Context $context, $indent = '', $escape = false) {
return $this->rendered;
}
public function renderInternal(Mustache_Context $context, $indent = '', $escape = false)
{
return $this->rendered;
}
}
+121 -118
View File
@@ -12,130 +12,133 @@
/**
* @group unit
*/
class Mustache_Test_TokenizerTest extends PHPUnit_Framework_TestCase {
class Mustache_Test_TokenizerTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider getTokens
*/
public function testScan($text, $delimiters, $expected) {
$tokenizer = new Mustache_Tokenizer;
$this->assertSame($expected, $tokenizer->scan($text, $delimiters));
}
/**
* @dataProvider getTokens
*/
public function testScan($text, $delimiters, $expected)
{
$tokenizer = new Mustache_Tokenizer;
$this->assertSame($expected, $tokenizer->scan($text, $delimiters));
}
public function getTokens() {
return array(
array(
'text',
null,
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'text',
),
),
),
public function getTokens()
{
return array(
array(
'text',
null,
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'text',
),
),
),
array(
'text',
'<<< >>>',
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'text',
),
),
),
array(
'text',
'<<< >>>',
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => 'text',
),
),
),
array(
'{{ name }}',
null,
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name',
Mustache_Tokenizer::OTAG => '{{',
Mustache_Tokenizer::CTAG => '}}',
Mustache_Tokenizer::INDEX => 10,
)
)
),
array(
'{{ name }}',
null,
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name',
Mustache_Tokenizer::OTAG => '{{',
Mustache_Tokenizer::CTAG => '}}',
Mustache_Tokenizer::INDEX => 10,
)
)
),
array(
'{{ name }}',
'<<< >>>',
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => '{{ name }}',
),
),
),
array(
'{{ name }}',
'<<< >>>',
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => '{{ name }}',
),
),
),
array(
'<<< name >>>',
'<<< >>>',
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name',
Mustache_Tokenizer::OTAG => '<<<',
Mustache_Tokenizer::CTAG => '>>>',
Mustache_Tokenizer::INDEX => 12,
)
)
),
array(
'<<< name >>>',
'<<< >>>',
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'name',
Mustache_Tokenizer::OTAG => '<<<',
Mustache_Tokenizer::CTAG => '>>>',
Mustache_Tokenizer::INDEX => 12,
)
)
),
array(
"{{{ a }}}\n{{# b }} \n{{= | | =}}| c ||/ b |\n|{ d }|",
null,
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_UNESCAPED,
Mustache_Tokenizer::NAME => 'a',
Mustache_Tokenizer::OTAG => '{{',
Mustache_Tokenizer::CTAG => '}}',
Mustache_Tokenizer::INDEX => 8,
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => "\n",
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_SECTION,
Mustache_Tokenizer::NAME => 'b',
Mustache_Tokenizer::OTAG => '{{',
Mustache_Tokenizer::CTAG => '}}',
Mustache_Tokenizer::INDEX => 18,
),
null,
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'c',
Mustache_Tokenizer::OTAG => '|',
Mustache_Tokenizer::CTAG => '|',
Mustache_Tokenizer::INDEX => 37,
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
Mustache_Tokenizer::NAME => 'b',
Mustache_Tokenizer::OTAG => '|',
Mustache_Tokenizer::CTAG => '|',
Mustache_Tokenizer::INDEX => 37,
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => "\n",
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_UNESCAPED,
Mustache_Tokenizer::NAME => 'd',
Mustache_Tokenizer::OTAG => '|',
Mustache_Tokenizer::CTAG => '|',
Mustache_Tokenizer::INDEX => 51,
),
array(
"{{{ a }}}\n{{# b }} \n{{= | | =}}| c ||/ b |\n|{ d }|",
null,
array(
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_UNESCAPED,
Mustache_Tokenizer::NAME => 'a',
Mustache_Tokenizer::OTAG => '{{',
Mustache_Tokenizer::CTAG => '}}',
Mustache_Tokenizer::INDEX => 8,
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => "\n",
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_SECTION,
Mustache_Tokenizer::NAME => 'b',
Mustache_Tokenizer::OTAG => '{{',
Mustache_Tokenizer::CTAG => '}}',
Mustache_Tokenizer::INDEX => 18,
),
null,
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
Mustache_Tokenizer::NAME => 'c',
Mustache_Tokenizer::OTAG => '|',
Mustache_Tokenizer::CTAG => '|',
Mustache_Tokenizer::INDEX => 37,
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
Mustache_Tokenizer::NAME => 'b',
Mustache_Tokenizer::OTAG => '|',
Mustache_Tokenizer::CTAG => '|',
Mustache_Tokenizer::INDEX => 37,
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
Mustache_Tokenizer::VALUE => "\n",
),
array(
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_UNESCAPED,
Mustache_Tokenizer::NAME => 'd',
Mustache_Tokenizer::OTAG => '|',
Mustache_Tokenizer::CTAG => '|',
Mustache_Tokenizer::INDEX => 51,
),
)
),
);
}
)
),
);
}
}