3 class ParserMethodsTest
extends MediaWikiLangTestCase
{
5 public static function providePreSaveTransform() {
7 array( 'hello this is ~~~',
8 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
10 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
11 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
17 * @dataProvider providePreSaveTransform
18 * @covers Parser::preSaveTransform
20 public function testPreSaveTransform( $text, $expected ) {
23 $title = Title
::newFromText( str_replace( '::', '__', __METHOD__
) );
25 $user->setName( "127.0.0.1" );
26 $popts = ParserOptions
::newFromUser( $user );
27 $text = $wgParser->preSaveTransform( $text, $title, $user, $popts );
29 $this->assertEquals( $expected, $text );
33 * @expectedException MWException
34 * @expectedExceptionMessage Parser state cleared while parsing. Did you call Parser::parse recursively?
35 * @covers Parser::lock
37 public function testRecursiveParse() {
39 $title = Title
::newFromText( 'foo' );
40 $po = new ParserOptions
;
41 $wgParser->setHook( 'recursivecallparser', array( $this, 'helperParserFunc' ) );
42 $wgParser->parse( '<recursivecallparser>baz</recursivecallparser>', $title, $po );
45 public function helperParserFunc( $input, $args, $parser) {
46 $title = Title
::newFromText( 'foo' );
47 $po = new ParserOptions
;
48 $parser->parse( $input, $title, $po );
53 * @covers Parser::callParserFunction
55 public function testCallParserFunction() {
58 // Normal parses test passing PPNodes. Test passing an array.
59 $title = Title
::newFromText( str_replace( '::', '__', __METHOD__
) );
60 $wgParser->startExternalParse( $title, new ParserOptions(), Parser
::OT_HTML
);
61 $frame = $wgParser->getPreprocessor()->newFrame();
62 $ret = $wgParser->callParserFunction( $frame, '#tag',
63 array( 'pre', 'foo', 'style' => 'margin-left: 1.6em' )
65 $ret['text'] = $wgParser->mStripState
->unstripBoth( $ret['text'] );
66 $this->assertSame( array(
68 'text' => '<pre style="margin-left: 1.6em">foo</pre>',
69 ), $ret, 'callParserFunction works for {{#tag:pre|foo|style=margin-left: 1.6em}}' );
73 * @covers Parser::parse
74 * @covers ParserOutput::getSections
76 public function testGetSections() {
79 $title = Title
::newFromText( str_replace( '::', '__', __METHOD__
) );
80 $out = $wgParser->parse( "==foo==\n<h2>bar</h2>\n==baz==\n", $title, new ParserOptions() );
81 $this->assertSame( array(
88 'fromtitle' => $title->getPrefixedDBkey(),
108 'fromtitle' => $title->getPrefixedDBkey(),
112 ), $out->getSections(), 'getSections() with proper value when <h2> is used' );
114 // @todo Add tests for cleanSig() / cleanSigInSig(), getSection(),
115 // replaceSection(), getPreloadText()