MediaWiki  REL1_21
ParserMethodsTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class ParserMethodsTest extends MediaWikiLangTestCase {
00004 
00005         public static function providePreSaveTransform() {
00006                 return array(
00007                         array( 'hello this is ~~~',
00008                                 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
00009                         ),
00010                         array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
00011                                 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
00012                         ),
00013                 );
00014         }
00015 
00019         public function testPreSaveTransform( $text, $expected ) {
00020                 global $wgParser;
00021 
00022                 $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
00023                 $user = new User();
00024                 $user->setName( "127.0.0.1" );
00025                 $popts = ParserOptions::newFromUser( $user );
00026                 $text = $wgParser->preSaveTransform( $text, $title, $user, $popts );
00027 
00028                 $this->assertEquals( $expected, $text );
00029         }
00030 
00031         public function testCallParserFunction() {
00032                 global $wgParser;
00033 
00034                 // Normal parses test passing PPNodes. Test passing an array.
00035                 $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
00036                 $wgParser->startExternalParse( $title, new ParserOptions(), Parser::OT_HTML );
00037                 $frame = $wgParser->getPreprocessor()->newFrame();
00038                 $ret = $wgParser->callParserFunction( $frame, '#tag',
00039                         array( 'pre', 'foo', 'style' => 'margin-left: 1.6em' )
00040                 );
00041                 $ret['text'] = $wgParser->mStripState->unstripBoth( $ret['text'] );
00042                 $this->assertSame( array(
00043                         'found' => true,
00044                         'text' => '<pre style="margin-left: 1.6em">foo</pre>',
00045                 ), $ret, 'callParserFunction works for {{#tag:pre|foo|style=margin-left: 1.6em}}' );
00046         }
00047 
00048         // TODO: Add tests for cleanSig() / cleanSigInSig(), getSection(), replaceSection(), getPreloadText()
00049 }