From 38a5e57514a6b20ded3b8debdabe70141f73abd9 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 1 Jun 2010 17:00:44 -0400 Subject: [PATCH] Added context and section unit tests for dot notation pragma. --- test/MustachePragmaDotNotationTest.php | 27 ++++++++++++++++++++++++++ test/MustacheTest.php | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/test/MustachePragmaDotNotationTest.php b/test/MustachePragmaDotNotationTest.php index d6d31b7..65195b6 100644 --- a/test/MustachePragmaDotNotationTest.php +++ b/test/MustachePragmaDotNotationTest.php @@ -31,4 +31,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}}')); + } } \ No newline at end of file diff --git a/test/MustacheTest.php b/test/MustacheTest.php index 7787c64..c787f37 100644 --- a/test/MustacheTest.php +++ b/test/MustacheTest.php @@ -176,11 +176,11 @@ class MustacheTest extends PHPUnit_Framework_TestCase { */ public function testResetTemplateForMultipleInvocations() { $m = new Mustache('Sirve.'); - $m->render('No sirve.'); + $this->assertEquals('No sirve.', $m->render('No sirve.')); $this->assertEquals('Sirve.', $m->render()); $m2 = new Mustache(); - $m2->render('No sirve.'); + $this->assertEquals('No sirve.', $m2->render('No sirve.')); $this->assertEquals('', $m2->render()); }