wiki.techinc.nl/tests/phpunit/suites/ParserIntegrationTest.php
C. Scott Ananian 71aa8e0e0d Add support for running parsertests with Parsoid in integrated mode
This allows us to move Parsoid-specific extension code from the
Parsoid repo into the extension's own repository and still have
Parsoid parser tests run on it via core's mechanism for running
extension tests.

Factored out some common ParserOptions setup into a common helper
function.  There are a number of features still missing from the
Parsoid test runner, which are marked with @todo comments and
phab task numbers.

Bug: T254181
Change-Id: Ifaf53862b96e9127d8f375ad8dd0cc362cba9f5b
2020-12-23 15:50:50 -05:00

66 lines
1.8 KiB
PHP

<?php
/**
* This is the TestCase subclass for running a single parser test via the
* ParserTestRunner integration test system.
*
* Note: the following groups are not used by PHPUnit.
* The list in ParserTestFileSuite::__construct() is used instead.
*
* @group large
* @group Database
* @group Parser
* @group ParserTests
*
* @covers Parser
* @covers BlockLevelPass
* @covers CoreParserFunctions
* @covers CoreTagHooks
* @covers Sanitizer
* @covers Preprocessor
* @covers Preprocessor_Hash
* @covers DateFormatter
* @covers LinkHolderArray
* @covers StripState
* @covers ParserOptions
* @covers ParserOutput
*/
class ParserIntegrationTest extends PHPUnit\Framework\TestCase {
use MediaWikiCoversValidator;
use MediaWikiTestCaseTrait;
/** @var array */
private $ptTest;
/** @var ParserTestRunner */
private $ptRunner;
/** @var string|null */
private $skipMessage = null;
public function __construct( $runner, $fileName, $test, $skipMessage = null ) {
parent::__construct( 'testParse', [ ( $test['parsoid'] ?? false ) ? 'parsoid' : 'legacy parser' ],
basename( $fileName ) . ': ' . $test['desc'] );
$this->ptTest = $test;
$this->ptRunner = $runner;
$this->skipMessage = $skipMessage;
}
public function testParse() {
if ( $this->skipMessage !== null ) {
$this->markTestSkipped( $this->skipMessage );
}
$this->ptRunner->getRecorder()->setTestCase( $this );
if ( $this->ptTest['parsoid'] ?? false ) {
$result = $this->ptRunner->runParsoidTest( $this->ptTest['parsoid'] );
} else {
$result = $this->ptRunner->runTest( $this->ptTest );
}
if ( $result === false ) {
// Test intentionally skipped.
$result = new ParserTestResult( $this->ptTest, "SKIP", "SKIP" );
}
$this->assertEquals( $result->expected, $result->actual );
}
}