2012-06-23 18:28:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
2012-06-23 21:04:57 +00:00
|
|
|
class ParserMethodsTest extends MediaWikiLangTestCase {
|
2012-06-23 18:28:51 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function providePreSaveTransform() {
|
2012-06-23 18:28:51 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'hello this is ~~~',
|
2013-02-15 10:24:31 +00:00
|
|
|
"hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
|
2012-06-23 18:28:51 +00:00
|
|
|
),
|
|
|
|
|
array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
|
2013-02-15 10:24:31 +00:00
|
|
|
'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
|
2012-06-23 18:28:51 +00:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider providePreSaveTransform
|
2013-10-22 23:50:38 +00:00
|
|
|
* @covers Parser::preSaveTransform
|
2012-06-23 18:28:51 +00:00
|
|
|
*/
|
|
|
|
|
public function testPreSaveTransform( $text, $expected ) {
|
|
|
|
|
global $wgParser;
|
|
|
|
|
|
|
|
|
|
$title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
|
|
|
|
|
$user = new User();
|
|
|
|
|
$user->setName( "127.0.0.1" );
|
|
|
|
|
$popts = ParserOptions::newFromUser( $user );
|
|
|
|
|
$text = $wgParser->preSaveTransform( $text, $title, $user, $popts );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $text );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-22 23:50:38 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Parser::callParserFunction
|
|
|
|
|
*/
|
2013-03-04 03:35:05 +00:00
|
|
|
public function testCallParserFunction() {
|
|
|
|
|
global $wgParser;
|
|
|
|
|
|
|
|
|
|
// Normal parses test passing PPNodes. Test passing an array.
|
|
|
|
|
$title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
|
|
|
|
|
$wgParser->startExternalParse( $title, new ParserOptions(), Parser::OT_HTML );
|
|
|
|
|
$frame = $wgParser->getPreprocessor()->newFrame();
|
|
|
|
|
$ret = $wgParser->callParserFunction( $frame, '#tag',
|
|
|
|
|
array( 'pre', 'foo', 'style' => 'margin-left: 1.6em' )
|
|
|
|
|
);
|
|
|
|
|
$ret['text'] = $wgParser->mStripState->unstripBoth( $ret['text'] );
|
|
|
|
|
$this->assertSame( array(
|
|
|
|
|
'found' => true,
|
|
|
|
|
'text' => '<pre style="margin-left: 1.6em">foo</pre>',
|
|
|
|
|
), $ret, 'callParserFunction works for {{#tag:pre|foo|style=margin-left: 1.6em}}' );
|
|
|
|
|
}
|
2013-10-09 15:03:40 +00:00
|
|
|
|
2013-10-22 23:50:38 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Parser::parse
|
|
|
|
|
* @covers ParserOutput::getSections
|
|
|
|
|
*/
|
2013-10-09 15:03:40 +00:00
|
|
|
public function testGetSections() {
|
|
|
|
|
global $wgParser;
|
|
|
|
|
|
|
|
|
|
$title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
|
|
|
|
|
$out = $wgParser->parse( "==foo==\n<h2>bar</h2>\n==baz==\n", $title, new ParserOptions() );
|
|
|
|
|
$this->assertSame( array(
|
|
|
|
|
array(
|
|
|
|
|
'toclevel' => 1,
|
|
|
|
|
'level' => '2',
|
|
|
|
|
'line' => 'foo',
|
|
|
|
|
'number' => '1',
|
|
|
|
|
'index' => '1',
|
|
|
|
|
'fromtitle' => $title->getPrefixedDBkey(),
|
|
|
|
|
'byteoffset' => 0,
|
|
|
|
|
'anchor' => 'foo',
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'toclevel' => 1,
|
|
|
|
|
'level' => '2',
|
|
|
|
|
'line' => 'bar',
|
|
|
|
|
'number' => '2',
|
|
|
|
|
'index' => '',
|
|
|
|
|
'fromtitle' => false,
|
|
|
|
|
'byteoffset' => null,
|
|
|
|
|
'anchor' => 'bar',
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'toclevel' => 1,
|
|
|
|
|
'level' => '2',
|
|
|
|
|
'line' => 'baz',
|
|
|
|
|
'number' => '3',
|
|
|
|
|
'index' => '2',
|
|
|
|
|
'fromtitle' => $title->getPrefixedDBkey(),
|
|
|
|
|
'byteoffset' => 21,
|
|
|
|
|
'anchor' => 'baz',
|
|
|
|
|
),
|
|
|
|
|
), $out->getSections(), 'getSections() with proper value when <h2> is used' );
|
|
|
|
|
}
|
2014-04-24 17:52:09 +00:00
|
|
|
// @todo Add tests for cleanSig() / cleanSigInSig(), getSection(),
|
|
|
|
|
// replaceSection(), getPreloadText()
|
2012-06-23 18:28:51 +00:00
|
|
|
}
|