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/';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-03-23 03:06:28 +00:00
|
|
|
* @dataProvider provideProcessTemplate
|
|
|
|
|
* @covers TemplateParser::processTemplate
|
|
|
|
|
* @covers TemplateParser::getTemplate
|
2015-03-22 22:01:52 +00:00
|
|
|
* @covers TemplateParser::getTemplateFilename
|
|
|
|
|
*/
|
2015-03-23 03:06:28 +00:00
|
|
|
public function testProcessTemplate( $name, $args, $result, $exception = false ) {
|
2015-03-22 22:01:52 +00:00
|
|
|
if ( $exception ) {
|
|
|
|
|
$this->setExpectedException( $exception );
|
|
|
|
|
}
|
2015-03-23 03:06:28 +00:00
|
|
|
$tp = new TemplateParser( $this->templateDir );
|
|
|
|
|
$this->assertEquals( $result, $tp->processTemplate( $name, $args ) );
|
2015-03-22 22:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-23 03:06:28 +00:00
|
|
|
public static function provideProcessTemplate() {
|
2015-03-22 22:01:52 +00:00
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
'foobar',
|
2015-03-23 03:06:28 +00:00
|
|
|
array(),
|
|
|
|
|
"hello world!\n"
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'foobar_args',
|
|
|
|
|
array(
|
|
|
|
|
'planet' => 'world',
|
|
|
|
|
),
|
|
|
|
|
"hello world!\n",
|
2015-03-22 22:01:52 +00:00
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'../foobar',
|
2015-03-23 03:06:28 +00:00
|
|
|
array(),
|
|
|
|
|
false,
|
2015-03-22 22:01:52 +00:00
|
|
|
'UnexpectedValueException'
|
|
|
|
|
),
|
2015-03-23 03:06:28 +00:00
|
|
|
array(
|
|
|
|
|
'nonexistenttemplate',
|
|
|
|
|
array(),
|
|
|
|
|
false,
|
|
|
|
|
'RuntimeException',
|
2015-07-07 01:32:21 +00:00
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'has_partial',
|
|
|
|
|
array(
|
|
|
|
|
'planet' => 'world',
|
|
|
|
|
),
|
|
|
|
|
"Partial hello world!\n in here\n",
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'bad_partial',
|
|
|
|
|
array(),
|
|
|
|
|
false,
|
|
|
|
|
'Exception',
|
|
|
|
|
),
|
2015-01-30 19:31:44 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|