Merge branch 'dev' into feature/higher-order-sections

Conflicts:
	Mustache.php
This commit is contained in:
Justin Hileman
2010-08-09 09:41:40 -04:00
16 changed files with 323 additions and 33 deletions
+56
View File
@@ -0,0 +1,56 @@
<?php
require_once '../Mustache.php';
class MustacheObjectSectionTest extends PHPUnit_Framework_TestCase {
public function testBasicObject() {
$alpha = new Alpha();
$this->assertEquals('Foo', $alpha->render('{{#foo}}{{name}}{{/foo}}'));
}
public function testObjectWithGet() {
$beta = new Beta();
$this->assertEquals('Foo', $beta->render('{{#foo}}{{name}}{{/foo}}'));
}
public function testSectionObjectWithGet() {
$gamma = new Gamma();
$this->assertEquals('Foo', $gamma->render('{{#bar}}{{#foo}}{{name}}{{/foo}}{{/bar}}'));
}
}
class Alpha extends Mustache {
public $foo;
public function __construct() {
$this->foo = new StdClass();
$this->foo->name = 'Foo';
$this->foo->number = 1;
}
}
class Beta extends Mustache {
protected $_data = array();
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 __get($name) {
return $this->_data[$name];
}
}
class Gamma extends Mustache {
public $bar;
public function __construct() {
$this->bar = new Beta();
}
}
@@ -0,0 +1,51 @@
<?php
require_once '../Mustache.php';
require_once 'PHPUnit/Framework.php';
class MustachePragmaImplicitIteratorTest extends PHPUnit_Framework_TestCase {
public function testEnablePragma() {
$m = $this->getMock('Mustache', array('_renderPragma'), array('{{%IMPLICIT-ITERATOR}}'));
$m->expects($this->exactly(1))
->method('_renderPragma')
->with(array('{{%IMPLICIT-ITERATOR}}', 'IMPLICIT-ITERATOR', null));
$m->render();
}
public function testImplicitIterator() {
$m1 = new Mustache('{{%IMPLICIT-ITERATOR}}{{#items}}{{.}}{{/items}}', array('items' => array('a', 'b', 'c')));
$this->assertEquals('abc', $m1->render());
$m2 = new Mustache('{{%IMPLICIT-ITERATOR}}{{#items}}{{.}}{{/items}}', array('items' => array(1, 2, 3)));
$this->assertEquals('123', $m2->render());
}
public function testDotNotationCollision() {
$m = new Mustache(null, array('items' => array('foo', 'bar', 'baz')));
$this->assertEquals('foobarbaz', $m->render('{{%IMPLICIT-ITERATOR}}{{%DOT-NOTATION}}{{#items}}{{.}}{{/items}}'));
$this->assertEquals('foobarbaz', $m->render('{{%DOT-NOTATION}}{{%IMPLICIT-ITERATOR}}{{#items}}{{.}}{{/items}}'));
}
public function testCustomIterator() {
$m = new Mustache(null, array('items' => array('foo', 'bar', 'baz')));
$this->assertEquals('foobarbaz', $m->render('{{%IMPLICIT-ITERATOR}}{{#items}}{{.}}{{/items}}'));
$this->assertEquals('foobarbaz', $m->render('{{%IMPLICIT-ITERATOR iterator=i}}{{#items}}{{i}}{{/items}}'));
$this->assertEquals('foobarbaz', $m->render('{{%IMPLICIT-ITERATOR iterator=items}}{{#items}}{{items}}{{/items}}'));
}
public function testDotNotationContext() {
$m = new Mustache(null, array('items' => array(
array('index' => 1, 'name' => 'foo'),
array('index' => 2, 'name' => 'bar'),
array('index' => 3, 'name' => 'baz'),
)));
$this->assertEquals('foobarbaz', $m->render('{{%IMPLICIT-ITERATOR}}{{#items}}{{#.}}{{name}}{{/.}}{{/items}}'));
$this->assertEquals('123', $m->render('{{%IMPLICIT-ITERATOR iterator=i}}{{%DOT-NOTATION}}{{#items}}{{i.index}}{{/items}}'));
$this->assertEquals('foobarbaz', $m->render('{{%IMPLICIT-ITERATOR iterator=i}}{{%DOT-NOTATION}}{{#items}}{{i.name}}{{/items}}'));
}
}
+17 -13
View File
@@ -262,26 +262,30 @@ class MustacheTest extends PHPUnit_Framework_TestCase {
foreach ($children as $file) {
if (!$file->isFile()) continue;
$filename = $file->getPathInfo();
$filename = $file->getPathname();
$info = pathinfo($filename);
switch($info['extension']) {
case 'php':
$class = $info['filename'];
include_once($filename);
break;
if (isset($info['extension'])) {
switch($info['extension']) {
case 'php':
$class = $info['filename'];
include_once($filename);
break;
case 'mustache':
$template = file_get_contents($filename);
break;
case 'mustache':
$template = file_get_contents($filename);
break;
case 'txt':
$output = file_get_contents($filename);
break;
case 'txt':
$output = file_get_contents($filename);
break;
}
}
}
$ret[$example] = array($class, $template, $output);
if (!empty($class)) {
$ret[$example] = array($class, $template, $output);
}
}
$files->next();