This is sufficient to make https://gerrit.wikimedia.org/r/#/c/223165/ work. It hardcodes .mustache as the extension, but so does existing getTemplateFilename(). Bug: T97188 Change-Id: Id588ae9b43b13fcf35ebd285c826dd502ac424ec
76 lines
1.4 KiB
PHP
76 lines
1.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group Templates
|
|
*/
|
|
class TemplateParserTest extends MediaWikiTestCase {
|
|
|
|
protected $templateDir;
|
|
|
|
protected function setUp() {
|
|
parent::setUp();
|
|
|
|
$this->setMwGlobals( array(
|
|
'wgSecretKey' => 'foo',
|
|
'wgMemc' => new EmptyBagOStuff(),
|
|
) );
|
|
|
|
$this->templateDir = dirname( __DIR__ ) . '/data/templates/';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideProcessTemplate
|
|
* @covers TemplateParser::processTemplate
|
|
* @covers TemplateParser::getTemplate
|
|
* @covers TemplateParser::getTemplateFilename
|
|
*/
|
|
public function testProcessTemplate( $name, $args, $result, $exception = false ) {
|
|
if ( $exception ) {
|
|
$this->setExpectedException( $exception );
|
|
}
|
|
$tp = new TemplateParser( $this->templateDir );
|
|
$this->assertEquals( $result, $tp->processTemplate( $name, $args ) );
|
|
}
|
|
|
|
public static function provideProcessTemplate() {
|
|
return array(
|
|
array(
|
|
'foobar',
|
|
array(),
|
|
"hello world!\n"
|
|
),
|
|
array(
|
|
'foobar_args',
|
|
array(
|
|
'planet' => 'world',
|
|
),
|
|
"hello world!\n",
|
|
),
|
|
array(
|
|
'../foobar',
|
|
array(),
|
|
false,
|
|
'UnexpectedValueException'
|
|
),
|
|
array(
|
|
'nonexistenttemplate',
|
|
array(),
|
|
false,
|
|
'RuntimeException',
|
|
),
|
|
array(
|
|
'has_partial',
|
|
array(
|
|
'planet' => 'world',
|
|
),
|
|
"Partial hello world!\n in here\n",
|
|
),
|
|
array(
|
|
'bad_partial',
|
|
array(),
|
|
false,
|
|
'Exception',
|
|
),
|
|
);
|
|
}
|
|
}
|