PortableInfobox/tests/phpunit/MediaWikiParserTest.php

74 lines
2.1 KiB
PHP
Raw Normal View History

2015-05-07 08:00:18 +00:00
<?php
2018-08-08 09:42:22 +00:00
/**
* @group PortableInfobox
* @covers PortableInfobox\Parser\MediaWikiParserService
2018-08-08 09:42:22 +00:00
*/
class MediaWikiParserTest extends MediaWikiTestCase {
2015-05-07 08:00:18 +00:00
/** @var Parser */
protected $parser;
public function setUp() {
$this->parser = new Parser();
$title = Title::newFromText( 'test' );
$options = new ParserOptions();
2018-08-19 11:35:46 +00:00
// Required for MW >= 1.30
2018-08-22 14:22:30 +00:00
if ( method_exists( $options, 'setOption' ) ) {
2018-08-19 11:35:46 +00:00
$options->setOption( 'wrapclass', false );
}
$this->parser->startExternalParse( $title, $options, 'text', true );
parent::setUp();
}
2018-08-08 09:42:22 +00:00
public function tearDown() {
2018-08-16 09:25:53 +00:00
unset( $this->parser );
2018-08-08 09:42:22 +00:00
parent::tearDown();
}
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-16 09:25:53 +00:00
/* Fails - it needs a modification in the core to pass
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
} */
/**
* @dataProvider mwParserWrapperDataProvider
*
* @param $wikitext
* @param $params
*/
public function testWrapper( $wikitext, $params, $newline ) {
$frame = $this->parser->getPreprocessor()->newCustomFrame( $params );
$wrapper = new PortableInfobox\Parser\MediaWikiParserService( $this->parser, $frame );
$output = $wrapper->parseRecursive( $wikitext );
$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 ],
[ "{{{test}}}", [ 'test' => 1 ], false ],
2018-08-16 09:25:53 +00:00
[ " :asdf", [], false ],
[ "\n:asdf", [], false ],
[ "\n;asdf", [], false ],
[ "[[asdf]]", [], false ]
];
}
2018-08-16 09:25:53 +00:00
}