diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/tests/phpunit/includes/TemplateParserTest.php |
first commit
Diffstat (limited to 'www/wiki/tests/phpunit/includes/TemplateParserTest.php')
-rw-r--r-- | www/wiki/tests/phpunit/includes/TemplateParserTest.php | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/www/wiki/tests/phpunit/includes/TemplateParserTest.php b/www/wiki/tests/phpunit/includes/TemplateParserTest.php new file mode 100644 index 00000000..ccccf0f9 --- /dev/null +++ b/www/wiki/tests/phpunit/includes/TemplateParserTest.php @@ -0,0 +1,123 @@ +<?php + +/** + * @group Templates + * @covers TemplateParser + */ +class TemplateParserTest extends MediaWikiTestCase { + + protected $templateDir; + + protected function setUp() { + 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->setExpectedException( $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', + ], + ]; + } + + 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->setExpectedException( Exception::class ); + $tp->processTemplate( 'recurse', $data ); + } + +} |