wiki.techinc.nl/tests/phpunit/suites/ParsoidTestFileSuite.php
libraryupgrader 5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00

81 lines
2.4 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
use PHPUnit\Framework\TestSuite;
use Wikimedia\ScopedCallback;
/**
* This is the suite class for running tests with Parsoid in integrated
* mode within a single .txt source file.
* It is not invoked directly. Use --filter to select files, or
* use parserTests.php.
*/
class ParsoidTestFileSuite extends TestSuite {
use SuiteEventsTrait;
private $ptRunner;
private $ptFileName;
private $ptFileInfo;
/** @var ScopedCallback */
private $ptTeardownScope;
public function __construct( $runner, $name, $fileName ) {
parent::__construct( $name );
$this->ptRunner = $runner;
$this->ptFileName = $fileName;
$this->ptFileInfo = Wikimedia\Parsoid\ParserTests\TestFileReader::read( $fileName, static function ( $msg ) {
wfDeprecatedMsg( $msg, '1.35', false, false );
} );
$fileOptions = $this->ptFileInfo->fileOptions;
if ( !isset( $fileOptions['parsoid-compatible'] ) ) {
// Running files in Parsoid integrated mode is opt-in for now.
$skipMessage = 'not compatible with Parsoid integrated mode';
} elseif ( !MediaWikiServices::getInstance()->hasService( 'ParsoidPageConfigFactory' ) ) {
// Disable integrated mode if Parsoid's services aren't available
// (Temporary measure until Parsoid is fully integrated in core.)
$skipMessage = 'Parsoid not available';
} elseif ( !$this->ptRunner->meetsRequirements( $fileOptions['requirements'] ?? [] ) ) {
$skipMessage = 'required extension not enabled';
} else {
$skipMessage = null;
}
foreach ( $this->ptFileInfo->testCases as $t ) {
$test = [
'test' => $t->testName,
'desc' => ( $t->comment ?? '' ) . $t->testName,
'input' => $t->wikitext,
'result' => $t->legacyHtml,
'options' => $t->options,
'config' => $t->config ?? '',
'line' => $t->lineNumStart,
'file' => $t->filename,
'parsoid' => $t,
];
$this->addTest( new ParserIntegrationTest( $runner, $fileName, $test, $skipMessage ),
[ 'Database', 'Parser', 'ParserTests' ] );
}
}
protected function setUp(): void {
$articles = [];
foreach ( $this->ptFileInfo->articles as $a ) {
$articles[] = [
'name' => $a->title,
'text' => $a->text,
'line' => $a->lineNumStart,
'file' => $a->filename,
];
}
$this->ptTeardownScope = $this->ptRunner->addArticles(
$articles
);
}
protected function tearDown(): void {
if ( $this->ptTeardownScope ) {
ScopedCallback::consume( $this->ptTeardownScope );
}
}
}