Merge branch 'dev' into feature/implicit-iterator

Conflicts:
	Mustache.php
This commit is contained in:
Justin Hileman
2010-07-05 15:55:00 -04:00
20 changed files with 317 additions and 129 deletions
+27 -1
View File
@@ -1,7 +1,6 @@
<?php
require_once '../Mustache.php';
require_once 'PHPUnit/Framework.php';
class MustachePragmaDotNotationTest extends PHPUnit_Framework_TestCase {
@@ -31,4 +30,31 @@ class MustachePragmaDotNotationTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($m->render('{{%DOT-NOTATION}}{{one.one}}|{{one.two}}|{{one.three}}'), 'one-one|one-two|one-three');
}
public function testDotNotationContext() {
$data = array('parent' => array('items' => array(
array('item' => array('index' => 1)),
array('item' => array('index' => 2)),
array('item' => array('index' => 3)),
array('item' => array('index' => 4)),
array('item' => array('index' => 5)),
)));
$m = new Mustache('', $data);
$this->assertEquals('12345', $m->render('{{%DOT-NOTATION}}{{#parent}}{{#items}}{{item.index}}{{/items}}{{/parent}}'));
}
public function testDotNotationSectionNames() {
$data = array('parent' => array('items' => array(
array('item' => array('index' => 1)),
array('item' => array('index' => 2)),
array('item' => array('index' => 3)),
array('item' => array('index' => 4)),
array('item' => array('index' => 5)),
)));
$m = new Mustache('', $data);
$this->assertEquals('.....', $m->render('{{%DOT-NOTATION}}{{#parent.items}}.{{/parent.items}}'));
$this->assertEquals('12345', $m->render('{{%DOT-NOTATION}}{{#parent.items}}{{item.index}}{{/parent.items}}'));
$this->assertEquals('12345', $m->render('{{%DOT-NOTATION}}{{#parent.items}}{{#item}}{{index}}{{/item}}{{/parent.items}}'));
}
}
+6 -1
View File
@@ -1,7 +1,6 @@
<?php
require_once '../Mustache.php';
require_once 'PHPUnit/Framework.php';
class MustachePragmaTest extends PHPUnit_Framework_TestCase {
@@ -39,4 +38,10 @@ class MustachePragmaTest extends PHPUnit_Framework_TestCase {
$this->assertEquals("1\n23", $m->render("1\n2{{%DOT-NOTATION}}\n3"), 'Wrong newline removed with pragma tag');
}
public function testPragmaReset() {
$m = new Mustache('', array('symbol' => '>>>'));
$this->assertEquals('>>>', $m->render('{{{symbol}}}'));
$this->assertEquals('>>>', $m->render('{{%UNESCAPED}}{{symbol}}'));
$this->assertEquals('>>>', $m->render('{{{symbol}}}'));
}
}
+2 -1
View File
@@ -1,7 +1,6 @@
<?php
require_once '../Mustache.php';
require_once 'PHPUnit/Framework.php';
class MustachePragmaUnescapedTest extends PHPUnit_Framework_TestCase {
@@ -9,7 +8,9 @@ class MustachePragmaUnescapedTest extends PHPUnit_Framework_TestCase {
$m = new Mustache(null, array('title' => 'Bear > Shark'));
$this->assertEquals('Bear > Shark', $m->render('{{%UNESCAPED}}{{title}}'));
$this->assertEquals('Bear &gt; Shark', $m->render('{{title}}'));
$this->assertEquals('Bear &gt; Shark', $m->render('{{%UNESCAPED}}{{{title}}}'));
$this->assertEquals('Bear > Shark', $m->render('{{{title}}}'));
}
}
+67 -1
View File
@@ -1,7 +1,6 @@
<?php
require_once '../Mustache.php';
require_once 'PHPUnit/Framework.php';
/**
* A PHPUnit test case for Mustache.php.
@@ -167,6 +166,51 @@ class MustacheTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($first, $second);
}
/**
* Mustache should not use templates passed to the render() method for subsequent invocations.
*
* @access public
* @return void
*/
public function testResetTemplateForMultipleInvocations() {
$m = new Mustache('Sirve.');
$this->assertEquals('No sirve.', $m->render('No sirve.'));
$this->assertEquals('Sirve.', $m->render());
$m2 = new Mustache();
$this->assertEquals('No sirve.', $m2->render('No sirve.'));
$this->assertEquals('', $m2->render());
}
/**
* testClone function.
*
* @dataProvider getExamples
* @access public
* @return void
*/
public function test__clone($class, $template, $output) {
if ($class == 'Delimiters') {
$this->markTestSkipped("Known issue: sections don't respect delimiter changes");
return;
}
$m = new $class;
$n = clone $m;
$n_output = $n->render($template);
$o = clone $n;
$this->assertEquals($m->render($template), $n_output);
$this->assertEquals($n_output, $o->render($template));
$this->assertNotSame($m, $n);
$this->assertNotSame($n, $o);
$this->assertNotSame($m, $o);
}
/**
* Test everything in the `examples` directory.
*
@@ -178,6 +222,11 @@ class MustacheTest extends PHPUnit_Framework_TestCase {
* @return void
*/
public function testExamples($class, $template, $output) {
if ($class == 'Delimiters') {
$this->markTestSkipped("Known issue: sections don't respect delimiter changes");
return;
}
$m = new $class;
$this->assertEquals($output, $m->render($template));
}
@@ -239,4 +288,21 @@ class MustacheTest extends PHPUnit_Framework_TestCase {
}
return $ret;
}
public function testCrazyDelimiters() {
$m = new Mustache(null, array('result' => 'success'));
$this->assertEquals('success', $m->render('{{=[[ ]]=}}[[ result ]]'));
$this->assertEquals('success', $m->render('{{=(( ))=}}(( result ))'));
$this->assertEquals('success', $m->render('{{={$ $}=}}{$ result $}'));
$this->assertEquals('success', $m->render('{{=<.. ..>=}}<.. result ..>'));
$this->assertEquals('success', $m->render('{{=^^ ^^}}^^ result ^^'));
$this->assertEquals('success', $m->render('{{=// \\\\}}// result \\\\'));
}
public function testResetDelimiters() {
$m = new Mustache(null, array('result' => 'success'));
$this->assertEquals('success', $m->render('{{=[[ ]]=}}[[ result ]]'));
$this->assertEquals('success', $m->render('{{=<< >>=}}<< result >>'));
$this->assertEquals('success', $m->render('{{=<% %>=}}<% result %>'));
}
}
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<testsuite name="Mustache">
<directory>./</directory>
</testsuite>
</phpunit>