We introduced a new type for "ParserTestMode" and then uniformly pass this around alongside the ParserTest object itself. (We started by using a string for the $mode but the "explicit changetree" mode requires more structured data. We *could* encode this in JSON just to keep the string type around, but it seems cleaner and more future proof to wrap this in a proper class type.) Removed the old TestFileReader wrapper class, which served only as a thunk to convert the new Test class into the same sort of array which the legacy parser test runner code expected. There's still some remaining ::testToArray() usage here for the TestRecorder framework, but that will be cleaned up in a future patch. Also updated the TestRecorder with stronger types: use the same <Test,TestMode> pair when invoking the TestRecorder, instead of the loosely typed array we'd used previously. Change-Id: Iec4c0c7972a655b4faccacc67bdc3ca66d4c163d
70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Tests\TestMode as ParserTestMode;
|
|
use Wikimedia\Parsoid\ParserTests\Test as ParserTest;
|
|
|
|
/**
|
|
* 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 ParserTest */
|
|
private $ptTest;
|
|
|
|
/** @var ParserTestMode */
|
|
private $ptMode;
|
|
|
|
/** @var ParserTestRunner */
|
|
private $ptRunner;
|
|
|
|
/** @var string|null */
|
|
private $skipMessage;
|
|
|
|
public function __construct( $runner, $fileName, ParserTest $test, ParserTestMode $mode, $skipMessage = null ) {
|
|
parent::__construct( 'testParse',
|
|
[ "$mode" ],
|
|
basename( $fileName ) . ': ' . $test->testName );
|
|
$this->ptTest = $test;
|
|
$this->ptTestMode = $mode;
|
|
$this->ptRunner = $runner;
|
|
$this->skipMessage = $skipMessage;
|
|
}
|
|
|
|
public function testParse() {
|
|
if ( $this->skipMessage !== null ) {
|
|
$this->markTestSkipped( $this->skipMessage );
|
|
}
|
|
$this->ptRunner->getRecorder()->setTestCase( $this );
|
|
$result = $this->ptRunner->runTest( $this->ptTest, $this->ptTestMode );
|
|
if ( $result === false ) {
|
|
// Test intentionally skipped.
|
|
$result = new ParserTestResult( $this->ptTest, $this->ptTestMode, "SKIP", "SKIP" );
|
|
}
|
|
$this->assertEquals( $result->expected, $result->actual );
|
|
}
|
|
}
|