2015-01-30 19:31:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group Templates
|
|
|
|
|
*/
|
|
|
|
|
class TemplateParserTest extends MediaWikiTestCase {
|
2015-03-22 22:01:52 +00:00
|
|
|
|
|
|
|
|
protected $templateDir;
|
|
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->setMwGlobals( array(
|
|
|
|
|
'wgSecretKey' => 'foo',
|
|
|
|
|
'wgMemc' => new EmptyBagOStuff(),
|
|
|
|
|
) );
|
|
|
|
|
|
|
|
|
|
$this->templateDir = dirname( __DIR__ ) . '/data/templates/';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers TemplateParser::getTemplateFilename
|
|
|
|
|
* @dataProvider provideGetTemplateFilename
|
|
|
|
|
*/
|
|
|
|
|
public function testGetTemplateFilename( $dir, $name, $result, $exception = false ) {
|
|
|
|
|
if ( $exception ) {
|
|
|
|
|
$this->setExpectedException( $exception );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tp = new TemplateParser( $dir );
|
|
|
|
|
$path = $tp->getTemplateFilename( $name );
|
|
|
|
|
$this->assertEquals( $result, $path );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideGetTemplateFilename() {
|
|
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
'dir/templates',
|
|
|
|
|
'foobar',
|
|
|
|
|
'dir/templates/foobar.mustache',
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'dir/templates',
|
|
|
|
|
'../foobar',
|
|
|
|
|
'',
|
|
|
|
|
'UnexpectedValueException'
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers TemplateParser::getTemplate
|
|
|
|
|
*/
|
|
|
|
|
public function testGetTemplate() {
|
|
|
|
|
$tp = new TemplateParser( $this->templateDir );
|
|
|
|
|
$this->assertTrue( is_callable( $tp->getTemplate( 'foobar' ) ) );
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-30 19:31:44 +00:00
|
|
|
/**
|
|
|
|
|
* @covers TemplateParser::compile
|
|
|
|
|
*/
|
|
|
|
|
public function testTemplateCompilation() {
|
|
|
|
|
$this->assertRegExp(
|
|
|
|
|
'/^<\?php return function/',
|
|
|
|
|
TemplateParser::compile( "test" ),
|
|
|
|
|
'compile a simple mustache template'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers TemplateParser::compile
|
|
|
|
|
*/
|
|
|
|
|
public function testTemplateCompilationWithVariable() {
|
|
|
|
|
$this->assertRegExp(
|
|
|
|
|
'/return \'\'\.htmlentities\(\(string\)\(\(isset\(\$in\[\'value\'\]\) && '
|
|
|
|
|
. 'is_array\(\$in\)\) \? \$in\[\'value\'\] : null\), ENT_QUOTES, '
|
|
|
|
|
. '\'UTF-8\'\)\.\'\';/',
|
|
|
|
|
TemplateParser::compile( "{{value}}" ),
|
|
|
|
|
'compile a mustache template with an escaped variable'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|