5 * @covers TemplateParser
7 class TemplateParserTest
extends MediaWikiTestCase
{
9 protected $templateDir;
11 protected function setUp() {
14 $this->setMwGlobals( [
15 'wgSecretKey' => 'foo',
18 $this->templateDir
= dirname( __DIR__
) . '/data/templates/';
22 * @dataProvider provideProcessTemplate
24 public function testProcessTemplate( $name, $args, $result, $exception = false ) {
26 $this->setExpectedException( $exception );
28 $tp = new TemplateParser( $this->templateDir
);
29 $this->assertEquals( $result, $tp->processTemplate( $name, $args ) );
32 public static function provideProcessTemplate() {
50 'UnexpectedValueException'
56 'UnexpectedValueException'
62 'UnexpectedValueException'
65 // Allegedly this can strip ext in windows.
69 'UnexpectedValueException'
75 'UnexpectedValueException'
81 'UnexpectedValueException'
87 'UnexpectedValueException'
90 'nonexistenttemplate',
100 "Partial hello world!\n in here\n",
117 "f\n\n\tf x\n\n\tf y\n\n"
122 public function testEnableRecursivePartials() {
123 $tp = new TemplateParser( $this->templateDir
);
124 $data = [ 'r' => [ 'r' => [ 'r' => [] ] ] ];
126 $tp->enableRecursivePartials( true );
127 $this->assertEquals( 'rrr', $tp->processTemplate( 'recurse', $data ) );
129 $tp->enableRecursivePartials( false );
130 $this->setExpectedException( Exception
::class );
131 $tp->processTemplate( 'recurse', $data );