6 class TemplateParserTest
extends MediaWikiTestCase
{
8 protected $templateDir;
10 protected function setUp() {
13 $this->setMwGlobals( array(
14 'wgSecretKey' => 'foo',
15 'wgMemc' => new EmptyBagOStuff(),
18 $this->templateDir
= dirname( __DIR__
) . '/data/templates/';
22 * @covers TemplateParser::getTemplateFilename
23 * @dataProvider provideGetTemplateFilename
25 public function testGetTemplateFilename( $dir, $name, $result, $exception = false ) {
27 $this->setExpectedException( $exception );
30 $tp = new TemplateParser( $dir );
31 $path = $tp->getTemplateFilename( $name );
32 $this->assertEquals( $result, $path );
35 public static function provideGetTemplateFilename() {
40 'dir/templates/foobar.mustache',
46 'UnexpectedValueException'
52 * @covers TemplateParser::getTemplate
54 public function testGetTemplate() {
55 $tp = new TemplateParser( $this->templateDir
);
56 $this->assertTrue( is_callable( $tp->getTemplate( 'foobar' ) ) );
60 * @covers TemplateParser::compile
62 public function testTemplateCompilation() {
64 '/^<\?php return function/',
65 TemplateParser
::compile( "test" ),
66 'compile a simple mustache template'
71 * @covers TemplateParser::compile
73 public function testTemplateCompilationWithVariable() {
75 '/return \'\'\.htmlentities\(\(string\)\(\(isset\(\$in\[\'value\'\]\) && '
76 . 'is_array\(\$in\)\) \? \$in\[\'value\'\] : null\), ENT_QUOTES, '
77 . '\'UTF-8\'\)\.\'\';/',
78 TemplateParser
::compile( "{{value}}" ),
79 'compile a mustache template with an escaped variable'