MediaWiki
REL1_22
|
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 00020 public function testPreSaveTransform( $text, $expected ) { 00021 global $wgParser; 00022 00023 $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) ); 00024 $user = new User(); 00025 $user->setName( "127.0.0.1" ); 00026 $popts = ParserOptions::newFromUser( $user ); 00027 $text = $wgParser->preSaveTransform( $text, $title, $user, $popts ); 00028 00029 $this->assertEquals( $expected, $text ); 00030 } 00031 00035 public function testCallParserFunction() { 00036 global $wgParser; 00037 00038 // Normal parses test passing PPNodes. Test passing an array. 00039 $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) ); 00040 $wgParser->startExternalParse( $title, new ParserOptions(), Parser::OT_HTML ); 00041 $frame = $wgParser->getPreprocessor()->newFrame(); 00042 $ret = $wgParser->callParserFunction( $frame, '#tag', 00043 array( 'pre', 'foo', 'style' => 'margin-left: 1.6em' ) 00044 ); 00045 $ret['text'] = $wgParser->mStripState->unstripBoth( $ret['text'] ); 00046 $this->assertSame( array( 00047 'found' => true, 00048 'text' => '<pre style="margin-left: 1.6em">foo</pre>', 00049 ), $ret, 'callParserFunction works for {{#tag:pre|foo|style=margin-left: 1.6em}}' ); 00050 } 00051 00056 public function testGetSections() { 00057 global $wgParser; 00058 00059 $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) ); 00060 $out = $wgParser->parse( "==foo==\n<h2>bar</h2>\n==baz==\n", $title, new ParserOptions() ); 00061 $this->assertSame( array( 00062 array( 00063 'toclevel' => 1, 00064 'level' => '2', 00065 'line' => 'foo', 00066 'number' => '1', 00067 'index' => '1', 00068 'fromtitle' => $title->getPrefixedDBkey(), 00069 'byteoffset' => 0, 00070 'anchor' => 'foo', 00071 ), 00072 array( 00073 'toclevel' => 1, 00074 'level' => '2', 00075 'line' => 'bar', 00076 'number' => '2', 00077 'index' => '', 00078 'fromtitle' => false, 00079 'byteoffset' => null, 00080 'anchor' => 'bar', 00081 ), 00082 array( 00083 'toclevel' => 1, 00084 'level' => '2', 00085 'line' => 'baz', 00086 'number' => '3', 00087 'index' => '2', 00088 'fromtitle' => $title->getPrefixedDBkey(), 00089 'byteoffset' => 21, 00090 'anchor' => 'baz', 00091 ), 00092 ), $out->getSections(), 'getSections() with proper value when <h2> is used' ); 00093 } 00094 //@Todo Add tests for cleanSig() / cleanSigInSig(), getSection(), replaceSection(), getPreloadText() 00095 }