Mock the needed services, or set fixed values to avoid DB lookups, when possible. Add the test to the Database group otherwise, e.g. for things like Skin and Parser that use global state all over the place. Change-Id: I8d87013d89accaf04d0ac19cb4b7216290383eb5
41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tests\Parser\Parsoid;
|
|
|
|
use MediaWiki\Title\Title;
|
|
use MediaWikiIntegrationTestCase;
|
|
use ParserOptions;
|
|
|
|
/**
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidParser::parse
|
|
* @group Database
|
|
*/
|
|
class ParsoidParserTest extends MediaWikiIntegrationTestCase {
|
|
|
|
/** @dataProvider provideParsoidParserHtml */
|
|
public function testParsoidParserHtml( $args, $expected, $getTextOpts = [] ) {
|
|
$parsoidParser = $this->getServiceContainer()
|
|
->getParsoidParserFactory()->create();
|
|
if ( is_string( $args[1] ?? '' ) ) {
|
|
// Make a PageReference from a string
|
|
$args[1] = Title::newFromText( $args[1] ?? 'Main Page' );
|
|
}
|
|
if ( ( $args[2] ?? null ) === null ) {
|
|
// Make default ParserOptions if none are provided
|
|
$args[2] = ParserOptions::newFromAnon();
|
|
}
|
|
$output = $parsoidParser->parse( ...$args );
|
|
$html = $output->getText( $getTextOpts );
|
|
$this->assertStringContainsString( $expected, $html );
|
|
$this->assertSame( [ 'wrapclass', 'interfaceMessage', 'maxIncludeSize' ], $output->getUsedOptions() );
|
|
}
|
|
|
|
public static function provideParsoidParserHtml() {
|
|
return [
|
|
[ [ 'Hello, World' ], 'Hello, World' ],
|
|
[ [ '__NOTOC__' ], '<meta property="mw:PageProp/notoc"' ],
|
|
// Once we support $linestart and other parser options we
|
|
// can extend these tests.
|
|
];
|
|
}
|
|
}
|