6 * @covers BlockLevelPass
8 class ParserMethodsTest
extends MediaWikiLangTestCase
{
10 public static function providePreSaveTransform() {
12 [ 'hello this is ~~~',
13 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
15 [ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
16 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
22 * @dataProvider providePreSaveTransform
24 public function testPreSaveTransform( $text, $expected ) {
27 $title = Title
::newFromText( str_replace( '::', '__', __METHOD__
) );
29 $user->setName( "127.0.0.1" );
30 $popts = ParserOptions
::newFromUser( $user );
31 $text = $wgParser->preSaveTransform( $text, $title, $user, $popts );
33 $this->assertEquals( $expected, $text );
36 public static function provideStripOuterParagraph() {
37 // This mimics the most common use case (stripping paragraphs generated by the parser).
38 $message = new RawMessage( "Message text." );
46 "<p class='foo'>Text.</p>",
47 "<p class='foo'>Text.</p>",
54 "<p>Text.</p><p>More text.</p>",
55 "<p>Text.</p><p>More text.</p>",
65 * @dataProvider provideStripOuterParagraph
67 public function testStripOuterParagraph( $text, $expected ) {
68 $this->assertEquals( $expected, Parser
::stripOuterParagraph( $text ) );
72 * @expectedException MWException
73 * @expectedExceptionMessage Parser state cleared while parsing.
74 * Did you call Parser::parse recursively?
76 public function testRecursiveParse() {
78 $title = Title
::newFromText( 'foo' );
79 $po = new ParserOptions
;
80 $wgParser->setHook( 'recursivecallparser', [ $this, 'helperParserFunc' ] );
81 $wgParser->parse( '<recursivecallparser>baz</recursivecallparser>', $title, $po );
84 public function helperParserFunc( $input, $args, $parser ) {
85 $title = Title
::newFromText( 'foo' );
86 $po = new ParserOptions
;
87 $parser->parse( $input, $title, $po );
91 public function testCallParserFunction() {
94 // Normal parses test passing PPNodes. Test passing an array.
95 $title = Title
::newFromText( str_replace( '::', '__', __METHOD__
) );
96 $wgParser->startExternalParse( $title, new ParserOptions(), Parser
::OT_HTML
);
97 $frame = $wgParser->getPreprocessor()->newFrame();
98 $ret = $wgParser->callParserFunction( $frame, '#tag',
99 [ 'pre', 'foo', 'style' => 'margin-left: 1.6em' ]
101 $ret['text'] = $wgParser->mStripState
->unstripBoth( $ret['text'] );
104 'text' => '<pre style="margin-left: 1.6em">foo</pre>',
105 ], $ret, 'callParserFunction works for {{#tag:pre|foo|style=margin-left: 1.6em}}' );
110 * @covers ParserOutput::getSections
112 public function testGetSections() {
115 $title = Title
::newFromText( str_replace( '::', '__', __METHOD__
) );
116 $out = $wgParser->parse( "==foo==\n<h2>bar</h2>\n==baz==\n", $title, new ParserOptions() );
124 'fromtitle' => $title->getPrefixedDBkey(),
134 'fromtitle' => false,
135 'byteoffset' => null,
144 'fromtitle' => $title->getPrefixedDBkey(),
148 ], $out->getSections(), 'getSections() with proper value when <h2> is used' );
152 * @dataProvider provideNormalizeLinkUrl
154 public function testNormalizeLinkUrl( $explanation, $url, $expected ) {
155 $this->assertEquals( $expected, Parser
::normalizeLinkUrl( $url ), $explanation );
158 public static function provideNormalizeLinkUrl() {
161 'Escaping of unsafe characters',
162 'http://example.org/foo bar?param[]="value"¶m[]=valüe',
163 'http://example.org/foo%20bar?param%5B%5D=%22value%22¶m%5B%5D=val%C3%BCe',
166 'Case normalization of percent-encoded characters',
167 'http://example.org/%ab%cD%Ef%FF',
168 'http://example.org/%AB%CD%EF%FF',
171 'Unescaping of safe characters',
172 'http://example.org/%3C%66%6f%6F%3E?%3C%66%6f%6F%3E#%3C%66%6f%6F%3E',
173 'http://example.org/%3Cfoo%3E?%3Cfoo%3E#%3Cfoo%3E',
176 'Context-sensitive replacement of sometimes-safe characters',
177 'http://example.org/%23%2F%3F%26%3D%2B%3B?%23%2F%3F%26%3D%2B%3B#%23%2F%3F%26%3D%2B%3B',
178 'http://example.org/%23%2F%3F&=+;?%23/?%26%3D%2B%3B#%23/?&=+;',
183 // @todo Add tests for cleanSig() / cleanSigInSig(), getSection(),
184 // replaceSection(), getPreloadText()