diff options
Diffstat (limited to 'tests/phpunit')
-rw-r--r-- | tests/phpunit/data/templates/foobar_args.mustache | 1 | ||||
-rw-r--r-- | tests/phpunit/includes/TemplateParserTest.php | 67 |
2 files changed, 25 insertions, 43 deletions
diff --git a/tests/phpunit/data/templates/foobar_args.mustache b/tests/phpunit/data/templates/foobar_args.mustache new file mode 100644 index 000000000000..cfbe3d0f7eb8 --- /dev/null +++ b/tests/phpunit/data/templates/foobar_args.mustache @@ -0,0 +1 @@ +hello {{planet}}! diff --git a/tests/phpunit/includes/TemplateParserTest.php b/tests/phpunit/includes/TemplateParserTest.php index f884a8ef17ba..81854ff32281 100644 --- a/tests/phpunit/includes/TemplateParserTest.php +++ b/tests/phpunit/includes/TemplateParserTest.php @@ -19,64 +19,45 @@ class TemplateParserTest extends MediaWikiTestCase { } /** + * @dataProvider provideProcessTemplate + * @covers TemplateParser::processTemplate + * @covers TemplateParser::getTemplate * @covers TemplateParser::getTemplateFilename - * @dataProvider provideGetTemplateFilename */ - public function testGetTemplateFilename( $dir, $name, $result, $exception = false ) { + public function testProcessTemplate( $name, $args, $result, $exception = false ) { if ( $exception ) { $this->setExpectedException( $exception ); } - - $tp = new TemplateParser( $dir ); - $path = $tp->getTemplateFilename( $name ); - $this->assertEquals( $result, $path ); + $tp = new TemplateParser( $this->templateDir ); + $this->assertEquals( $result, $tp->processTemplate( $name, $args ) ); } - public static function provideGetTemplateFilename() { + public static function provideProcessTemplate() { return array( array( - 'dir/templates', 'foobar', - 'dir/templates/foobar.mustache', + array(), + "hello world!\n" + ), + array( + 'foobar_args', + array( + 'planet' => 'world', + ), + "hello world!\n", ), array( - 'dir/templates', '../foobar', - '', + array(), + false, 'UnexpectedValueException' ), - ); - } - - /** - * @covers TemplateParser::getTemplate - */ - public function testGetTemplate() { - $tp = new TemplateParser( $this->templateDir ); - $this->assertTrue( is_callable( $tp->getTemplate( 'foobar' ) ) ); - } - - /** - * @covers TemplateParser::compile - */ - public function testTemplateCompilation() { - $this->assertRegExp( - '/^<\?php return function/', - TemplateParser::compile( "test" ), - 'compile a simple mustache template' - ); - } - - /** - * @covers TemplateParser::compile - */ - public function testTemplateCompilationWithVariable() { - $this->assertRegExp( - '/return \'\'\.htmlentities\(\(string\)\(\(isset\(\$in\[\'value\'\]\) && ' - . 'is_array\(\$in\)\) \? \$in\[\'value\'\] : null\), ENT_QUOTES, ' - . '\'UTF-8\'\)\.\'\';/', - TemplateParser::compile( "{{value}}" ), - 'compile a mustache template with an escaped variable' + array( + 'nonexistenttemplate', + array(), + false, + 'RuntimeException', + ) ); } } |