Merge "Bump wikimedia/parsoid to 0.21.0-a11"
[mediawiki.git] / tests / phpunit / suites / ParsoidTestFileSuite.php
blob7fbf5d4583fbf98f179463c196c93f1d66c0feea
1 <?php
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;
9 /**
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 {
16 use SuiteEventsTrait;
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;
27 try {
28 $this->ptFileInfo = TestFileReader::read( $fileName, static function ( $msg ) {
29 wfDeprecatedMsg( $msg, '1.35', false, false );
30 } );
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,
41 $fileName
43 // Don't bother doing anything else if a skip message is set.
44 if ( $skipMessage !== null ) {
45 return;
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 );
53 $suite = $this;
54 $runnerOpts = $this->ptRunner->getOptions();
55 foreach ( $this->ptFileInfo->testCases as $t ) {
56 $skipMessage = $this->ptRunner->getTestSkipMessage( $t, false );
57 if ( $skipMessage ) {
58 continue;
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
65 ) {
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'
81 ) {
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 );