3 use PHPUnit\Framework\TestSuite
;
4 use Wikimedia\Parsoid\ParserTests\Test
as ParserTest
;
5 use Wikimedia\Parsoid\ParserTests\TestFileReader
;
6 use Wikimedia\Parsoid\ParserTests\TestMode
as ParserTestMode
;
7 use Wikimedia\ScopedCallback
;
10 * This is the suite class for running tests with Parsoid in integrated
11 * mode within a single .txt source file.
12 * It is not invoked directly. Use --filter to select files, or
13 * use parserTests.php.
15 class ParsoidTestFileSuite
extends TestSuite
{
18 private ParserTestRunner
$ptRunner;
19 private TestFileReader
$ptFileInfo;
21 /** @var ScopedCallback */
22 private $ptTeardownScope;
24 public function __construct( ParserTestRunner
$runner, string $name, string $fileName ) {
25 parent
::__construct( $name );
26 $this->ptRunner
= $runner;
28 $this->ptFileInfo
= TestFileReader
::read( $fileName, static function ( $msg ) {
29 wfDeprecatedMsg( $msg, '1.35', false, false );
31 } catch ( \Exception
$e ) {
32 // Friendlier wrapping for any syntax errors that might occur.
33 throw new RuntimeException(
34 $fileName . ': ' . $e->getMessage()
38 $skipMessage = $this->ptRunner
->getFileSkipMessage(
39 false, /* parsoid tests */
40 $this->ptFileInfo
->fileOptions
,
43 // Don't bother doing anything else if a skip message is set.
44 if ( $skipMessage !== null ) {
48 // This is expected to be set at this point. $skipMessage above will have
49 // skipped the file if not.
50 $validTestModes = $this->ptRunner
->computeValidTestModes(
51 $this->ptRunner
->getRequestedTestModes(), $this->ptFileInfo
->fileOptions
);
54 $runnerOpts = $this->ptRunner
->getOptions();
55 foreach ( $this->ptFileInfo
->testCases
as $t ) {
56 $skipMessage = $this->ptRunner
->getTestSkipMessage( $t, false );
60 $testModes = $t->computeTestModes( $validTestModes );
61 $t->testAllModes( $testModes, $runner->getOptions(),
62 // $options is being ignored but it is identical to $runner->getOptions()
63 function ( ParserTest
$test, string $modeStr, array $options ) use (
64 $t, $suite, $fileName, $skipMessage
66 if ( $modeStr !== 'selser' ||
$test->changetree
!== null ) {
67 // $test could be a clone of $t
68 // Ensure that updates to knownFailures in $test are reflected in $t
69 $test->knownFailures
= &$t->knownFailures
;
70 $mode = new ParserTestMode( $modeStr, $test->changetree
);
71 $pit = new ParserIntegrationTest( $this->ptRunner
, $fileName, $test, $mode, $skipMessage );
72 $suite->addTest( $pit, [ 'Database', 'Parser', 'ParserTests' ] );
77 // Add a "selser-auto-composite" composite test
78 if ( in_array( 'selser', $testModes ) &&
79 ( $runnerOpts['selser'] ??
null ) !== 'noauto' &&
80 ( $t->options
['parsoid']['selser'] ??
null ) !== 'noauto'
82 $mode = new ParserTestMode( 'selser-auto-composite', $runnerOpts['changetree'] ??
null );
83 $pit = new ParserIntegrationTest( $runner, $fileName, $t, $mode, $skipMessage );
84 $suite->addTest( $pit, [ 'Database', 'Parser', 'ParserTests' ] );
89 protected function setUp(): void
{
90 $this->ptTeardownScope
= $this->ptRunner
->addArticles(
91 $this->ptFileInfo
->articles
95 protected function tearDown(): void
{
96 if ( $this->ptRunner
->getOptions()['updateKnownFailures'] ) {
97 $this->ptRunner
->updateKnownFailures( $this->ptFileInfo
);
100 if ( $this->ptTeardownScope
) {
101 ScopedCallback
::consume( $this->ptTeardownScope
);