There is currently no straightforward way for anything to call a parser function and get the result. This abstracts out that portion of braceSubstitution() to allow this. The immediate motivation for this patch is to close bug 41769 against Scribunto, see I0138836654b0e34c5c23daaedcdf5d4f9d1c7ab2. Bug: 41769 Change-Id: I339b882010dedd714e7965e25ad650ed8b8cd48f
49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
<?php
|
|
|
|
class ParserMethodsTest extends MediaWikiLangTestCase {
|
|
|
|
public static function providePreSaveTransform() {
|
|
return array(
|
|
array( 'hello this is ~~~',
|
|
"hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
|
|
),
|
|
array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
|
|
'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providePreSaveTransform
|
|
*/
|
|
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 );
|
|
}
|
|
|
|
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}}' );
|
|
}
|
|
|
|
// TODO: Add tests for cleanSig() / cleanSigInSig(), getSection(), replaceSection(), getPreloadText()
|
|
}
|