https://github.com/zordius/lightncandy/compare/v0.23...v1.2.4 https://github.com/zordius/lightncandy/releases/tag/v0.89 https://github.com/zordius/lightncandy/releases/tag/v0.90 https://github.com/zordius/lightncandy/releases/tag/v0.91 https://github.com/zordius/lightncandy/releases/tag/v0.92 https://github.com/zordius/lightncandy/releases/tag/v0.93 https://github.com/zordius/lightncandy/releases/tag/v0.94 https://github.com/zordius/lightncandy/releases/tag/v0.95 https://github.com/zordius/lightncandy/releases/tag/v1.0.0 https://github.com/zordius/lightncandy/releases/tag/v1.0.1 https://github.com/zordius/lightncandy/releases/tag/v1.0.2 https://github.com/zordius/lightncandy/releases/tag/v1.0.3 https://github.com/zordius/lightncandy/releases/tag/v1.1.0 https://github.com/zordius/lightncandy/releases/tag/v1.2.0 https://github.com/zordius/lightncandy/releases/tag/v1.2.1 https://github.com/zordius/lightncandy/releases/tag/v1.2.2 https://github.com/zordius/lightncandy/releases/tag/v1.2.3 https://github.com/zordius/lightncandy/releases/tag/v1.2.4 Bug: T121947 Change-Id: Ida9e12e759cdc4508238c32153540000485a6561 Depends-On: Id1a642f5a32dfd5655c9c29094e3f3ed6077e10a Depends-On: If448d8155970d7cb4df2b9194dce8094eb887b86
134 lines
2.2 KiB
PHP
134 lines
2.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group Templates
|
|
* @covers TemplateParser
|
|
*/
|
|
class TemplateParserTest extends MediaWikiTestCase {
|
|
|
|
protected $templateDir;
|
|
|
|
protected function setUp() : void {
|
|
parent::setUp();
|
|
|
|
$this->setMwGlobals( [
|
|
'wgSecretKey' => 'foo',
|
|
] );
|
|
|
|
$this->templateDir = dirname( __DIR__ ) . '/data/templates/';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideProcessTemplate
|
|
*/
|
|
public function testProcessTemplate( $name, $args, $result, $exception = false ) {
|
|
if ( $exception ) {
|
|
$this->expectException( $exception );
|
|
}
|
|
$tp = new TemplateParser( $this->templateDir );
|
|
$this->assertEquals( $result, $tp->processTemplate( $name, $args ) );
|
|
}
|
|
|
|
public static function provideProcessTemplate() {
|
|
return [
|
|
[
|
|
'foobar',
|
|
[],
|
|
"hello world!\n"
|
|
],
|
|
[
|
|
'foobar_args',
|
|
[
|
|
'planet' => 'world',
|
|
],
|
|
"hello world!\n",
|
|
],
|
|
[
|
|
'../foobar',
|
|
[],
|
|
false,
|
|
'UnexpectedValueException'
|
|
],
|
|
[
|
|
"\000../foobar",
|
|
[],
|
|
false,
|
|
'UnexpectedValueException'
|
|
],
|
|
[
|
|
'/',
|
|
[],
|
|
false,
|
|
'UnexpectedValueException'
|
|
],
|
|
[
|
|
// Allegedly this can strip ext in windows.
|
|
'baz<',
|
|
[],
|
|
false,
|
|
'UnexpectedValueException'
|
|
],
|
|
[
|
|
'\\foo',
|
|
[],
|
|
false,
|
|
'UnexpectedValueException'
|
|
],
|
|
[
|
|
'C:\bar',
|
|
[],
|
|
false,
|
|
'UnexpectedValueException'
|
|
],
|
|
[
|
|
"foo\000bar",
|
|
[],
|
|
false,
|
|
'UnexpectedValueException'
|
|
],
|
|
[
|
|
'nonexistenttemplate',
|
|
[],
|
|
false,
|
|
'RuntimeException',
|
|
],
|
|
[
|
|
'has_partial',
|
|
[
|
|
'planet' => 'world',
|
|
],
|
|
"Partial hello world!\n in here\n",
|
|
],
|
|
[
|
|
'bad_partial',
|
|
[],
|
|
false,
|
|
'Exception',
|
|
],
|
|
[
|
|
'parentvars',
|
|
[
|
|
'foo' => 'f',
|
|
'bar' => [
|
|
[ 'baz' => 'x' ],
|
|
[ 'baz' => 'y' ]
|
|
]
|
|
],
|
|
"f\n\tf x\n\tf y\n"
|
|
]
|
|
];
|
|
}
|
|
|
|
public function testEnableRecursivePartials() {
|
|
$tp = new TemplateParser( $this->templateDir );
|
|
$data = [ 'r' => [ 'r' => [ 'r' => [] ] ] ];
|
|
|
|
$tp->enableRecursivePartials( true );
|
|
$this->assertEquals( 'rrr', $tp->processTemplate( 'recurse', $data ) );
|
|
|
|
$tp->enableRecursivePartials( false );
|
|
$this->expectException( Exception::class );
|
|
$tp->processTemplate( 'recurse', $data );
|
|
}
|
|
|
|
}
|