Explorar el Código

Adding data provider to test legal and illegal syntax inside of a parent tag

Dan Miller hace 11 años
padre
commit
efae42978d
Se han modificado 1 ficheros con 80 adiciones y 14 borrados
  1. 80 14
      test/Mustache/Test/Functional/InheritanceTest.php

+ 80 - 14
test/Mustache/Test/Functional/InheritanceTest.php

@@ -14,6 +14,71 @@ class Mustache_Test_Functional_InheritanceTest extends PHPUnit_Framework_TestCas
         $this->mustache = new Mustache_Engine;
     }
 
+    public function getIllegalInheritanceExamples()
+    {
+        return array(
+            array(
+                array(
+                    'foo' => '{{$baz}}default content{{/baz}}',
+                ),
+                array(
+                    'bar' => 'set by user'
+                ),
+                '{{< foo }}{{# bar }}{{$ baz }}{{/ baz }}{{/ bar }}{{/ foo }}',
+            ),
+            array(
+                array(
+                    'foo' => '{{$baz}}default content{{/baz}}'
+                ),
+                array(
+                ),
+                '{{<foo}}{{^bar}}{{$baz}}set by template{{/baz}}{{/bar}}{{/foo}}',
+            ),
+            array(
+                array(
+                    'foo' => '{{$baz}}default content{{/baz}}',
+                    'qux' => 'I am a partial'
+                ),
+                array(
+                ),
+                '{{<foo}}{{>qux}}{{$baz}}set by template{{/baz}}{{/foo}}'
+            ),
+            array(
+                array(
+                    'foo' => '{{$baz}}default content{{/baz}}'
+                ),
+                array(
+                ),
+                '{{<foo}}{{=<% %>=}}<%={{ }}=%>{{/foo}}'
+            )
+        );
+    }
+
+    public function getLegalInheritanceExamples()
+    {
+        return array(
+            array(
+                array(
+                    'foo' => '{{$baz}}default content{{/baz}}',
+                ),
+                array(
+                    'bar' => 'set by user'
+                ),
+                '{{<foo}}{{bar}}{{$baz}}override{{/baz}}{{/foo}}',
+                'override'
+            ),
+            array(
+                array(
+                    'foo' => '{{$baz}}default content{{/baz}}'
+                ),
+                array(
+                ),
+                '{{<foo}}{{! ignore me }}{{$baz}}set by template{{/baz}}{{/foo}}',
+                'set by template'
+            )
+        );
+    }
+
     public function testDefaultContent()
     {
         $tpl = $this->mustache->loadTemplate('{{$title}}Default title{{/title}}');
@@ -339,26 +404,27 @@ class Mustache_Test_Functional_InheritanceTest extends PHPUnit_Framework_TestCas
         $this->assertEquals('default content', $tpl->render($data));
     }
 
+    
+
     /**
+     * @dataProvider getIllegalInheritanceExamples
      * @expectedException Mustache_Exception_SyntaxException
      * @expectedExceptionMessage Illegal content in < parent tag
      */
-    public function testOnlyBlockTagsAllowedInParent()
+    public function testIllegalInheritanceExamples($partials, $data, $template)
     {
-        $partials = array(
-           'foo' => '{{$baz}}default content{{/baz}}'
-       );
-
         $this->mustache->setPartials($partials);
-
-        $tpl = $this->mustache->loadTemplate(
-            '{{< foo }}{{# bar }}{{$ baz }}{{/ baz }}{{/ bar }}{{/ foo }}'
-        );
-
-        $data = array(
-            'bar' => 'set by user'
-        );
-
+        $tpl = $this->mustache->loadTemplate($template);
         $tpl->render($data);
     }
+
+    /**
+     * @dataProvider getLegalInheritanceExamples
+     */
+    public function testLegalInheritanceExamples($partials, $data, $template, $expect)
+    {
+        $this->mustache->setPartials($partials);
+        $tpl = $this->mustache->loadTemplate($template);
+        $this->assertSame($expect, $tpl->render($data));
+    }
 }