2015-05-07 08:00:18 +00:00
|
|
|
<?php
|
2021-09-11 23:07:07 +00:00
|
|
|
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2018-08-08 09:42:22 +00:00
|
|
|
/**
|
|
|
|
* @group PortableInfobox
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Parser\MediaWikiParserService
|
2018-08-08 09:42:22 +00:00
|
|
|
*/
|
2021-12-15 22:01:13 +00:00
|
|
|
class MediaWikiParserTest extends MediaWikiIntegrationTestCase {
|
2015-05-07 08:00:18 +00:00
|
|
|
|
2015-06-15 10:43:13 +00:00
|
|
|
/** @var Parser */
|
|
|
|
protected $parser;
|
|
|
|
|
2021-09-11 23:07:07 +00:00
|
|
|
public function setUp(): void {
|
|
|
|
$this->parser = MediaWikiServices::getInstance()->getParser();
|
2015-06-15 10:43:13 +00:00
|
|
|
$title = Title::newFromText( 'test' );
|
2021-09-11 23:07:07 +00:00
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
$options = new ParserOptions( $user );
|
2021-09-12 20:32:41 +00:00
|
|
|
$options->setOption( 'wrapclass', false );
|
2015-06-15 10:43:13 +00:00
|
|
|
$this->parser->startExternalParse( $title, $options, 'text', true );
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
2021-09-11 23:07:07 +00:00
|
|
|
public function tearDown(): void {
|
2018-08-16 09:25:53 +00:00
|
|
|
unset( $this->parser );
|
2018-08-08 09:42:22 +00:00
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
2015-06-15 10:43:13 +00:00
|
|
|
protected function parse( $wikitext, $params, $newline = false ) {
|
2018-10-02 07:41:19 +00:00
|
|
|
$withVars = $this->parser->replaceVariables(
|
|
|
|
$wikitext, $this->parser->getPreprocessor()->newCustomFrame( $params )
|
|
|
|
);
|
|
|
|
$parserOutput = $this->parser->parse(
|
|
|
|
$withVars, $this->parser->getTitle(), $this->parser->getOptions(), $newline
|
|
|
|
);
|
2015-06-15 10:43:13 +00:00
|
|
|
|
2018-10-02 07:41:19 +00:00
|
|
|
return preg_replace(
|
|
|
|
'|{{{.*}}}|Us', '', preg_replace( '|[\n\r]|Us', '', $parserOutput->getText() )
|
|
|
|
);
|
2015-06-15 10:43:13 +00:00
|
|
|
}
|
|
|
|
|
2015-05-07 08:00:18 +00:00
|
|
|
public function testAsideTagPWrappedDuringParsing() {
|
|
|
|
$aside = "<aside></aside>";
|
2021-12-03 19:28:38 +00:00
|
|
|
$result = \BlockLevelPass::doBlockLevels( $aside, true );
|
2021-09-12 23:49:00 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $aside, $result );
|
|
|
|
}
|
2015-06-15 10:43:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider mwParserWrapperDataProvider
|
|
|
|
*
|
|
|
|
* @param $wikitext
|
|
|
|
* @param $params
|
|
|
|
*/
|
|
|
|
public function testWrapper( $wikitext, $params, $newline ) {
|
|
|
|
$frame = $this->parser->getPreprocessor()->newCustomFrame( $params );
|
2018-08-09 09:49:10 +00:00
|
|
|
$wrapper = new PortableInfobox\Parser\MediaWikiParserService( $this->parser, $frame );
|
2015-06-15 10:43:13 +00:00
|
|
|
|
2021-09-12 21:14:18 +00:00
|
|
|
$output = $wrapper->parseRecursive( $wikitext );
|
2015-06-15 10:43:13 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $this->parse( $wikitext, $params, $newline ), $output );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function mwParserWrapperDataProvider() {
|
|
|
|
return [
|
2018-08-16 09:25:53 +00:00
|
|
|
[ "*1\n*2\n*3", [], true ],
|
|
|
|
[ "''d''", [], false ],
|
|
|
|
[ "'''dd'''", [], false ],
|
|
|
|
[ "#1\n#2\n#3 ksajdlk", [], true ],
|
2015-06-15 10:43:13 +00:00
|
|
|
[ "{{{test}}}", [ 'test' => 1 ], false ],
|
2018-08-16 09:25:53 +00:00
|
|
|
[ " :asdf", [], false ],
|
|
|
|
[ "\n:asdf", [], false ],
|
|
|
|
[ "\n;asdf", [], false ],
|
|
|
|
[ "[[asdf]]", [], false ]
|
2015-06-15 10:43:13 +00:00
|
|
|
];
|
|
|
|
}
|
2018-08-16 09:25:53 +00:00
|
|
|
}
|