Merge "Fix table loading bug for CRH transliteration"
[lhc/web/wiklou.git] / tests / phpunit / includes / TemplateParserTest.php
index ddef24a..ccccf0f 100644 (file)
@@ -2,6 +2,7 @@
 
 /**
  * @group Templates
+ * @covers TemplateParser
  */
 class TemplateParserTest extends MediaWikiTestCase {
 
@@ -10,18 +11,15 @@ class TemplateParserTest extends MediaWikiTestCase {
        protected function setUp() {
                parent::setUp();
 
-               $this->setMwGlobals( array(
+               $this->setMwGlobals( [
                        'wgSecretKey' => 'foo',
-               ) );
+               ] );
 
                $this->templateDir = dirname( __DIR__ ) . '/data/templates/';
        }
 
        /**
         * @dataProvider provideProcessTemplate
-        * @covers TemplateParser::processTemplate
-        * @covers TemplateParser::getTemplate
-        * @covers TemplateParser::getTemplateFilename
         */
        public function testProcessTemplate( $name, $args, $result, $exception = false ) {
                if ( $exception ) {
@@ -32,44 +30,94 @@ class TemplateParserTest extends MediaWikiTestCase {
        }
 
        public static function provideProcessTemplate() {
-               return array(
-                       array(
+               return [
+                       [
                                'foobar',
-                               array(),
+                               [],
                                "hello world!\n"
-                       ),
-                       array(
+                       ],
+                       [
                                'foobar_args',
-                               array(
+                               [
                                        'planet' => 'world',
-                               ),
+                               ],
                                "hello world!\n",
-                       ),
-                       array(
+                       ],
+                       [
                                '../foobar',
-                               array(),
+                               [],
                                false,
                                'UnexpectedValueException'
-                       ),
-                       array(
+                       ],
+                       [
+                               "\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',
-                               array(),
+                               [],
                                false,
                                'RuntimeException',
-                       ),
-                       array(
+                       ],
+                       [
                                'has_partial',
-                               array(
+                               [
                                        'planet' => 'world',
-                               ),
+                               ],
                                "Partial hello world!\n in here\n",
-                       ),
-                       array(
+                       ],
+                       [
                                'bad_partial',
-                               array(),
+                               [],
                                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 );
+       }
+
 }