2015-05-07 08:00:18 +00:00
|
|
|
<?php
|
2018-08-08 09:42:22 +00:00
|
|
|
/**
|
|
|
|
* @group PortableInfobox
|
|
|
|
* @covers Wikia\PortableInfobox\Parser\MediaWikiParserService
|
|
|
|
*/
|
|
|
|
class MediaWikiParserTest extends MediaWikiTestCase {
|
2015-05-07 08:00:18 +00:00
|
|
|
|
2015-06-15 10:43:13 +00:00
|
|
|
/** @var Parser */
|
|
|
|
protected $parser;
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
$this->parser = new Parser();
|
|
|
|
$title = Title::newFromText( 'test' );
|
|
|
|
$options = new ParserOptions();
|
2018-08-08 09:42:22 +00:00
|
|
|
$options->setOption( 'wrapclass', false );
|
2015-06-15 10:43:13 +00:00
|
|
|
$this->parser->startExternalParse( $title, $options, 'text', true );
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
2018-08-08 09:42:22 +00:00
|
|
|
public function tearDown() {
|
|
|
|
unset($this->parser);
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
2015-06-15 10:43:13 +00:00
|
|
|
protected function parse( $wikitext, $params, $newline = false ) {
|
|
|
|
$withVars = $this->parser->replaceVariables( $wikitext,
|
|
|
|
$this->parser->getPreprocessor()->newCustomFrame( $params ) );
|
|
|
|
$parserOutput = $this->parser->parse( $withVars, $this->parser->getTitle(), $this->parser->getOptions(),
|
|
|
|
$newline );
|
|
|
|
|
|
|
|
return preg_replace( '|{{{.*}}}|Us', '', preg_replace( '|[\n\r]|Us', '', $parserOutput->getText() ) );
|
|
|
|
}
|
|
|
|
|
2018-08-08 09:42:22 +00:00
|
|
|
/* Fails - it needs a modification in the core
|
2015-05-07 08:00:18 +00:00
|
|
|
public function testAsideTagPWrappedDuringParsing() {
|
|
|
|
$aside = "<aside></aside>";
|
|
|
|
$result = ( new Parser() )->doBlockLevels( $aside, true );
|
|
|
|
//parser adds new line at the end of block
|
|
|
|
$this->assertEquals( $aside . "\n", $result );
|
2018-08-08 09:42:22 +00:00
|
|
|
} */
|
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 );
|
|
|
|
$wrapper = new \Wikia\PortableInfobox\Parser\MediaWikiParserService( $this->parser, $frame );
|
|
|
|
|
|
|
|
$output = $wrapper->parseRecursive( $wikitext );
|
|
|
|
|
|
|
|
$this->assertEquals( $this->parse( $wikitext, $params, $newline ), $output );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function mwParserWrapperDataProvider() {
|
|
|
|
return [
|
|
|
|
[ "*1\n*2\n*3", [ ], true ],
|
|
|
|
[ "''d''", [ ], false ],
|
|
|
|
[ "'''dd'''", [ ], false ],
|
|
|
|
[ "#1\n#2\n#3 ksajdlk", [ ], true ],
|
|
|
|
[ "{{{test}}}", [ 'test' => 1 ], false ],
|
|
|
|
[ " :asdf", [ ], false ],
|
|
|
|
[ "\n:asdf", [ ], false ],
|
|
|
|
[ "\n;asdf", [ ], false ],
|
|
|
|
[ "[[asdf]]", [ ], false ]
|
|
|
|
];
|
|
|
|
}
|
2015-05-07 08:00:18 +00:00
|
|
|
}
|