|
|
@@ -23,105 +23,58 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
|
|
|
$this->mustache = new Mustache_Engine;
|
|
|
}
|
|
|
|
|
|
- // interpolation
|
|
|
-
|
|
|
- public function testInterpolationInjection()
|
|
|
+ /**
|
|
|
+ * @dataProvider injectionData
|
|
|
+ */
|
|
|
+ public function testInjection($tpl, $data, $partials, $expect)
|
|
|
{
|
|
|
- $tpl = $this->mustache->loadTemplate('{{ a }}');
|
|
|
-
|
|
|
- $data = array(
|
|
|
- 'a' => '{{ b }}',
|
|
|
- 'b' => 'FAIL'
|
|
|
- );
|
|
|
-
|
|
|
- $this->assertEquals('{{ b }}', $tpl->render($data));
|
|
|
+ $this->mustache->setPartials($partials);
|
|
|
+ $this->assertEquals($expect, $this->mustache->render($tpl, $data));
|
|
|
}
|
|
|
|
|
|
- public function testUnescapedInterpolationInjection()
|
|
|
+ public function injectionData()
|
|
|
{
|
|
|
- $tpl = $this->mustache->loadTemplate('{{{ a }}}');
|
|
|
-
|
|
|
- $data = array(
|
|
|
+ $interpolationData = array(
|
|
|
'a' => '{{ b }}',
|
|
|
'b' => 'FAIL'
|
|
|
);
|
|
|
|
|
|
- $this->assertEquals('{{ b }}', $tpl->render($data));
|
|
|
- }
|
|
|
-
|
|
|
- // sections
|
|
|
-
|
|
|
- public function testSectionInjection()
|
|
|
- {
|
|
|
- $tpl = $this->mustache->loadTemplate('{{# a }}{{ b }}{{/ a }}');
|
|
|
-
|
|
|
- $data = array(
|
|
|
+ $sectionData = array(
|
|
|
'a' => true,
|
|
|
'b' => '{{ c }}',
|
|
|
'c' => 'FAIL'
|
|
|
);
|
|
|
|
|
|
- $this->assertEquals('{{ c }}', $tpl->render($data));
|
|
|
- }
|
|
|
-
|
|
|
- public function testUnescapedSectionInjection()
|
|
|
- {
|
|
|
- $tpl = $this->mustache->loadTemplate('{{# a }}{{{ b }}}{{/ a }}');
|
|
|
-
|
|
|
- $data = array(
|
|
|
- 'a' => true,
|
|
|
- 'b' => '{{ c }}',
|
|
|
- 'c' => 'FAIL'
|
|
|
- );
|
|
|
-
|
|
|
- $this->assertEquals('{{ c }}', $tpl->render($data));
|
|
|
- }
|
|
|
-
|
|
|
- // partials
|
|
|
-
|
|
|
- public function testPartialInjection()
|
|
|
- {
|
|
|
- $tpl = $this->mustache->loadTemplate('{{> partial }}');
|
|
|
- $this->mustache->setPartials(array(
|
|
|
- 'partial' => '{{ a }}',
|
|
|
- ));
|
|
|
-
|
|
|
- $data = array(
|
|
|
+ $partialData = array(
|
|
|
'a' => '{{ b }}',
|
|
|
'b' => 'FAIL'
|
|
|
);
|
|
|
|
|
|
- $this->assertEquals('{{ b }}', $tpl->render($data));
|
|
|
- }
|
|
|
-
|
|
|
- public function testPartialUnescapedInjection()
|
|
|
- {
|
|
|
- $tpl = $this->mustache->loadTemplate('{{> partial }}');
|
|
|
- $this->mustache->setPartials(array(
|
|
|
- 'partial' => '{{{ a }}}',
|
|
|
- ));
|
|
|
+ $lambdaInterpolationData = array(
|
|
|
+ 'a' => array($this, 'lambdaInterpolationCallback'),
|
|
|
+ 'b' => '{{ c }}',
|
|
|
+ 'c' => 'FAIL'
|
|
|
+ );
|
|
|
|
|
|
- $data = array(
|
|
|
- 'a' => '{{ b }}',
|
|
|
- 'b' => 'FAIL'
|
|
|
+ $lambdaSectionData = array(
|
|
|
+ 'a' => array($this, 'lambdaSectionCallback'),
|
|
|
+ 'b' => '{{ c }}',
|
|
|
+ 'c' => 'FAIL'
|
|
|
);
|
|
|
|
|
|
- $this->assertEquals('{{ b }}', $tpl->render($data));
|
|
|
- }
|
|
|
+ return array(
|
|
|
+ array('{{ a }}', $interpolationData, array(), '{{ b }}'),
|
|
|
+ array('{{{ a }}}', $interpolationData, array(), '{{ b }}'),
|
|
|
|
|
|
- // lambdas
|
|
|
+ array('{{# a }}{{ b }}{{/ a }}', $sectionData, array(), '{{ c }}'),
|
|
|
+ array('{{# a }}{{{ b }}}{{/ a }}', $sectionData, array(), '{{ c }}'),
|
|
|
|
|
|
- public function testLambdaInterpolationInjection()
|
|
|
- {
|
|
|
- $tpl = $this->mustache->loadTemplate('{{ a }}');
|
|
|
+ array('{{> partial }}', $interpolationData, array('partial' => '{{ a }}'), '{{ b }}'),
|
|
|
+ array('{{> partial }}', $interpolationData, array('partial' => '{{{ a }}}'), '{{ b }}'),
|
|
|
|
|
|
- $data = array(
|
|
|
- 'a' => array($this, 'lambdaInterpolationCallback'),
|
|
|
- 'b' => '{{ c }}',
|
|
|
- 'c' => 'FAIL'
|
|
|
+ array('{{ a }}', $lambdaInterpolationData, array(), '{{ c }}'),
|
|
|
+ array('{{# a }}b{{/ a }}', $lambdaSectionData, array(), '{{ c }}'),
|
|
|
);
|
|
|
-
|
|
|
- $this->assertEquals('{{ c }}', $tpl->render($data));
|
|
|
}
|
|
|
|
|
|
public static function lambdaInterpolationCallback()
|
|
|
@@ -129,19 +82,6 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
|
|
|
return '{{ b }}';
|
|
|
}
|
|
|
|
|
|
- public function testLambdaSectionInjection()
|
|
|
- {
|
|
|
- $tpl = $this->mustache->loadTemplate('{{# a }}b{{/ a }}');
|
|
|
-
|
|
|
- $data = array(
|
|
|
- 'a' => array($this, 'lambdaSectionCallback'),
|
|
|
- 'b' => '{{ c }}',
|
|
|
- 'c' => 'FAIL'
|
|
|
- );
|
|
|
-
|
|
|
- $this->assertEquals('{{ c }}', $tpl->render($data));
|
|
|
- }
|
|
|
-
|
|
|
public static function lambdaSectionCallback($text)
|
|
|
{
|
|
|
return '{{ ' . $text . ' }}';
|