Browse Source

Added context and section unit tests for dot notation pragma.

Justin Hileman 15 years ago
parent
commit
38a5e57514
2 changed files with 29 additions and 2 deletions
  1. 27 0
      test/MustachePragmaDotNotationTest.php
  2. 2 2
      test/MustacheTest.php

+ 27 - 0
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}}'));
+	}
 }

+ 2 - 2
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());
 	}