Refactor duplication out of Mustache injection test.
This commit is contained in:
@@ -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 }}');
|
||||
$this->mustache->setPartials($partials);
|
||||
$this->assertEquals($expect, $this->mustache->render($tpl, $data));
|
||||
}
|
||||
|
||||
$data = array(
|
||||
public function injectionData()
|
||||
{
|
||||
$interpolationData = array(
|
||||
'a' => '{{ b }}',
|
||||
'b' => 'FAIL'
|
||||
);
|
||||
|
||||
$this->assertEquals('{{ b }}', $tpl->render($data));
|
||||
}
|
||||
|
||||
public function testUnescapedInterpolationInjection()
|
||||
{
|
||||
$tpl = $this->mustache->loadTemplate('{{{ a }}}');
|
||||
|
||||
$data = 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 }}}',
|
||||
));
|
||||
|
||||
$data = array(
|
||||
'a' => '{{ b }}',
|
||||
'b' => 'FAIL'
|
||||
);
|
||||
|
||||
$this->assertEquals('{{ b }}', $tpl->render($data));
|
||||
}
|
||||
|
||||
// lambdas
|
||||
|
||||
public function testLambdaInterpolationInjection()
|
||||
{
|
||||
$tpl = $this->mustache->loadTemplate('{{ a }}');
|
||||
|
||||
$data = array(
|
||||
$lambdaInterpolationData = array(
|
||||
'a' => array($this, 'lambdaInterpolationCallback'),
|
||||
'b' => '{{ c }}',
|
||||
'c' => 'FAIL'
|
||||
);
|
||||
|
||||
$this->assertEquals('{{ c }}', $tpl->render($data));
|
||||
$lambdaSectionData = array(
|
||||
'a' => array($this, 'lambdaSectionCallback'),
|
||||
'b' => '{{ c }}',
|
||||
'c' => 'FAIL'
|
||||
);
|
||||
|
||||
return array(
|
||||
array('{{ a }}', $interpolationData, array(), '{{ b }}'),
|
||||
array('{{{ a }}}', $interpolationData, array(), '{{ b }}'),
|
||||
|
||||
array('{{# a }}{{ b }}{{/ a }}', $sectionData, array(), '{{ c }}'),
|
||||
array('{{# a }}{{{ b }}}{{/ a }}', $sectionData, array(), '{{ c }}'),
|
||||
|
||||
array('{{> partial }}', $interpolationData, array('partial' => '{{ a }}'), '{{ b }}'),
|
||||
array('{{> partial }}', $interpolationData, array('partial' => '{{{ a }}}'), '{{ b }}'),
|
||||
|
||||
array('{{ a }}', $lambdaInterpolationData, array(), '{{ c }}'),
|
||||
array('{{# a }}b{{/ a }}', $lambdaSectionData, array(), '{{ c }}'),
|
||||
);
|
||||
}
|
||||
|
||||
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 . ' }}';
|
||||
|
||||
Reference in New Issue
Block a user