Merge "Final page of search results sometimes having erroneous "next" link"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / ParserMethodsTest.php
index e5c5cb2..29af2c2 100644 (file)
@@ -29,6 +29,62 @@ class ParserMethodsTest extends MediaWikiLangTestCase {
                $this->assertEquals( $expected, $text );
        }
 
+       public static function provideStripOuterParagraph() {
+               // This mimics the most common use case (stripping paragraphs generated by the parser).
+               $message = new RawMessage( "Message text." );
+
+               return array(
+                       array(
+                               "<p>Text.</p>",
+                               "Text.",
+                       ),
+                       array(
+                               "<p class='foo'>Text.</p>",
+                               "<p class='foo'>Text.</p>",
+                       ),
+                       array(
+                               "<p>Text.\n</p>\n",
+                               "Text.",
+                       ),
+                       array(
+                               "<p>Text.</p><p>More text.</p>",
+                               "<p>Text.</p><p>More text.</p>",
+                       ),
+                       array(
+                               $message->parse(),
+                               "Message text.",
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideStripOuterParagraph
+        * @covers Parser::stripOuterParagraph
+        */
+       public function testStripOuterParagraph( $text, $expected ) {
+               $this->assertEquals( $expected, Parser::stripOuterParagraph( $text ) );
+       }
+
+       /**
+        * @expectedException MWException
+        * @expectedExceptionMessage Parser state cleared while parsing. Did you call Parser::parse recursively?
+        * @covers Parser::lock
+        */
+       public function testRecursiveParse() {
+               global $wgParser;
+               $title = Title::newFromText( 'foo' );
+               $po = new ParserOptions;
+               $wgParser->setHook( 'recursivecallparser', array( $this, 'helperParserFunc' ) );
+               $wgParser->parse( '<recursivecallparser>baz</recursivecallparser>', $title, $po );
+       }
+
+       public function helperParserFunc( $input, $args, $parser) {
+               $title = Title::newFromText( 'foo' );
+               $po = new ParserOptions;
+               $parser->parse( $input, $title, $po );
+               return 'bar';
+       }
+
        /**
         * @covers Parser::callParserFunction
         */
@@ -91,5 +147,6 @@ class ParserMethodsTest extends MediaWikiLangTestCase {
                        ),
                ), $out->getSections(), 'getSections() with proper value when <h2> is used' );
        }
-       //@Todo Add tests for cleanSig() / cleanSigInSig(), getSection(), replaceSection(), getPreloadText()
+       // @todo Add tests for cleanSig() / cleanSigInSig(), getSection(),
+       // replaceSection(), getPreloadText()
 }