From efae42978dbce89b2989800649ba444982c4f621 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Fri, 11 Apr 2014 16:46:27 +0000 Subject: [PATCH] Adding data provider to test legal and illegal syntax inside of a parent tag --- .../Test/Functional/InheritanceTest.php | 94 ++++++++++++++++--- 1 file changed, 80 insertions(+), 14 deletions(-) diff --git a/test/Mustache/Test/Functional/InheritanceTest.php b/test/Mustache/Test/Functional/InheritanceTest.php index bbd4969..2c57936 100644 --- a/test/Mustache/Test/Functional/InheritanceTest.php +++ b/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( + ), + '{{ '{{$baz}}default content{{/baz}}', + 'qux' => 'I am a partial' + ), + array( + ), + '{{qux}}{{$baz}}set by template{{/baz}}{{/foo}}' + ), + array( + array( + 'foo' => '{{$baz}}default content{{/baz}}' + ), + array( + ), + '{{=}}<%={{ }}=%>{{/foo}}' + ) + ); + } + + public function getLegalInheritanceExamples() + { + return array( + array( + array( + 'foo' => '{{$baz}}default content{{/baz}}', + ), + array( + 'bar' => 'set by user' + ), + '{{ '{{$baz}}default content{{/baz}}' + ), + array( + ), + '{{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)); + } }