2012-01-09 22:33:00 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* Generic backend for the MediaWiki parser test suite, used by both the
|
|
|
|
|
* standalone parserTests.php and the PHPUnit "parsertests" suite.
|
2012-10-02 20:24:33 +00:00
|
|
|
*
|
2024-02-09 01:02:16 +00:00
|
|
|
* Copyright © 2004, 2010 Brooke Vibber <bvibber@wikimedia.org>
|
2014-03-20 15:45:01 +00:00
|
|
|
* https://www.mediawiki.org/
|
2012-10-02 20:24:33 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-01-09 22:33:00 +00:00
|
|
|
* @todo Make this more independent of the configuration (and if possible the database)
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Testing
|
|
|
|
|
*/
|
2019-07-04 10:01:31 +00:00
|
|
|
|
2024-08-06 13:40:20 +00:00
|
|
|
use MediaWiki\Content\WikitextContent;
|
2024-02-08 14:56:54 +00:00
|
|
|
use MediaWiki\Context\IContextSource;
|
|
|
|
|
use MediaWiki\Context\RequestContext;
|
2023-05-06 20:01:10 +00:00
|
|
|
use MediaWiki\HookContainer\HookRunner;
|
2023-02-16 19:27:21 +00:00
|
|
|
use MediaWiki\Html\Html;
|
2020-12-18 22:32:27 +00:00
|
|
|
use MediaWiki\Interwiki\ClassicInterwikiLookup;
|
2024-05-16 12:28:33 +00:00
|
|
|
use MediaWiki\Json\FormatJson;
|
2023-07-14 20:07:22 +00:00
|
|
|
use MediaWiki\Linker\LinkTarget;
|
2022-04-27 15:42:24 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2016-04-25 05:41:32 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-07-14 20:07:22 +00:00
|
|
|
use MediaWiki\Page\PageReferenceValue;
|
2023-12-13 22:50:44 +00:00
|
|
|
use MediaWiki\Parser\Parser;
|
2023-12-14 19:20:33 +00:00
|
|
|
use MediaWiki\Parser\ParserOutput;
|
2022-07-26 18:16:28 +00:00
|
|
|
use MediaWiki\Parser\ParserOutputFlags;
|
2023-07-14 19:18:01 +00:00
|
|
|
use MediaWiki\Permissions\UltimateAuthority;
|
2020-06-10 08:40:05 +00:00
|
|
|
use MediaWiki\Revision\MutableRevisionRecord;
|
2020-07-03 00:20:38 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2020-06-10 08:40:05 +00:00
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2023-08-06 11:10:37 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-09-18 13:56:39 +00:00
|
|
|
use MediaWiki\Title\TitleValue;
|
2023-09-19 12:13:45 +00:00
|
|
|
use MediaWiki\User\User;
|
2023-07-14 19:18:01 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
|
|
|
|
use MediaWiki\User\UserIdentityValue;
|
2023-08-19 03:35:06 +00:00
|
|
|
use MediaWiki\Utils\MWTimestamp;
|
2023-02-23 20:44:38 +00:00
|
|
|
use MediaWiki\WikiMap\WikiMap;
|
2021-03-31 16:50:45 +00:00
|
|
|
use Psr\Log\NullLogger;
|
2022-05-20 20:42:25 +00:00
|
|
|
use Wikimedia\Assert\Assert;
|
2024-05-19 13:40:05 +00:00
|
|
|
use Wikimedia\FileBackend\FileBackend;
|
2022-03-14 18:36:57 +00:00
|
|
|
use Wikimedia\Parsoid\Config\PageConfig;
|
2022-05-20 20:42:25 +00:00
|
|
|
use Wikimedia\Parsoid\Config\SiteConfig;
|
2023-12-22 17:28:24 +00:00
|
|
|
use Wikimedia\Parsoid\Core\LinkTarget as ParsoidLinkTarget;
|
2022-04-04 10:44:11 +00:00
|
|
|
use Wikimedia\Parsoid\Core\SelserData;
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
use Wikimedia\Parsoid\DOM\Document;
|
2022-05-20 20:42:25 +00:00
|
|
|
use Wikimedia\Parsoid\Ext\ExtensionModule;
|
|
|
|
|
use Wikimedia\Parsoid\ParserTests\Article as ParserTestArticle;
|
2020-07-24 04:41:09 +00:00
|
|
|
use Wikimedia\Parsoid\ParserTests\ParserHook as ParsoidParserHook;
|
|
|
|
|
use Wikimedia\Parsoid\ParserTests\RawHTML as ParsoidRawHTML;
|
|
|
|
|
use Wikimedia\Parsoid\ParserTests\StyleTag as ParsoidStyleTag;
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
use Wikimedia\Parsoid\ParserTests\Test as ParserTest;
|
2022-05-20 20:42:25 +00:00
|
|
|
use Wikimedia\Parsoid\ParserTests\TestFileReader;
|
2022-08-16 20:25:05 +00:00
|
|
|
use Wikimedia\Parsoid\ParserTests\TestMode as ParserTestMode;
|
2020-07-24 04:41:09 +00:00
|
|
|
use Wikimedia\Parsoid\Parsoid;
|
2022-04-04 10:44:11 +00:00
|
|
|
use Wikimedia\Parsoid\Utils\ContentUtils;
|
|
|
|
|
use Wikimedia\Parsoid\Utils\DOMCompat;
|
2022-05-20 20:42:25 +00:00
|
|
|
use Wikimedia\Parsoid\Utils\DOMDataUtils;
|
2022-03-15 11:15:18 +00:00
|
|
|
use Wikimedia\Parsoid\Utils\DOMUtils;
|
2022-05-27 20:38:32 +00:00
|
|
|
use Wikimedia\Rdbms\DBError;
|
|
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
2016-10-12 05:36:03 +00:00
|
|
|
use Wikimedia\ScopedCallback;
|
2017-06-27 21:09:12 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
2012-01-09 22:33:00 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ingroup Testing
|
|
|
|
|
*/
|
2016-09-08 01:07:06 +00:00
|
|
|
class ParserTestRunner {
|
2017-07-07 22:26:21 +00:00
|
|
|
|
2012-01-09 22:33:00 +00:00
|
|
|
/**
|
2024-01-20 19:24:35 +00:00
|
|
|
* @var array<string,bool> The status of each setup function
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
private $setupDone = [
|
|
|
|
|
'staticSetup' => false,
|
|
|
|
|
'perTestSetup' => false,
|
|
|
|
|
'setupDatabase' => false,
|
|
|
|
|
'setupUploads' => false,
|
|
|
|
|
];
|
2012-01-09 22:33:00 +00:00
|
|
|
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
/**
|
|
|
|
|
* @var array (CLI/Config) Options for the test runner
|
|
|
|
|
* See the constructor for documentation
|
|
|
|
|
*/
|
|
|
|
|
private $options;
|
|
|
|
|
|
|
|
|
|
/**
|
2024-01-20 19:24:35 +00:00
|
|
|
* @var string[] Set of requested test modes
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
*/
|
|
|
|
|
private $requestedTestModes;
|
|
|
|
|
|
2012-01-09 22:33:00 +00:00
|
|
|
/**
|
|
|
|
|
* Our connection to the database
|
2022-05-27 20:38:32 +00:00
|
|
|
* @var IDatabase
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
|
|
|
|
private $db;
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
/**
|
|
|
|
|
* @var TestRecorder
|
2016-07-26 09:39:15 +00:00
|
|
|
*/
|
|
|
|
|
private $recorder;
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
/**
|
|
|
|
|
* The upload directory, or null to not set up an upload directory
|
|
|
|
|
*
|
|
|
|
|
* @var string|null
|
|
|
|
|
*/
|
2012-01-09 22:33:00 +00:00
|
|
|
private $uploadDir = null;
|
|
|
|
|
|
|
|
|
|
/**
|
2022-03-08 11:40:54 +00:00
|
|
|
* The name of the file backend to use, or false to use MockFileBackend.
|
|
|
|
|
* @var string|false
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
private $fileBackendName;
|
2012-01-09 22:33:00 +00:00
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
/**
|
|
|
|
|
* A complete regex for filtering tests.
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $regex;
|
2012-01-09 22:33:00 +00:00
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
/**
|
|
|
|
|
* A list of normalization functions to apply to the expected and actual
|
|
|
|
|
* output.
|
2024-01-20 19:24:35 +00:00
|
|
|
* @var string[]
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
*/
|
|
|
|
|
private $normalizationFunctions = [];
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2018-07-20 02:03:48 +00:00
|
|
|
/**
|
|
|
|
|
* Run disabled parser tests
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
private $runDisabled;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Disable parse on article insertion
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
private $disableSaveParse;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reuse upload directory
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
private $keepUploads;
|
|
|
|
|
|
2022-07-27 18:18:17 +00:00
|
|
|
/**
|
|
|
|
|
* Did some Parsoid test pass where it was expected to fail?
|
|
|
|
|
* This can happen if the test failure is recorded in the -knownFailures.json file
|
|
|
|
|
* but the test result changed, or functionality changed that causes tests to pass.
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
public $unexpectedTestPasses = false;
|
|
|
|
|
|
2020-12-23 18:52:12 +00:00
|
|
|
/**
|
|
|
|
|
* Table name prefix.
|
|
|
|
|
*/
|
|
|
|
|
public const DB_PREFIX = 'parsertest_';
|
|
|
|
|
|
2023-04-13 23:09:39 +00:00
|
|
|
/** @var string */
|
|
|
|
|
private const FILTER_MSG = "Test doesn't match filter";
|
|
|
|
|
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
/**
|
|
|
|
|
* Compute the set of valid test runner modes
|
|
|
|
|
*
|
2024-01-20 19:24:35 +00:00
|
|
|
* @return string[]
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
*/
|
|
|
|
|
public function getRequestedTestModes(): array {
|
|
|
|
|
return $this->requestedTestModes;
|
|
|
|
|
}
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
/**
|
|
|
|
|
* @param TestRecorder $recorder
|
|
|
|
|
* @param array $options
|
2022-05-14 05:06:03 +00:00
|
|
|
* - parsoid (bool) if true, run Parsoid tests
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
* - testFile (string)
|
|
|
|
|
* If set, the (Parsoid) test file to run tests from.
|
|
|
|
|
* Currently, only used for CLI PHPUnit test runs
|
|
|
|
|
* to avoid running every single test file out there.
|
|
|
|
|
* Legacy parser test runs ignore this option.
|
|
|
|
|
* - wt2html (bool) If true, run Parsoid wt2html tests
|
|
|
|
|
* - wt2wt (bool) If true, run Parsoid wt2wt tests
|
|
|
|
|
* - html2wt (bool) If true, run Parsoid html2wt tests
|
|
|
|
|
* - html2html (bool) If true, run Parsoid html2html tests
|
|
|
|
|
* - selser (bool/"noauto")
|
|
|
|
|
* If true, run Parsoid auto-generated selser tests
|
|
|
|
|
* If "noauto", run Parsoid manual edit selser tests
|
2022-05-14 05:06:03 +00:00
|
|
|
* - numchanges (int) number of selser edit tests to generate
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
* - changetree (array|null)
|
|
|
|
|
* If not null, run a Parsoid selser edit test with this changetree
|
|
|
|
|
* - updateKnownFailures (bool)
|
|
|
|
|
* If true, *knownFailures.json files are updated
|
2022-10-03 16:44:33 +00:00
|
|
|
* - traceFlags (array)
|
|
|
|
|
* (Parsoid-only) Flags for tracing different Parsoid stages
|
|
|
|
|
* - dumpFlags (array)
|
|
|
|
|
* (Parsoid-only) Flags for dumping various pieces of state
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
* - norm (array)
|
|
|
|
|
* An array of normalization functions to run on test output
|
|
|
|
|
* to use in legacy parser test runs
|
|
|
|
|
* - regex (string) Regex for filtering tests
|
|
|
|
|
* - run-disabled (bool) If true, run disabled tests
|
|
|
|
|
* - keep-uploads (bool) If true, reuse upload directory
|
|
|
|
|
* - file-backend (string|bool)
|
|
|
|
|
* If false, use MockFileBackend
|
|
|
|
|
* Else name of the file backend to use
|
|
|
|
|
* - disable-save-parse (bool) if true, disable parse on article insertion
|
2023-03-21 21:51:43 +00:00
|
|
|
* - update-tests (bool) Update parserTests.txt with results from wt2html fails.
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
*
|
|
|
|
|
* NOTE: At this time, Parsoid-specific test options are only handled
|
|
|
|
|
* in PHPUnit mode. A future patch will likely tweak some of this and
|
|
|
|
|
* support these flags no matter how this test runner is instantiated.
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct( TestRecorder $recorder, $options = [] ) {
|
|
|
|
|
$this->recorder = $recorder;
|
2022-05-20 21:36:02 +00:00
|
|
|
$this->options = $options + [
|
|
|
|
|
'keep-uploads' => false,
|
|
|
|
|
'file-backend' => false,
|
|
|
|
|
'run-disabled' => false,
|
|
|
|
|
'disable-save-parse' => false,
|
|
|
|
|
'upload-dir' => null,
|
|
|
|
|
'regex' => false,
|
|
|
|
|
'norm' => [],
|
|
|
|
|
// Parsoid-specific options
|
|
|
|
|
'parsoid' => false,
|
|
|
|
|
'knownFailures' => true,
|
|
|
|
|
'updateKnownFailures' => false,
|
|
|
|
|
'changetree' => null,
|
2023-03-21 21:51:43 +00:00
|
|
|
'update-tests' => false,
|
2022-05-20 20:42:25 +00:00
|
|
|
// Options can also match those in ParserTestModes::TEST_MODES
|
|
|
|
|
// but we don't need to initialize those here; they will be
|
|
|
|
|
// accessed via $this->requestedTestModes instead.
|
2022-10-03 16:44:33 +00:00
|
|
|
'traceFlags' => [],
|
|
|
|
|
'dumpFlags' => [],
|
2022-05-20 21:36:02 +00:00
|
|
|
];
|
2022-10-03 16:44:33 +00:00
|
|
|
|
2022-05-20 21:36:02 +00:00
|
|
|
// Requested test modes are used for Parsoid tests and ignored for
|
|
|
|
|
// legacy parser tests.
|
2022-05-20 20:42:25 +00:00
|
|
|
$this->requestedTestModes = ParserTestMode::requestedTestModes(
|
|
|
|
|
$this->options
|
|
|
|
|
);
|
2022-05-20 21:36:02 +00:00
|
|
|
|
2022-10-03 16:44:33 +00:00
|
|
|
$normFuncs = $this->options['norm'];
|
|
|
|
|
'@phan-var string[] $normFuncs';
|
|
|
|
|
foreach ( $normFuncs as $func ) {
|
2022-05-20 21:36:02 +00:00
|
|
|
if ( in_array( $func, [ 'removeTbody', 'trimWhitespace' ] ) ) {
|
|
|
|
|
$this->normalizationFunctions[] = $func;
|
|
|
|
|
} else {
|
|
|
|
|
$this->recorder->warning(
|
|
|
|
|
"Warning: unknown normalization option \"$func\"\n" );
|
2016-03-09 04:42:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2022-05-20 21:36:02 +00:00
|
|
|
if ( $this->options['regex'] !== false ) {
|
|
|
|
|
$this->regex = $this->options['regex'];
|
2012-01-09 22:33:00 +00:00
|
|
|
} else {
|
|
|
|
|
# Matches anything
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$this->regex = '//';
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-20 21:36:02 +00:00
|
|
|
$this->keepUploads = (bool)$this->options['keep-uploads'];
|
|
|
|
|
$this->fileBackendName = $this->options['file-backend'];
|
|
|
|
|
$this->runDisabled = (bool)$this->options['run-disabled'];
|
|
|
|
|
$this->disableSaveParse = (bool)$this->options['disable-save-parse'];
|
|
|
|
|
$this->uploadDir = $this->options['upload-dir'];
|
2023-07-13 17:12:45 +00:00
|
|
|
}
|
2019-07-04 10:01:31 +00:00
|
|
|
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getOptions(): array {
|
|
|
|
|
return $this->options;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-07 22:26:21 +00:00
|
|
|
/**
|
|
|
|
|
* Get list of filenames to extension and core parser tests
|
|
|
|
|
*
|
2024-01-20 19:24:35 +00:00
|
|
|
* @param string[] $dirs
|
|
|
|
|
* @return string[]
|
2017-07-07 22:26:21 +00:00
|
|
|
*/
|
2022-10-24 18:05:51 +00:00
|
|
|
public static function getParserTestFiles( array $dirs = [] ): array {
|
|
|
|
|
if ( $dirs ) {
|
|
|
|
|
$ptDirs = [];
|
|
|
|
|
foreach ( $dirs as $i => $dir ) {
|
|
|
|
|
if ( !is_dir( $dir ) ) {
|
|
|
|
|
echo "$dir is not a directory. Skipping it.\n";
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$ptDirs["_CLI{$i}_"] = $dir;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Auto-discover core test files
|
|
|
|
|
$ptDirs = [ 'core' => __DIR__ ];
|
2017-07-07 22:26:21 +00:00
|
|
|
|
2022-10-24 18:05:51 +00:00
|
|
|
// Auto-discover extension parser tests
|
|
|
|
|
$registry = ExtensionRegistry::getInstance();
|
|
|
|
|
foreach ( $registry->getAllThings() as $info ) {
|
|
|
|
|
$dir = dirname( $info['path'] ) . '/tests/parser';
|
|
|
|
|
if ( !is_dir( $dir ) ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$ptDirs[ $info['name'] ] = $dir;
|
2017-07-07 22:26:21 +00:00
|
|
|
}
|
2022-10-12 21:09:59 +00:00
|
|
|
}
|
2022-10-24 18:05:51 +00:00
|
|
|
|
2022-10-12 21:09:59 +00:00
|
|
|
$files = [];
|
|
|
|
|
foreach ( $ptDirs as $extName => $dir ) {
|
2017-07-08 07:14:13 +00:00
|
|
|
$counter = 1;
|
2017-07-07 22:26:21 +00:00
|
|
|
$dirIterator = new RecursiveIteratorIterator(
|
|
|
|
|
new RecursiveDirectoryIterator( $dir )
|
|
|
|
|
);
|
|
|
|
|
foreach ( $dirIterator as $fileInfo ) {
|
|
|
|
|
/** @var SplFileInfo $fileInfo */
|
2022-04-13 13:44:41 +00:00
|
|
|
if ( str_ends_with( $fileInfo->getFilename(), '.txt' ) ) {
|
2022-10-12 21:09:59 +00:00
|
|
|
$name = $extName . '_' . $counter;
|
2017-07-08 07:14:13 +00:00
|
|
|
while ( isset( $files[$name] ) ) {
|
2020-07-24 04:07:56 +00:00
|
|
|
$counter++;
|
2022-10-12 21:09:59 +00:00
|
|
|
$name = $extName . '_' . $counter;
|
2017-07-08 07:14:13 +00:00
|
|
|
}
|
|
|
|
|
$files[$name] = $fileInfo->getPathname();
|
2017-07-07 22:26:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return array_unique( $files );
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-01 16:48:16 +00:00
|
|
|
public function getRecorder(): TestRecorder {
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
return $this->recorder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Do any setup which can be done once for all tests, independent of test
|
|
|
|
|
* options, except for database setup.
|
|
|
|
|
*
|
|
|
|
|
* Public setup functions in this class return a ScopedCallback object. When
|
|
|
|
|
* this object is destroyed by going out of scope, teardown of the
|
|
|
|
|
* corresponding test setup is performed.
|
|
|
|
|
*
|
|
|
|
|
* Teardown objects may be chained by passing a ScopedCallback from a
|
|
|
|
|
* previous setup stage as the $nextTeardown parameter. This enforces the
|
|
|
|
|
* convention that teardown actions are taken in reverse order to the
|
|
|
|
|
* corresponding setup actions. When $nextTeardown is specified, a
|
|
|
|
|
* ScopedCallback will be returned which first tears down the current
|
|
|
|
|
* setup stage, and then tears down the previous setup stage which was
|
|
|
|
|
* specified by $nextTeardown.
|
|
|
|
|
*
|
|
|
|
|
* @param ScopedCallback|null $nextTeardown
|
|
|
|
|
* @return ScopedCallback
|
|
|
|
|
*/
|
|
|
|
|
public function staticSetup( $nextTeardown = null ) {
|
|
|
|
|
// A note on coding style:
|
|
|
|
|
|
|
|
|
|
// The general idea here is to keep setup code together with
|
|
|
|
|
// corresponding teardown code, in a fine-grained manner. We have two
|
|
|
|
|
// arrays: $setup and $teardown. The code snippets in the $setup array
|
|
|
|
|
// are executed at the end of the method, before it returns, and the
|
|
|
|
|
// code snippets in the $teardown array are executed in reverse order
|
2016-10-12 05:36:03 +00:00
|
|
|
// when the Wikimedia\ScopedCallback object is consumed.
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
|
|
|
|
|
// Because it is a common operation to save, set and restore global
|
|
|
|
|
// variables, we have an additional convention: when the array key of
|
|
|
|
|
// $setup is a string, the string is taken to be the name of the global
|
|
|
|
|
// variable, and the element value is taken to be the desired new value.
|
|
|
|
|
|
|
|
|
|
// It's acceptable to just do the setup immediately, instead of adding
|
|
|
|
|
// a closure to $setup, except when the setup action depends on global
|
|
|
|
|
// variable initialisation being done first. In this case, you have to
|
|
|
|
|
// append a closure to $setup after the global variable is appended.
|
|
|
|
|
|
|
|
|
|
// When you add to setup functions in this class, please keep associated
|
|
|
|
|
// setup and teardown actions together in the source code, and please
|
|
|
|
|
// add comments explaining why the setup action is necessary.
|
|
|
|
|
|
|
|
|
|
$setup = [];
|
|
|
|
|
$teardown = [];
|
|
|
|
|
|
|
|
|
|
$teardown[] = $this->markSetupDone( 'staticSetup' );
|
|
|
|
|
|
|
|
|
|
// Some settings which influence HTML output
|
|
|
|
|
$setup['wgSitename'] = 'MediaWiki';
|
2021-12-03 00:41:33 +00:00
|
|
|
$setup['wgMetaNamespace'] = "TestWiki";
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$setup['wgServer'] = 'http://example.org';
|
|
|
|
|
$setup['wgServerName'] = 'example.org';
|
|
|
|
|
$setup['wgCapitalLinks'] = true;
|
|
|
|
|
$setup['wgNoFollowLinks'] = true;
|
|
|
|
|
$setup['wgNoFollowDomainExceptions'] = [ 'no-nofollow.org' ];
|
|
|
|
|
$setup['wgExternalLinkTarget'] = false;
|
|
|
|
|
$setup['wgLocaltimezone'] = 'UTC';
|
2023-07-29 19:21:04 +00:00
|
|
|
$reset = static function () {
|
|
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'UrlUtils' );
|
|
|
|
|
};
|
|
|
|
|
$setup[] = $reset;
|
|
|
|
|
$teardown[] = $reset;
|
2023-03-17 08:54:00 +00:00
|
|
|
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
// Language and variant settings
|
|
|
|
|
$setup['wgLanguageCode'] = 'en';
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$setup['wgDisableLangConversion'] = false;
|
|
|
|
|
$setup['wgDisableTitleConversion'] = false;
|
2020-09-17 00:31:54 +00:00
|
|
|
$setup['wgUsePigLatinVariant'] = false;
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
$this->resetLanguageServices( $setup, $teardown, true );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
|
|
|
|
|
// "extra language links"
|
|
|
|
|
// see https://gerrit.wikimedia.org/r/111390
|
|
|
|
|
$setup['wgExtraInterlanguageLinkPrefixes'] = [ 'mul' ];
|
|
|
|
|
|
|
|
|
|
// All FileRepo changes should be done here by injecting services,
|
|
|
|
|
// there should be no need to change global variables.
|
2019-05-01 12:54:54 +00:00
|
|
|
MediaWikiServices::getInstance()->disableService( 'RepoGroup' );
|
|
|
|
|
MediaWikiServices::getInstance()->redefineService( 'RepoGroup',
|
|
|
|
|
function () {
|
|
|
|
|
return $this->createRepoGroup();
|
|
|
|
|
}
|
|
|
|
|
);
|
2021-02-06 19:40:52 +00:00
|
|
|
$teardown[] = static function () {
|
2019-05-01 12:54:54 +00:00
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'RepoGroup' );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Set up null lock managers
|
|
|
|
|
$setup['wgLockManagers'] = [ [
|
2013-02-14 11:22:13 +00:00
|
|
|
'name' => 'fsLockManager',
|
2018-01-13 00:02:09 +00:00
|
|
|
'class' => NullLockManager::class,
|
2016-02-17 09:09:32 +00:00
|
|
|
], [
|
2013-02-14 11:22:13 +00:00
|
|
|
'name' => 'nullLockManager',
|
2018-01-13 00:02:09 +00:00
|
|
|
'class' => NullLockManager::class,
|
2016-02-17 09:09:32 +00:00
|
|
|
] ];
|
2021-02-06 19:40:52 +00:00
|
|
|
$reset = static function () {
|
2019-08-15 18:07:36 +00:00
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'LockManagerGroupFactory' );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
};
|
|
|
|
|
$setup[] = $reset;
|
|
|
|
|
$teardown[] = $reset;
|
|
|
|
|
|
|
|
|
|
// This allows article insertion into the prefixed DB
|
|
|
|
|
$setup['wgDefaultExternalStore'] = false;
|
|
|
|
|
|
|
|
|
|
// This might slightly reduce memory usage
|
|
|
|
|
$setup['wgAdaptiveMessageCache'] = true;
|
|
|
|
|
|
|
|
|
|
// This is essential and overrides disabling of database messages in TestSetup
|
|
|
|
|
$setup['wgUseDatabaseMessages'] = true;
|
2021-02-06 19:40:52 +00:00
|
|
|
$reset = static function () {
|
2019-04-08 15:21:49 +00:00
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'MessageCache' );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
};
|
|
|
|
|
$setup[] = $reset;
|
|
|
|
|
$teardown[] = $reset;
|
|
|
|
|
|
|
|
|
|
// It's not necessary to actually convert any files
|
|
|
|
|
$setup['wgSVGConverter'] = 'null';
|
|
|
|
|
$setup['wgSVGConverters'] = [ 'null' => 'echo "1">$output' ];
|
|
|
|
|
|
|
|
|
|
// Fake constant timestamp
|
2024-06-04 17:55:10 +00:00
|
|
|
$teardown[] = $this->registerHook(
|
2021-04-30 22:30:46 +00:00
|
|
|
'ParserGetVariableValueTs',
|
|
|
|
|
function ( $parser, &$ts ) {
|
|
|
|
|
$ts = $this->getFakeTimestamp();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
);
|
2020-04-14 17:56:55 +00:00
|
|
|
|
2024-06-04 17:55:10 +00:00
|
|
|
// Fake specific translated language names, for testing {{#language}}
|
|
|
|
|
$teardown[] = $this->registerHook(
|
|
|
|
|
'LanguageGetTranslatedLanguageNames',
|
|
|
|
|
static function ( &$names, $code ) {
|
|
|
|
|
if ( $code === 'en' || $code === 'simple' ) {
|
|
|
|
|
$names['ar'] = 'Arabic';
|
|
|
|
|
$names['de-formal'] = 'German (formal address)';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
|
|
|
|
|
$this->appendNamespaceSetup( $setup, $teardown );
|
|
|
|
|
|
|
|
|
|
// Set up interwikis and append teardown function
|
2020-12-18 22:32:27 +00:00
|
|
|
$this->appendInterwikiSetup( $setup, $teardown );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
|
|
|
|
|
// Set up a mock MediaHandlerFactory
|
|
|
|
|
MediaWikiServices::getInstance()->disableService( 'MediaHandlerFactory' );
|
|
|
|
|
MediaWikiServices::getInstance()->redefineService(
|
|
|
|
|
'MediaHandlerFactory',
|
2021-02-07 13:10:36 +00:00
|
|
|
static function ( MediaWikiServices $services ) {
|
2022-04-27 15:42:24 +00:00
|
|
|
$handlers = $services->getMainConfig()->get( MainConfigNames::ParserTestMediaHandlers );
|
2021-03-31 16:50:45 +00:00
|
|
|
return new MediaHandlerFactory(
|
|
|
|
|
new NullLogger(),
|
|
|
|
|
$handlers
|
|
|
|
|
);
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
}
|
|
|
|
|
);
|
2021-02-06 19:40:52 +00:00
|
|
|
$teardown[] = static function () {
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'MediaHandlerFactory' );
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$teardown[] = $this->executeSetupSnippets( $setup );
|
|
|
|
|
|
|
|
|
|
// Schedule teardown snippets in reverse order
|
|
|
|
|
return $this->createTeardownObject( $teardown, $nextTeardown );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function appendNamespaceSetup( &$setup, &$teardown ) {
|
|
|
|
|
// Add a namespace shadowing a interwiki link, to test
|
2017-02-20 23:45:58 +00:00
|
|
|
// proper precedence when resolving links. (T53680)
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$setup['wgExtraNamespaces'] = [
|
|
|
|
|
100 => 'MemoryAlpha',
|
|
|
|
|
101 => 'MemoryAlpha_talk'
|
|
|
|
|
];
|
2018-08-05 08:36:32 +00:00
|
|
|
// Changing wgExtraNamespaces invalidates caches in NamespaceInfo and any live Language
|
|
|
|
|
// object, both on setup and teardown
|
2021-02-06 19:40:52 +00:00
|
|
|
$reset = static function () {
|
2022-03-11 22:54:37 +00:00
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'MainConfig' );
|
2018-08-05 08:36:32 +00:00
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'NamespaceInfo' );
|
2022-03-11 22:54:37 +00:00
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'LanguageFactory' );
|
|
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'ContentLanguage' );
|
|
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'LanguageConverterFactory' );
|
2024-01-26 23:07:27 +00:00
|
|
|
// Don't destroy the link cache, because various things hold a
|
|
|
|
|
// copy of it. Just clear it.
|
|
|
|
|
MediaWikiServices::getInstance()->getLinkCache()->clear();
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
};
|
|
|
|
|
$setup[] = $reset;
|
|
|
|
|
$teardown[] = $reset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a RepoGroup object appropriate for the current configuration
|
|
|
|
|
* @return RepoGroup
|
|
|
|
|
*/
|
|
|
|
|
protected function createRepoGroup() {
|
|
|
|
|
if ( $this->uploadDir ) {
|
|
|
|
|
if ( $this->fileBackendName ) {
|
2023-06-03 15:25:27 +00:00
|
|
|
throw new RuntimeException( 'You cannot specify both use-filebackend and upload-dir' );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
}
|
|
|
|
|
$backend = new FSFileBackend( [
|
2013-02-14 11:22:13 +00:00
|
|
|
'name' => 'local-backend',
|
2021-12-21 00:47:14 +00:00
|
|
|
'wikiId' => WikiMap::getCurrentWikiId(),
|
2016-09-19 01:39:59 +00:00
|
|
|
'basePath' => $this->uploadDir,
|
|
|
|
|
'tmpDirectory' => wfTempDir()
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
] );
|
|
|
|
|
} elseif ( $this->fileBackendName ) {
|
|
|
|
|
global $wgFileBackends;
|
|
|
|
|
$name = $this->fileBackendName;
|
|
|
|
|
$useConfig = false;
|
|
|
|
|
foreach ( $wgFileBackends as $conf ) {
|
|
|
|
|
if ( $conf['name'] === $name ) {
|
|
|
|
|
$useConfig = $conf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( $useConfig === false ) {
|
2023-06-03 15:25:27 +00:00
|
|
|
throw new RuntimeException( "Unable to find file backend \"$name\"" );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
}
|
|
|
|
|
$useConfig['name'] = 'local-backend'; // swap name
|
|
|
|
|
unset( $useConfig['lockManager'] );
|
|
|
|
|
$class = $useConfig['class'];
|
2022-06-01 21:19:57 +00:00
|
|
|
// @phan-suppress-next-line PhanInvalidFQSENInClasslike
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$backend = new $class( $useConfig );
|
|
|
|
|
} else {
|
|
|
|
|
# Replace with a mock. We do not care about generating real
|
|
|
|
|
# files on the filesystem, just need to expose the file
|
|
|
|
|
# informations.
|
|
|
|
|
$backend = new MockFileBackend( [
|
|
|
|
|
'name' => 'local-backend',
|
2021-12-21 00:47:14 +00:00
|
|
|
'wikiId' => WikiMap::getCurrentWikiId()
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
] );
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
|
2021-08-13 11:46:31 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
return new RepoGroup(
|
|
|
|
|
[
|
2018-01-13 00:02:09 +00:00
|
|
|
'class' => MockLocalRepo::class,
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
'name' => 'local',
|
|
|
|
|
'url' => 'http://example.com/images',
|
|
|
|
|
'hashLevels' => 2,
|
|
|
|
|
'transformVia404' => false,
|
|
|
|
|
'backend' => $backend
|
|
|
|
|
],
|
2019-05-01 12:54:54 +00:00
|
|
|
[],
|
2021-08-13 11:46:31 +00:00
|
|
|
$services->getMainWANObjectCache(),
|
|
|
|
|
$services->getMimeAnalyzer()
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute an array in which elements with integer keys are taken to be
|
|
|
|
|
* callable objects, and other elements are taken to be global variable
|
|
|
|
|
* set operations, with the key giving the variable name and the value
|
|
|
|
|
* giving the new global variable value. A closure is returned which, when
|
|
|
|
|
* executed, sets the global variables back to the values they had before
|
|
|
|
|
* this function was called.
|
|
|
|
|
*
|
|
|
|
|
* @see staticSetup
|
|
|
|
|
*
|
|
|
|
|
* @param array $setup
|
|
|
|
|
* @return closure
|
|
|
|
|
*/
|
|
|
|
|
protected function executeSetupSnippets( $setup ) {
|
|
|
|
|
$saved = [];
|
|
|
|
|
foreach ( $setup as $name => $value ) {
|
|
|
|
|
if ( is_int( $name ) ) {
|
|
|
|
|
$value();
|
|
|
|
|
} else {
|
2017-10-06 22:17:58 +00:00
|
|
|
$saved[$name] = $GLOBALS[$name] ?? null;
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$GLOBALS[$name] = $value;
|
|
|
|
|
}
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
return function () use ( $saved ) {
|
|
|
|
|
$this->executeSetupSnippets( $saved );
|
|
|
|
|
};
|
|
|
|
|
}
|
2012-01-09 22:33:00 +00:00
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
/**
|
|
|
|
|
* Take a setup array in the same format as the one given to
|
|
|
|
|
* executeSetupSnippets(), and return a ScopedCallback which, when consumed,
|
|
|
|
|
* executes the snippets in the setup array in reverse order. This is used
|
|
|
|
|
* to create "teardown objects" for the public API.
|
|
|
|
|
*
|
|
|
|
|
* @see staticSetup
|
|
|
|
|
*
|
|
|
|
|
* @param array $teardown The snippet array
|
2017-08-11 16:09:41 +00:00
|
|
|
* @param ScopedCallback|null $nextTeardown A ScopedCallback to consume
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* @return ScopedCallback
|
|
|
|
|
*/
|
2020-12-21 22:30:52 +00:00
|
|
|
protected function createTeardownObject(
|
|
|
|
|
array $teardown, ?ScopedCallback $nextTeardown = null
|
|
|
|
|
) {
|
2017-06-26 16:35:31 +00:00
|
|
|
return new ScopedCallback( function () use ( $teardown, $nextTeardown ) {
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
// Schedule teardown snippets in reverse order
|
|
|
|
|
$teardown = array_reverse( $teardown );
|
|
|
|
|
|
|
|
|
|
$this->executeSetupSnippets( $teardown );
|
|
|
|
|
if ( $nextTeardown ) {
|
|
|
|
|
ScopedCallback::consume( $nextTeardown );
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-04 17:55:10 +00:00
|
|
|
protected function registerHook( string $name, callable $handler ) {
|
|
|
|
|
$hookContainer = MediaWikiServices::getInstance()->getHookContainer();
|
|
|
|
|
$reset = $hookContainer->scopedRegister( $name, $handler );
|
|
|
|
|
return static function () use ( &$reset ) {
|
|
|
|
|
ScopedCallback::consume( $reset );
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
/**
|
|
|
|
|
* Set a setupDone flag to indicate that setup has been done, and return
|
|
|
|
|
* the teardown closure. If the flag was already set, throw an exception.
|
|
|
|
|
*
|
|
|
|
|
* @param string $funcName The setup function name
|
|
|
|
|
* @return closure
|
|
|
|
|
*/
|
|
|
|
|
protected function markSetupDone( $funcName ) {
|
|
|
|
|
if ( $this->setupDone[$funcName] ) {
|
2023-06-03 15:25:27 +00:00
|
|
|
throw new RuntimeException( "$funcName is already done" );
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$this->setupDone[$funcName] = true;
|
|
|
|
|
return function () use ( $funcName ) {
|
|
|
|
|
$this->setupDone[$funcName] = false;
|
|
|
|
|
};
|
|
|
|
|
}
|
2014-07-21 02:35:50 +00:00
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
/**
|
2019-11-03 04:42:01 +00:00
|
|
|
* Ensure one of the given setup stages has been done, throw an exception otherwise.
|
2017-09-09 20:47:04 +00:00
|
|
|
* @param string $funcName
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
*/
|
2020-12-23 18:52:12 +00:00
|
|
|
protected function checkSetupDone( string $funcName ) {
|
|
|
|
|
if ( !$this->setupDone[$funcName] ) {
|
2023-06-03 15:25:27 +00:00
|
|
|
throw new BadMethodCallException( "$funcName must be called before calling " . wfGetCaller() );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-04-07 05:20:38 +00:00
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
/**
|
|
|
|
|
* Determine whether a particular setup function has been run
|
|
|
|
|
*
|
|
|
|
|
* @param string $funcName
|
2017-08-20 11:20:59 +00:00
|
|
|
* @return bool
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
*/
|
|
|
|
|
public function isSetupDone( $funcName ) {
|
2017-10-06 22:17:58 +00:00
|
|
|
return $this->setupDone[$funcName] ?? false;
|
2013-05-20 13:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Insert hardcoded interwiki in the lookup table.
|
|
|
|
|
*
|
|
|
|
|
* This function insert a set of well known interwikis that are used in
|
2020-12-18 22:32:27 +00:00
|
|
|
* the parser tests. We use the $wgInterwikiCache mechanism to completely
|
|
|
|
|
* replace any other lookup. (Note that the InterwikiLoadPrefix hook
|
|
|
|
|
* isn't used because it doesn't alter the result of
|
|
|
|
|
* Interwiki::getAllPrefixes() and so is incompatible with some users,
|
|
|
|
|
* including Parsoid.)
|
2021-01-16 19:44:17 +00:00
|
|
|
* @param array &$setup
|
|
|
|
|
* @param array &$teardown
|
2013-05-20 13:21:02 +00:00
|
|
|
*/
|
2020-12-18 22:32:27 +00:00
|
|
|
private function appendInterwikiSetup( &$setup, &$teardown ) {
|
|
|
|
|
static $testInterwikis = [
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'local',
|
2021-10-14 00:32:35 +00:00
|
|
|
// This is a "local interwiki" (see wgLocalInterwikis elsewhere in this file)
|
|
|
|
|
'iw_url' => 'http://example.org/wiki/$1',
|
|
|
|
|
'iw_local' => 1,
|
2020-12-18 22:32:27 +00:00
|
|
|
],
|
2021-12-03 00:41:33 +00:00
|
|
|
// Local interwiki that matches a namespace name (T228616)
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'project',
|
2021-10-14 00:32:35 +00:00
|
|
|
// This is a "local interwiki" (see wgLocalInterwikis elsewhere in this file)
|
|
|
|
|
'iw_url' => 'http://example.org/wiki/$1',
|
|
|
|
|
'iw_local' => 1,
|
2021-12-03 00:41:33 +00:00
|
|
|
],
|
2020-12-18 22:32:27 +00:00
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'wikipedia',
|
|
|
|
|
'iw_url' => 'http://en.wikipedia.org/wiki/$1',
|
|
|
|
|
'iw_local' => 0,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'meatball',
|
|
|
|
|
// this has been updated in the live wikis, but the parser tests
|
|
|
|
|
// expect the old value
|
|
|
|
|
'iw_url' => 'http://www.usemod.com/cgi-bin/mb.pl?$1',
|
|
|
|
|
'iw_local' => 0,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'memoryalpha',
|
|
|
|
|
'iw_url' => 'http://www.memory-alpha.org/en/index.php/$1',
|
|
|
|
|
'iw_local' => 0,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'zh',
|
|
|
|
|
'iw_url' => 'http://zh.wikipedia.org/wiki/$1',
|
|
|
|
|
'iw_local' => 1,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'es',
|
|
|
|
|
'iw_url' => 'http://es.wikipedia.org/wiki/$1',
|
|
|
|
|
'iw_local' => 1,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'fr',
|
|
|
|
|
'iw_url' => 'http://fr.wikipedia.org/wiki/$1',
|
|
|
|
|
'iw_local' => 1,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'ru',
|
|
|
|
|
'iw_url' => 'http://ru.wikipedia.org/wiki/$1',
|
|
|
|
|
'iw_local' => 1,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'mi',
|
2021-10-14 00:32:35 +00:00
|
|
|
// This is a "local interwiki" (see wgLocalInterwikis elsewhere in this file)
|
|
|
|
|
'iw_url' => 'http://example.org/wiki/$1',
|
2020-12-18 22:32:27 +00:00
|
|
|
'iw_local' => 1,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'mul',
|
|
|
|
|
'iw_url' => 'http://wikisource.org/wiki/$1',
|
|
|
|
|
'iw_local' => 1,
|
|
|
|
|
],
|
2020-12-18 23:50:51 +00:00
|
|
|
// Additions from Parsoid
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'en',
|
2022-06-07 22:42:27 +00:00
|
|
|
'iw_url' => '//en.wikipedia.org/wiki/$1',
|
|
|
|
|
'iw_local' => 1
|
2020-12-18 23:50:51 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'stats',
|
|
|
|
|
'iw_url' => 'https://stats.wikimedia.org/$1',
|
|
|
|
|
'iw_local' => 1,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'gerrit',
|
|
|
|
|
'iw_url' => 'https://gerrit.wikimedia.org/$1',
|
|
|
|
|
'iw_local' => 1,
|
|
|
|
|
],
|
2023-12-15 00:31:40 +00:00
|
|
|
// Added to support T145590#8608455
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'pmid',
|
|
|
|
|
'iw_url' => '//www.ncbi.nlm.nih.gov/pubmed/$1?dopt=Abstract',
|
|
|
|
|
'iw_local' => 1,
|
|
|
|
|
],
|
2020-12-18 23:50:51 +00:00
|
|
|
// Deliberately missing a $1 in the URL to exercise a common
|
|
|
|
|
// misconfiguration.
|
|
|
|
|
[
|
|
|
|
|
'iw_prefix' => 'wikinvest',
|
|
|
|
|
'iw_url' => 'https://meta.wikimedia.org/wiki/Interwiki_map/discontinued#Wikinvest',
|
|
|
|
|
'iw_local' => 1,
|
|
|
|
|
],
|
2020-12-18 22:32:27 +00:00
|
|
|
];
|
|
|
|
|
// When running from parserTests.php, database setup happens *after*
|
|
|
|
|
// interwiki setup, and that changes the wiki id. In order to avoid
|
|
|
|
|
// breaking the interwiki cache, use 'global scope' for the interwiki
|
|
|
|
|
// lookup.
|
|
|
|
|
$GLOBAL_SCOPE = 2; // See docs for $wgInterwikiScopes
|
|
|
|
|
$setup['wgInterwikiScopes'] = $GLOBAL_SCOPE;
|
|
|
|
|
$setup['wgInterwikiCache'] =
|
|
|
|
|
ClassicInterwikiLookup::buildCdbHash( $testInterwikis, $GLOBAL_SCOPE );
|
2021-02-06 19:40:52 +00:00
|
|
|
$reset = static function () {
|
2020-12-18 22:32:27 +00:00
|
|
|
// Reset the service in case any other tests already cached some prefixes.
|
2018-04-10 21:05:31 +00:00
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'InterwikiLookup' );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
};
|
2020-12-18 22:32:27 +00:00
|
|
|
$setup[] = $reset;
|
|
|
|
|
$teardown[] = $reset;
|
|
|
|
|
|
|
|
|
|
// This affects title normalization in links. It invalidates
|
|
|
|
|
// MediaWikiTitleCodec objects.
|
2021-10-14 00:32:35 +00:00
|
|
|
// These interwikis should have 'iw_url' that matches wgServer.
|
2021-12-03 00:41:33 +00:00
|
|
|
$setup['wgLocalInterwikis'] = [ 'local', 'project', 'mi' ];
|
2020-12-18 22:32:27 +00:00
|
|
|
$reset = function () {
|
|
|
|
|
$this->resetTitleServices();
|
|
|
|
|
};
|
|
|
|
|
$setup[] = $reset;
|
|
|
|
|
$teardown[] = $reset;
|
2013-08-22 18:38:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-25 05:41:32 +00:00
|
|
|
/**
|
|
|
|
|
* Reset the Title-related services that need resetting
|
|
|
|
|
* for each test
|
2019-04-12 09:49:59 +00:00
|
|
|
*
|
|
|
|
|
* @todo We need to reset all services on every test
|
2016-04-25 05:41:32 +00:00
|
|
|
*/
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
private function resetTitleServices() {
|
2016-04-25 05:41:32 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$services->resetServiceForTesting( 'TitleFormatter' );
|
|
|
|
|
$services->resetServiceForTesting( 'TitleParser' );
|
|
|
|
|
$services->resetServiceForTesting( '_MediaWikiTitleCodec' );
|
Add LinkRenderer (rewrite of Linker::link())
This is a rewrite of Linker::link() to a non-static, LinkTarget-based
interface. Users of plain Linker::link() with no options can use the
LinkRenderer instance provided by MediaWikiServices. Others that
have specific options should create and configure their own instance,
which can be used to create as many links as necessary.
The main entrypoints for making links are:
* ->makeLink( $target, $text, $attribs, $query );
* ->makeKnownLink( $target, $text, $attribs, $query );
* ->makeBrokenLink( $target, $text, $attribs, $query );
The order of the parameters are the same as Linker::link(), except
$options are now part of the LinkRenderer instance, and
known/broken status requires calling the function explicitly.
Additionally, instead of passing in raw $html for the link text, the
$text parameter will automatically be escaped unless it is specially
marked as safe HTML using the MediaWiki\Linker\HtmlArmor class.
The LinkBegin and LinkEnd hooks are now deprecated, but still function
for backwards-compatability. Clients should migrate to the nearly-
equivalent LinkRendererBegin and LinkRendererEnd hooks.
The main differences between the hooks are:
* Passing HtmlPageLinkRenderer object instead of deprecated DummyLinker
* Using LinkTarget instead of Title
* Begin hook can no longer change known/broken status of link. Use the
TitleIsAlwaysKnown hook for that.
* $options are no longer passed, they can be read (but shouldn't be
modified!) from the LinkRenderer object.
Bug: T469
Change-Id: I057cc86ae6404a080aa3c8e0e956ecbb10a897d5
2016-04-21 20:13:21 +00:00
|
|
|
$services->resetServiceForTesting( 'LinkRenderer' );
|
|
|
|
|
$services->resetServiceForTesting( 'LinkRendererFactory' );
|
2019-04-12 09:49:59 +00:00
|
|
|
$services->resetServiceForTesting( 'NamespaceInfo' );
|
2020-09-22 18:16:23 +00:00
|
|
|
$services->resetServiceForTesting( 'SpecialPageFactory' );
|
2016-04-25 05:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-09 22:33:00 +00:00
|
|
|
/**
|
|
|
|
|
* Remove last character if it is a newline
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string $s
|
2014-08-25 16:50:35 +00:00
|
|
|
* @return string
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
2013-02-12 21:32:09 +00:00
|
|
|
public static function chomp( $s ) {
|
2024-01-25 11:13:06 +00:00
|
|
|
if ( str_ends_with( $s, "\n" ) ) {
|
2012-01-09 22:33:00 +00:00
|
|
|
return substr( $s, 0, -1 );
|
2013-02-14 11:22:13 +00:00
|
|
|
} else {
|
2012-01-09 22:33:00 +00:00
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-06 01:15:20 +00:00
|
|
|
private function skipAllTestsInFile(
|
|
|
|
|
string $filename, TestFileReader $testFileInfo, ParserTestMode $mode, string $skipMessage
|
|
|
|
|
): void {
|
|
|
|
|
foreach ( $testFileInfo->testCases as $test ) {
|
|
|
|
|
$this->recorder->startTest( $test, $mode );
|
|
|
|
|
$this->recorder->skipped( $test, $mode, $skipMessage );
|
|
|
|
|
}
|
|
|
|
|
$this->recorder->endSuite( $filename );
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-09 22:33:00 +00:00
|
|
|
/**
|
|
|
|
|
* Run a series of tests listed in the given text files.
|
|
|
|
|
* Each test consists of a brief description, wikitext input,
|
|
|
|
|
* and the expected HTML output.
|
|
|
|
|
*
|
|
|
|
|
* Prints status updates on stdout and counts up the total
|
|
|
|
|
* number and percentage of passed tests.
|
|
|
|
|
*
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* Handles all setup and teardown.
|
|
|
|
|
*
|
2024-01-20 19:24:35 +00:00
|
|
|
* @param string[] $filenames
|
2014-04-17 18:43:42 +00:00
|
|
|
* @return bool True if passed all tests, false if any tests failed.
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
|
|
|
|
public function runTestsFromFiles( $filenames ) {
|
|
|
|
|
$ok = false;
|
2013-07-30 13:12:12 +00:00
|
|
|
|
2020-12-23 18:52:12 +00:00
|
|
|
$teardownGuard = null;
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$teardownGuard = $this->setupDatabase( $teardownGuard );
|
2020-12-23 18:52:12 +00:00
|
|
|
$teardownGuard = $this->staticSetup( $teardownGuard );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$teardownGuard = $this->setupUploads( $teardownGuard );
|
2013-07-30 13:12:12 +00:00
|
|
|
|
2012-01-09 22:33:00 +00:00
|
|
|
$this->recorder->start();
|
|
|
|
|
try {
|
|
|
|
|
$ok = true;
|
2023-04-06 01:15:20 +00:00
|
|
|
$inParsoidMode = $this->options['parsoid'];
|
2024-03-01 16:48:16 +00:00
|
|
|
if ( $inParsoidMode ) {
|
|
|
|
|
$legacyMode = null;
|
|
|
|
|
$skipMode = new ParserTestMode( 'parsoid' );
|
|
|
|
|
} else {
|
|
|
|
|
$legacyMode = $skipMode = new ParserTestMode( 'legacy' );
|
|
|
|
|
}
|
2012-01-09 22:33:00 +00:00
|
|
|
|
|
|
|
|
foreach ( $filenames as $filename ) {
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$this->recorder->startSuite( $filename );
|
2023-04-05 17:37:14 +00:00
|
|
|
|
|
|
|
|
$testFileInfo = TestFileReader::read( $filename,
|
|
|
|
|
static function ( $msg ) {
|
|
|
|
|
wfDeprecatedMsg( $msg, '1.35', false, false );
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2023-04-06 01:15:20 +00:00
|
|
|
$skipMessage = $this->getFileSkipMessage( !$inParsoidMode, $testFileInfo->fileOptions, $filename );
|
|
|
|
|
if ( $skipMessage !== null ) {
|
|
|
|
|
$this->skipAllTestsInFile( $filename, $testFileInfo, $skipMode, $skipMessage );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$parsoidTestModeStrs = [];
|
|
|
|
|
if ( $inParsoidMode ) { // Intersect requested modes with test modes enabled in the file
|
|
|
|
|
$parsoidTestModeStrs = $this->computeValidTestModes(
|
2023-04-05 17:37:14 +00:00
|
|
|
$this->getRequestedTestModes(), $testFileInfo->fileOptions );
|
|
|
|
|
|
2023-04-06 01:15:20 +00:00
|
|
|
if ( !$parsoidTestModeStrs ) {
|
|
|
|
|
$skipMessage = 'No compatible Parsoid modes found for the file';
|
|
|
|
|
$this->skipAllTestsInFile( $filename, $testFileInfo, $skipMode, $skipMessage );
|
2023-04-05 17:37:14 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->checkSetupDone( 'staticSetup' );
|
|
|
|
|
$teardown = $this->addArticles( $testFileInfo->articles );
|
|
|
|
|
|
|
|
|
|
// Run tests
|
2023-04-06 01:15:20 +00:00
|
|
|
foreach ( $testFileInfo->testCases as $test ) {
|
|
|
|
|
$skipMessage = $this->getTestSkipMessage( $test, !$inParsoidMode );
|
2023-04-13 23:09:39 +00:00
|
|
|
if ( $skipMessage !== null ) {
|
|
|
|
|
if ( $skipMessage !== self::FILTER_MSG ) {
|
|
|
|
|
$this->recorder->startTest( $test, $skipMode );
|
|
|
|
|
$this->recorder->skipped( $test, $skipMode, $skipMessage );
|
|
|
|
|
}
|
2023-04-06 01:15:20 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $inParsoidMode ) {
|
|
|
|
|
// calls runTestInternal for each mode
|
|
|
|
|
$passed = $this->runTestInParsoidModes( $test, $parsoidTestModeStrs );
|
|
|
|
|
} else {
|
|
|
|
|
'@phan-var ParserTestMode $legacyMode'; // assert that this is not null
|
|
|
|
|
$passed = $this->runTestInternal( $test, $legacyMode )->isSuccess();
|
2023-04-05 17:37:14 +00:00
|
|
|
}
|
2023-04-06 01:15:20 +00:00
|
|
|
|
|
|
|
|
$ok = $ok && $passed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update tests / known-failures
|
|
|
|
|
if ( $inParsoidMode && $this->options['updateKnownFailures'] ) {
|
|
|
|
|
$this->updateKnownFailures( $filename, $testFileInfo );
|
2023-04-05 17:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->options['update-tests'] ) {
|
|
|
|
|
$this->updateTests( $filename, $testFileInfo, !$inParsoidMode );
|
2022-05-14 05:06:03 +00:00
|
|
|
}
|
2023-04-05 17:37:14 +00:00
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
|
ScopedCallback::consume( $teardown );
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$this->recorder->endSuite( $filename );
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->recorder->report();
|
2013-02-14 11:22:13 +00:00
|
|
|
} catch ( DBError $e ) {
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$this->recorder->warning( $e->getMessage() );
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
$this->recorder->end();
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
ScopedCallback::consume( $teardownGuard );
|
|
|
|
|
|
2012-01-09 22:33:00 +00:00
|
|
|
return $ok;
|
|
|
|
|
}
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
/**
|
|
|
|
|
* Determine whether the current parser has the hooks registered in it
|
|
|
|
|
* that are required by a file read by TestFileReader.
|
2024-01-20 19:24:35 +00:00
|
|
|
* @param array[] $requirements
|
2017-09-09 20:47:04 +00:00
|
|
|
* @return bool
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
*/
|
|
|
|
|
public function meetsRequirements( $requirements ) {
|
|
|
|
|
foreach ( $requirements as $requirement ) {
|
2022-06-01 21:19:57 +00:00
|
|
|
$ok = true;
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
switch ( $requirement['type'] ) {
|
2017-12-11 03:07:50 +00:00
|
|
|
case 'hook':
|
|
|
|
|
$ok = $this->requireHook( $requirement['name'] );
|
|
|
|
|
break;
|
|
|
|
|
case 'functionHook':
|
|
|
|
|
$ok = $this->requireFunctionHook( $requirement['name'] );
|
|
|
|
|
break;
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
}
|
|
|
|
|
if ( !$ok ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-14 05:06:03 +00:00
|
|
|
/**
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param bool $isLegacy
|
2022-05-14 05:06:03 +00:00
|
|
|
* @param array $fileOptions
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param string $filename
|
2022-05-14 05:06:03 +00:00
|
|
|
* @return string|null
|
|
|
|
|
*/
|
2022-05-20 20:42:25 +00:00
|
|
|
public function getFileSkipMessage( bool $isLegacy, array $fileOptions, string $filename ): ?string {
|
|
|
|
|
$runnerOpts = $this->getOptions();
|
|
|
|
|
// Verify minimum version #
|
|
|
|
|
$testFormat = intval( $fileOptions['version'] ?? '1' );
|
|
|
|
|
if ( $testFormat < 2 ) {
|
2023-06-03 15:25:27 +00:00
|
|
|
throw new RuntimeException(
|
2022-05-20 20:42:25 +00:00
|
|
|
"$filename needs an update. Support for the parserTest v1 file format was removed in MediaWiki 1.36"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-14 05:06:03 +00:00
|
|
|
// If any requirements are not met, mark all tests from the file as skipped
|
2022-05-20 20:42:25 +00:00
|
|
|
if ( !(
|
|
|
|
|
$isLegacy ||
|
2023-03-13 20:13:52 +00:00
|
|
|
isset( $fileOptions['parsoid-compatible'] )
|
2022-05-20 20:42:25 +00:00
|
|
|
) ) {
|
2022-05-14 05:06:03 +00:00
|
|
|
// Running files in Parsoid integrated mode is opt-in for now.
|
|
|
|
|
return 'not compatible with Parsoid integrated mode';
|
|
|
|
|
} elseif ( !$this->meetsRequirements( $fileOptions['requirements'] ?? [] ) ) {
|
|
|
|
|
return 'required extension not enabled';
|
|
|
|
|
} elseif ( ( $runnerOpts['testFile'] ?? $filename ) !== $filename ) {
|
|
|
|
|
return 'Not the requested test file';
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-06 01:15:20 +00:00
|
|
|
public function getTestSkipMessage( ParserTest $test, bool $isLegacy ): ?string {
|
2023-04-05 17:04:33 +00:00
|
|
|
$opts = $test->options;
|
|
|
|
|
|
2023-04-13 23:09:39 +00:00
|
|
|
if ( !$test->matchesFilter( [ 'regex' => $this->regex ] ) ) {
|
|
|
|
|
return self::FILTER_MSG;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 17:04:33 +00:00
|
|
|
// Skip deprecated preprocessor tests
|
|
|
|
|
if ( isset( $opts['preprocessor'] ) && $opts['preprocessor'] !== 'Preprocessor_Hash' ) {
|
|
|
|
|
wfDeprecated( 'preprocessor=Preprocessor_DOM', '1.36' );
|
|
|
|
|
return "Unsupported preprocessor type";
|
|
|
|
|
}
|
2023-04-04 20:40:50 +00:00
|
|
|
if ( $test->wikitext === null ) {
|
|
|
|
|
// Note that /in theory/ we could have pure html2html tests
|
|
|
|
|
// with no wikitext section, but /in practice/ all tests
|
|
|
|
|
// include a wikitext section.
|
|
|
|
|
$test->error( "Test lacks wikitext section", $test->testName );
|
|
|
|
|
}
|
|
|
|
|
// Skip disabled / filtered tests
|
2023-04-05 17:04:33 +00:00
|
|
|
if ( isset( $opts['disabled'] ) && !$this->runDisabled ) {
|
2023-04-04 20:40:50 +00:00
|
|
|
return "Test disabled";
|
|
|
|
|
}
|
2023-04-13 23:09:39 +00:00
|
|
|
|
2023-04-04 20:40:50 +00:00
|
|
|
// Skip parsoid-only tests if running in a legacy test mode
|
|
|
|
|
if (
|
|
|
|
|
$test->legacyHtml === null &&
|
|
|
|
|
self::getLegacyMetadataSection( $test ) === null
|
|
|
|
|
) {
|
|
|
|
|
// A Parsoid-only test should have one of the following sections
|
2023-02-22 20:49:45 +00:00
|
|
|
if (
|
2023-04-04 20:40:50 +00:00
|
|
|
isset( $test->sections['html/parsoid'] ) ||
|
|
|
|
|
isset( $test->sections['html/parsoid+integrated'] ) ||
|
|
|
|
|
isset( $test->sections['html/parsoid+standalone'] ) ||
|
|
|
|
|
isset( $test->sections['wikitext/edited'] ) ||
|
|
|
|
|
self::getParsoidMetadataSection( $test ) !== null
|
2023-02-22 20:49:45 +00:00
|
|
|
) {
|
2023-04-06 01:15:20 +00:00
|
|
|
if ( $isLegacy ) {
|
2023-04-04 20:40:50 +00:00
|
|
|
// Not an error, just skip this test if we're in
|
|
|
|
|
// legacy mode.
|
|
|
|
|
return "Parsoid-only test";
|
2022-05-20 20:42:25 +00:00
|
|
|
}
|
2023-04-04 20:40:50 +00:00
|
|
|
} else {
|
|
|
|
|
// This test lacks both a legacy html or metadata
|
|
|
|
|
// section and also any parsoid-specific html or
|
|
|
|
|
// metadata section or wikitext/edited section.
|
|
|
|
|
$test->error( "Test lacks html or metadata section", $test->testName );
|
2022-05-20 20:42:25 +00:00
|
|
|
}
|
2023-04-04 20:40:50 +00:00
|
|
|
}
|
|
|
|
|
return null;
|
2022-05-20 20:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-22 20:49:45 +00:00
|
|
|
public static function getLegacyMetadataSection( ParserTest $test ) {
|
|
|
|
|
return // specific results for legacy parser
|
|
|
|
|
$test->sections['metadata/php'] ??
|
|
|
|
|
// specific results for legacy parser and parsoid integrated mode
|
|
|
|
|
$test->sections['metadata/integrated'] ??
|
|
|
|
|
// generic for all parsers (even standalone)
|
|
|
|
|
$test->sections['metadata'] ??
|
|
|
|
|
// missing (== use legacy combined output format)
|
|
|
|
|
null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getParsoidMetadataSection( ParserTest $test ) {
|
|
|
|
|
return // specific results for parsoid integrated mode
|
|
|
|
|
$test->sections['metadata/parsoid+integrated'] ??
|
|
|
|
|
// specific results for parsoid
|
|
|
|
|
$test->sections['metadata/parsoid'] ??
|
|
|
|
|
// specific results for legacy parser and parsoid integrated mode
|
|
|
|
|
$test->sections['metadata/integrated'] ??
|
|
|
|
|
// generic for all parsers (even standalone)
|
|
|
|
|
$test->sections['metadata'] ??
|
|
|
|
|
// missing (== use legacy combined output format)
|
|
|
|
|
null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 21:46:58 +00:00
|
|
|
/**
|
|
|
|
|
* Compute valid test modes based on requested modes and file-enabled modes
|
2024-01-20 19:24:35 +00:00
|
|
|
* @param string[] $testModes
|
2022-10-25 21:46:58 +00:00
|
|
|
* @param array $fileOptions
|
2024-01-20 19:24:35 +00:00
|
|
|
* @return string[]
|
2022-10-25 21:46:58 +00:00
|
|
|
*/
|
|
|
|
|
public function computeValidTestModes( array $testModes, array $fileOptions ): array {
|
2024-01-26 23:07:27 +00:00
|
|
|
$modeRestriction = $fileOptions['parsoid-compatible'] ?: false;
|
2022-10-25 21:46:58 +00:00
|
|
|
if ( $modeRestriction !== false ) {
|
|
|
|
|
if ( is_string( $modeRestriction ) ) {
|
|
|
|
|
// shorthand
|
|
|
|
|
$modeRestriction = [ $modeRestriction ];
|
|
|
|
|
}
|
|
|
|
|
$testModes = array_values( array_intersect( $testModes, $modeRestriction ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $testModes;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-14 05:06:03 +00:00
|
|
|
/**
|
|
|
|
|
* Run the tests from a single file. staticSetup() and setupDatabase()
|
|
|
|
|
* must have been called already.
|
|
|
|
|
*
|
2023-04-06 01:15:20 +00:00
|
|
|
* @param ParserTest $t
|
|
|
|
|
* @param string[] $testModeStrs What Parsoid modes to run these these in?
|
|
|
|
|
* @return bool True if passed all modes, false if any mode failed.
|
2022-05-14 05:06:03 +00:00
|
|
|
*/
|
2023-04-06 01:15:20 +00:00
|
|
|
private function runTestInParsoidModes( ParserTest $t, array $testModeStrs ): bool {
|
|
|
|
|
if ( $this->options['updateKnownFailures'] ) {
|
|
|
|
|
// Reset known failures to ensure we reset newly skipped tests
|
|
|
|
|
$t->knownFailures = [];
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-14 05:06:03 +00:00
|
|
|
$ok = true;
|
|
|
|
|
$runner = $this;
|
2023-04-06 01:15:20 +00:00
|
|
|
$t->testAllModes( $t->computeTestModes( $testModeStrs ), $this->options,
|
|
|
|
|
function ( ParserTest $test, string $modeStr, array $options ) use ( $runner, $t, &$ok ) {
|
|
|
|
|
// $test could be a clone of $t
|
|
|
|
|
// Ensure that updates to knownFailures in $test are reflected in $t
|
|
|
|
|
$test->knownFailures = &$t->knownFailures;
|
|
|
|
|
$mode = new ParserTestMode( $modeStr, $test->changetree );
|
|
|
|
|
if ( $modeStr === 'selser' && $test->changetree === null ) {
|
|
|
|
|
// This is an auto-edit test with either a CLI changetree
|
|
|
|
|
// or a change tree that should be generated
|
|
|
|
|
$mode = new ParserTestMode( 'selser-auto', json_decode( $runner->options['changetree'] ) );
|
2022-05-14 05:06:03 +00:00
|
|
|
}
|
2023-04-06 01:15:20 +00:00
|
|
|
$result = $this->runTestInternal( $test, $mode );
|
|
|
|
|
$ok = $ok && $result->isSuccess();
|
|
|
|
|
}
|
|
|
|
|
);
|
2022-05-14 05:06:03 +00:00
|
|
|
|
|
|
|
|
return $ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update known failures JSON file for the parser tests file
|
2023-03-13 20:13:52 +00:00
|
|
|
* @param string $filename The parser test file
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param TestFileReader $testFileInfo
|
2022-05-14 05:06:03 +00:00
|
|
|
*/
|
2023-03-13 20:13:52 +00:00
|
|
|
public function updateKnownFailures( string $filename, TestFileReader $testFileInfo ) {
|
2022-05-14 05:06:03 +00:00
|
|
|
$testKnownFailures = [];
|
|
|
|
|
foreach ( $testFileInfo->testCases as $t ) {
|
2022-06-01 21:19:57 +00:00
|
|
|
if ( $t->knownFailures && $t->testName ) {
|
|
|
|
|
// @phan-suppress-next-line PhanTypeMismatchDimAssignment False positive
|
2022-05-14 05:06:03 +00:00
|
|
|
$testKnownFailures[$t->testName] = $t->knownFailures;
|
|
|
|
|
// FIXME: This reduces noise when updateKnownFailures is used
|
|
|
|
|
// with a subset of test modes. But, this also mixes up the selser
|
|
|
|
|
// test results with non-selser ones.
|
|
|
|
|
// ksort( $testKnownFailures[$t->testName] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Sort, otherwise, titles get added above based on the first
|
|
|
|
|
// failing mode, which can make diffs harder to verify when
|
|
|
|
|
// failing modes change.
|
|
|
|
|
ksort( $testKnownFailures );
|
2023-02-15 18:58:58 +00:00
|
|
|
// Cast to object to ensure that empty list is encoded as `{}` not `[]`
|
|
|
|
|
$contents = FormatJson::encode( (object)$testKnownFailures, "\t", FormatJson::ALL_OK ) . "\n";
|
2022-05-14 05:06:03 +00:00
|
|
|
|
|
|
|
|
if ( file_exists( $testFileInfo->knownFailuresPath ) ) {
|
|
|
|
|
$old = file_get_contents( $testFileInfo->knownFailuresPath );
|
|
|
|
|
} else {
|
2023-02-16 21:10:54 +00:00
|
|
|
// If file doesn't exist, use the JSON representation of an
|
|
|
|
|
// empty array, so it compares equal in the case that we
|
|
|
|
|
// end up with an empty array of known failures below.
|
|
|
|
|
$old = "{}";
|
2022-05-14 05:06:03 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-13 20:13:52 +00:00
|
|
|
if ( $old !== $contents ) {
|
|
|
|
|
if ( $testFileInfo->knownFailuresPath ) {
|
|
|
|
|
$this->recorder->warning( "Updating known failures file: {$testFileInfo->knownFailuresPath}" );
|
|
|
|
|
file_put_contents( $testFileInfo->knownFailuresPath, $contents );
|
|
|
|
|
} else {
|
|
|
|
|
// To be safe, we don't try to write a file that doesn't
|
|
|
|
|
// (yet) exist. Create an empty file if you need to, and
|
|
|
|
|
// then we'll happily update it for you.
|
2023-06-03 15:25:27 +00:00
|
|
|
throw new RuntimeException(
|
2023-03-13 20:13:52 +00:00
|
|
|
"Known failures file for $filename does not exist, " .
|
|
|
|
|
"and so won't be updated."
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-05-14 05:06:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 21:51:43 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $filename The parser test file
|
|
|
|
|
* @param TestFileReader $testFileInfo
|
|
|
|
|
* @param bool $isLegacy
|
|
|
|
|
*/
|
|
|
|
|
public function updateTests(
|
|
|
|
|
string $filename, TestFileReader $testFileInfo, bool $isLegacy
|
|
|
|
|
) {
|
|
|
|
|
$fileContent = file_get_contents( $filename );
|
|
|
|
|
foreach ( $testFileInfo->testCases as $t ) {
|
|
|
|
|
$testName = $t->testName;
|
|
|
|
|
$fail = $t->knownFailures[$isLegacy ? 'legacy' : 'wt2html'] ?? null;
|
|
|
|
|
$html = $isLegacy ? $t->legacyHtml : $t->parsoidHtml;
|
2023-04-20 18:41:18 +00:00
|
|
|
if ( $isLegacy && $fail === null ) {
|
|
|
|
|
$fail = $t->knownFailures['metadata'] ?? null;
|
|
|
|
|
$html = self::getLegacyMetadataSection( $t );
|
|
|
|
|
}
|
2023-03-21 21:51:43 +00:00
|
|
|
if ( $testName !== null && $fail !== null && $html !== null ) {
|
|
|
|
|
$exp = '/(!!\s*test\s*' .
|
|
|
|
|
preg_quote( $testName, '/' ) .
|
|
|
|
|
'(?:(?!!!\s*end)[\s\S])*' .
|
|
|
|
|
')(' . preg_quote( $html, '/' ) .
|
|
|
|
|
')/m';
|
|
|
|
|
$fileContent = preg_replace_callback(
|
|
|
|
|
$exp,
|
|
|
|
|
static function ( array $matches ) use ( $fail ) {
|
|
|
|
|
return $matches[1] . $fail;
|
|
|
|
|
},
|
|
|
|
|
$fileContent
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
file_put_contents( $filename, $fileContent );
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-27 21:28:14 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $wikitext
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
private function getRevRecordProperties( string $wikitext ): array {
|
|
|
|
|
return [
|
|
|
|
|
'pageid' => 187, // Some random fake page id
|
|
|
|
|
'revid' => 1337, // see Parser::getRevisionId()
|
|
|
|
|
'timestamp' => $this->getFakeTimestamp(),
|
|
|
|
|
'wikitext' => $wikitext
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a mutable rev record for test use.
|
|
|
|
|
*
|
2023-07-14 20:07:22 +00:00
|
|
|
* @param LinkTarget $target
|
2023-07-14 19:18:01 +00:00
|
|
|
* @param UserIdentity $user
|
2022-08-27 21:28:14 +00:00
|
|
|
* @param array $revProps
|
|
|
|
|
* @return RevisionRecord
|
|
|
|
|
*/
|
2023-07-14 20:07:22 +00:00
|
|
|
private function createRevRecord( LinkTarget $target, UserIdentity $user, array $revProps ): RevisionRecord {
|
2022-08-27 21:28:14 +00:00
|
|
|
$content = new WikitextContent( $revProps['wikitext'] );
|
2023-07-14 20:07:22 +00:00
|
|
|
$title = MediaWikiServices::getInstance()->getTitleFactory()->newFromRow( (object)[
|
2022-08-27 21:28:14 +00:00
|
|
|
'page_id' => $revProps['pageid'],
|
|
|
|
|
'page_len' => $content->getSize(),
|
|
|
|
|
'page_latest' => $revProps['revid'],
|
2023-07-14 20:07:22 +00:00
|
|
|
'page_namespace' => $target->getNamespace(),
|
|
|
|
|
'page_title' => $target->getDBkey(),
|
2022-08-27 21:28:14 +00:00
|
|
|
'page_is_redirect' => 0
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$revRecord = new MutableRevisionRecord( $title );
|
|
|
|
|
$revRecord->setContent( SlotRecord::MAIN, $content )
|
|
|
|
|
->setUser( $user )
|
|
|
|
|
->setTimestamp( strval( $revProps['timestamp'] ) )
|
|
|
|
|
->setPageId( $title->getArticleID() )
|
|
|
|
|
->setId( $title->getLatestRevID() );
|
|
|
|
|
|
|
|
|
|
return $revRecord;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-09 22:33:00 +00:00
|
|
|
/**
|
2020-07-24 04:41:09 +00:00
|
|
|
* Shared code to initialize ParserOptions based on the $test object,
|
|
|
|
|
* used by both the legacy Parser and the Parsoid parser.
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTest $test
|
2023-07-14 20:07:22 +00:00
|
|
|
* @param callable(IContextSource,LinkTarget,array):ParserOptions $parserOptionsCallback A callback to create the
|
2020-07-24 04:41:09 +00:00
|
|
|
* initial ParserOptions object. This allows for some minor
|
|
|
|
|
* differences in how the legacy Parser and Parsoid create this.
|
2024-03-01 16:48:16 +00:00
|
|
|
* @return array<LinkTarget|ParserOptions|int> An array of LinkTarget, ParserOptions, and integer revId.
|
|
|
|
|
* @phan-return array{0:LinkTarget,1:ParserOptions,2:int}
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
2022-05-20 20:42:25 +00:00
|
|
|
private function setupParserOptions( ParserTest $test, callable $parserOptionsCallback ) {
|
2020-07-24 04:41:09 +00:00
|
|
|
$opts = $test->options;
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$context = RequestContext::getMain();
|
2022-08-27 21:28:14 +00:00
|
|
|
$wikitext = $test->wikitext;
|
|
|
|
|
'@phan-var string $wikitext'; // assert that this is not null
|
|
|
|
|
$revProps = $this->getRevRecordProperties( $wikitext );
|
2012-01-09 22:33:00 +00:00
|
|
|
$user = $context->getUser();
|
2019-07-04 10:01:31 +00:00
|
|
|
$title = isset( $opts['title'] )
|
2023-07-14 20:07:22 +00:00
|
|
|
? MediaWikiServices::getInstance()->getTitleParser()->parseTitle( $opts['title'] )
|
|
|
|
|
: new TitleValue( NS_MAIN, 'Parser test' );
|
2019-07-04 10:01:31 +00:00
|
|
|
|
2022-08-27 21:28:14 +00:00
|
|
|
$revRecord = null;
|
2019-07-04 10:01:31 +00:00
|
|
|
if ( isset( $opts['lastsavedrevision'] ) ) {
|
2022-08-27 21:28:14 +00:00
|
|
|
$revRecord = $this->createRevRecord( $title, $user, $revProps );
|
|
|
|
|
$revProps['rev'] = $revRecord;
|
2022-09-20 20:45:44 +00:00
|
|
|
// Increment timestamp so that parser tests can distinguish between
|
|
|
|
|
// ParserOptions source and RevisionRecord
|
|
|
|
|
$revProps['timestamp'] += 234;
|
2022-08-27 21:28:14 +00:00
|
|
|
}
|
2020-06-03 03:48:42 +00:00
|
|
|
|
2022-08-27 21:28:14 +00:00
|
|
|
$options = $parserOptionsCallback( $context, $title, $revProps );
|
2022-09-20 20:45:44 +00:00
|
|
|
$options->setTimestamp(
|
|
|
|
|
MWTimestamp::convert( TS_MW, $revProps['timestamp'] )
|
|
|
|
|
);
|
2024-07-12 01:19:12 +00:00
|
|
|
$options->setUserLang( $opts['userlanguage'] ?? $context->getLanguage() );
|
2020-06-03 03:48:42 +00:00
|
|
|
|
2022-08-27 21:28:14 +00:00
|
|
|
if ( isset( $opts['lastsavedrevision'] ) ) {
|
2020-06-03 03:48:42 +00:00
|
|
|
$oldCallback = $options->getCurrentRevisionRecordCallback();
|
|
|
|
|
$options->setCurrentRevisionRecordCallback(
|
2023-07-14 20:07:22 +00:00
|
|
|
static function ( LinkTarget $link, $parser = null ) use ( $title, $revRecord, $oldCallback ) {
|
|
|
|
|
if ( $link->isSameLinkAs( $title ) ) {
|
2020-06-03 03:48:42 +00:00
|
|
|
return $revRecord;
|
2019-07-04 10:01:31 +00:00
|
|
|
} else {
|
2023-07-14 20:07:22 +00:00
|
|
|
return $oldCallback( $link, $parser );
|
2019-07-04 10:01:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-27 05:57:55 +00:00
|
|
|
if ( isset( $opts['maxincludesize'] ) ) {
|
|
|
|
|
$options->setMaxIncludeSize( $opts['maxincludesize'] );
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $opts['maxtemplatedepth'] ) ) {
|
|
|
|
|
$options->setMaxTemplateDepth( $opts['maxtemplatedepth'] );
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-27 21:28:14 +00:00
|
|
|
return [ $title, $options, $revProps['revid'] ];
|
2020-07-24 04:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a Parser object
|
|
|
|
|
*
|
|
|
|
|
* @return Parser
|
|
|
|
|
*/
|
|
|
|
|
public function getParser() {
|
|
|
|
|
$parserFactory = MediaWikiServices::getInstance()->getParserFactory();
|
|
|
|
|
$parser = $parserFactory->create(); // A fresh parser object.
|
|
|
|
|
ParserTestParserHook::setup( $parser );
|
|
|
|
|
return $parser;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
/**
|
|
|
|
|
* Run a given wikitext input through either the legacy wiki parser
|
|
|
|
|
* or Parsoid, depending on the given test mode, and compare the
|
|
|
|
|
* output against the expected results.
|
|
|
|
|
*
|
|
|
|
|
* @param ParserTest $test The test parameters
|
|
|
|
|
* @param ParserTestMode $mode The test mode
|
2022-06-07 22:35:32 +00:00
|
|
|
* @return ParserTestResult The test results.
|
2022-05-20 20:42:25 +00:00
|
|
|
*/
|
2023-04-06 01:15:20 +00:00
|
|
|
private function runTestInternal( ParserTest $test, ParserTestMode $mode ): ParserTestResult {
|
2022-06-03 21:44:26 +00:00
|
|
|
$this->recorder->startTest( $test, $mode );
|
2023-04-06 01:15:20 +00:00
|
|
|
if ( $mode->isLegacy() ) {
|
|
|
|
|
$result = $this->runLegacyTest( $test, $mode );
|
2022-05-20 20:42:25 +00:00
|
|
|
} else {
|
2023-04-06 01:15:20 +00:00
|
|
|
// Parsoid might skip a test for unsupported features
|
|
|
|
|
$result = $this->runParsoidTest( $test, $mode );
|
|
|
|
|
if ( $result === false ) {
|
|
|
|
|
$this->recorder->skipped( $test, $mode, 'SKIP' );
|
|
|
|
|
return new ParserTestResult( $test, $mode, 'SKIP', 'SKIP' );
|
|
|
|
|
}
|
2022-05-20 20:42:25 +00:00
|
|
|
}
|
2023-04-06 01:15:20 +00:00
|
|
|
$this->recorder->record( $result );
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Run a given wikitext input through either the legacy wiki parser
|
|
|
|
|
* or Parsoid, depending on the given test mode, and compare the
|
|
|
|
|
* output against the expected results.
|
|
|
|
|
*
|
|
|
|
|
* @param ParserTest $test The test parameters
|
|
|
|
|
* @param ParserTestMode $mode The test mode
|
|
|
|
|
* @return ParserTestResult The test results.
|
|
|
|
|
*/
|
|
|
|
|
public function runTest( ParserTest $test, ParserTestMode $mode ): ParserTestResult {
|
2023-04-13 23:09:39 +00:00
|
|
|
$skipMessage = $this->getTestSkipMessage( $test, $mode->isLegacy() );
|
|
|
|
|
if ( $skipMessage !== null ) {
|
|
|
|
|
if ( $skipMessage !== self::FILTER_MSG ) {
|
|
|
|
|
$this->recorder->startTest( $test, $mode );
|
|
|
|
|
$this->recorder->skipped( $test, $mode, $skipMessage );
|
|
|
|
|
}
|
2023-04-06 01:15:20 +00:00
|
|
|
return new ParserTestResult( $test, $mode, 'SKIP', 'SKIP' );
|
|
|
|
|
}
|
|
|
|
|
return $this->runTestInternal( $test, $mode );
|
2022-05-20 20:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-24 04:41:09 +00:00
|
|
|
/**
|
|
|
|
|
* Run a given wikitext input through a freshly-constructed instance
|
|
|
|
|
* of the legacy wiki parser, and compare the output against the expected
|
|
|
|
|
* results.
|
|
|
|
|
*
|
|
|
|
|
* Prints status and explanatory messages to stdout.
|
|
|
|
|
*
|
|
|
|
|
* staticSetup() and setupWikiData() must be called before this function
|
|
|
|
|
* is entered.
|
|
|
|
|
*
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTest $test The test parameters
|
|
|
|
|
* @param ParserTestMode $mode The test mode
|
2024-03-01 16:48:16 +00:00
|
|
|
* @return ParserTestResult
|
2020-07-24 04:41:09 +00:00
|
|
|
*/
|
2024-03-01 16:48:16 +00:00
|
|
|
public function runLegacyTest( ParserTest $test, ParserTestMode $mode ): ParserTestResult {
|
2022-05-20 20:42:25 +00:00
|
|
|
$desc = ( $test->comment ?? '' ) . $test->testName;
|
|
|
|
|
wfDebug( __METHOD__ . ": running $desc" );
|
2020-07-24 04:41:09 +00:00
|
|
|
$teardownGuard = $this->perTestSetup( $test );
|
|
|
|
|
[ $title, $options, $revId ] = $this->setupParserOptions(
|
2022-05-20 20:42:25 +00:00
|
|
|
$test,
|
2022-08-27 21:28:14 +00:00
|
|
|
static function ( $context, $title, $revProps ) {
|
2020-07-24 04:41:09 +00:00
|
|
|
return ParserOptions::newFromContext( $context );
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2023-04-05 17:04:33 +00:00
|
|
|
$opts = $test->options;
|
2012-01-09 22:33:00 +00:00
|
|
|
$local = isset( $opts['local'] );
|
Remove Preprocessor_DOM, deprecated in 1.34
Remove the deprecated Preprocessor_DOM class, which was hard-deprecated
in 1.34. This begins to simplify parser configuration and reduce redundant
code paths, but I've left two things for cleanup in a future patch:
1. The `preprocessorClass` configuration option to the parser, exposed
in `$wgParserConf`, ServiceWiring, ParserFactory, etc. There is no reason
for this to be exposed as configurable, but I've left this clean up to a
future patch.
2. The `$wgMaxGeneratedPPNodeCount` configuration, exposed also in
ParserOptions. Only Preprocessor_DOM calculated this count, and since
we are only using Preprocessor_Hash now, this configuration has no effect.
But since this value was exposed in ParserOptions and elsewhere, I've
deprecated where needed but left this clean up to a future patch.
Bug: T204945
Change-Id: I727f003f9a42d0c92bcbcce8a8289d5af6cd1298
2020-01-24 21:23:46 +00:00
|
|
|
$parser = $this->getParser();
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2018-02-26 21:49:08 +00:00
|
|
|
if ( isset( $opts['styletag'] ) ) {
|
|
|
|
|
// For testing the behavior of <style> (including those deduplicated
|
|
|
|
|
// into <link> tags), add tag hooks to allow them to be generated.
|
2021-02-07 13:10:36 +00:00
|
|
|
$parser->setHook( 'style', static function ( $content, $attributes, $parser ) {
|
2018-02-26 21:49:08 +00:00
|
|
|
$marker = Parser::MARKER_PREFIX . '-style-' . md5( $content ) . Parser::MARKER_SUFFIX;
|
2022-06-01 21:19:57 +00:00
|
|
|
// @phan-suppress-next-line SecurityCheck-XSS
|
2021-02-19 22:01:19 +00:00
|
|
|
$parser->getStripState()->addNoWiki( $marker, $content );
|
2018-02-26 21:49:08 +00:00
|
|
|
return Html::inlineStyle( $marker, 'all', $attributes );
|
|
|
|
|
} );
|
2021-02-07 13:10:36 +00:00
|
|
|
$parser->setHook( 'link', static function ( $content, $attributes, $parser ) {
|
2018-02-26 21:49:08 +00:00
|
|
|
return Html::element( 'link', $attributes );
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
$wikitext = $test->wikitext;
|
2023-02-22 16:28:57 +00:00
|
|
|
$output = null;
|
2023-07-14 20:07:22 +00:00
|
|
|
$pageReference = new PageReferenceValue( $title->getNamespace(), $title->getDBkey(), PageReferenceValue::LOCAL );
|
2022-05-20 20:42:25 +00:00
|
|
|
'@phan-var string $wikitext'; // assert that this is not null
|
2012-01-09 22:33:00 +00:00
|
|
|
if ( isset( $opts['pst'] ) ) {
|
2023-07-14 20:07:22 +00:00
|
|
|
$out = $parser->preSaveTransform( $wikitext, $pageReference, $options->getUserIdentity(), $options );
|
2017-07-07 01:06:43 +00:00
|
|
|
$output = $parser->getOutput();
|
2012-01-09 22:33:00 +00:00
|
|
|
} elseif ( isset( $opts['msg'] ) ) {
|
2023-07-14 20:07:22 +00:00
|
|
|
$out = $parser->transformMsg( $wikitext, $options, $pageReference );
|
2012-01-09 22:33:00 +00:00
|
|
|
} elseif ( isset( $opts['section'] ) ) {
|
|
|
|
|
$section = $opts['section'];
|
2022-05-20 20:42:25 +00:00
|
|
|
$out = $parser->getSection( $wikitext, $section );
|
2012-01-09 22:33:00 +00:00
|
|
|
} elseif ( isset( $opts['replace'] ) ) {
|
|
|
|
|
$section = $opts['replace'][0];
|
|
|
|
|
$replace = $opts['replace'][1];
|
2022-05-20 20:42:25 +00:00
|
|
|
$out = $parser->replaceSection( $wikitext, $section, $replace );
|
2012-01-09 22:33:00 +00:00
|
|
|
} elseif ( isset( $opts['comment'] ) ) {
|
2022-12-11 00:33:56 +00:00
|
|
|
$out = MediaWikiServices::getInstance()->getCommentFormatter()->format( $wikitext, $title, $local );
|
2012-01-09 22:33:00 +00:00
|
|
|
} elseif ( isset( $opts['preload'] ) ) {
|
2023-07-14 20:07:22 +00:00
|
|
|
$out = $parser->getPreloadText( $wikitext, $pageReference, $options );
|
2012-01-09 22:33:00 +00:00
|
|
|
} else {
|
2023-07-14 20:07:22 +00:00
|
|
|
$output = $parser->parse( $wikitext, $pageReference, $options, true, true, $revId );
|
2023-02-22 16:28:57 +00:00
|
|
|
if ( isset( $opts['nohtml'] ) ) {
|
|
|
|
|
$out = '';
|
2023-01-04 01:35:45 +00:00
|
|
|
} else {
|
|
|
|
|
$out = $output->getText( [
|
|
|
|
|
'allowTOC' => !isset( $opts['notoc'] ),
|
|
|
|
|
'unwrap' => !isset( $opts['wrap'] ),
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
'skin' => $this->getSkin( $opts['skin'] ?? 'fallback' ),
|
2023-01-04 01:35:45 +00:00
|
|
|
] );
|
2024-03-01 16:48:16 +00:00
|
|
|
$out = rtrim( $out );
|
2023-01-04 01:35:45 +00:00
|
|
|
}
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
2023-02-22 20:49:45 +00:00
|
|
|
|
|
|
|
|
$metadataExpected = self::getLegacyMetadataSection( $test );
|
|
|
|
|
$metadataActual = null;
|
2023-02-22 16:28:57 +00:00
|
|
|
if ( $output ) {
|
2023-02-22 20:49:45 +00:00
|
|
|
$this->addParserOutputInfo(
|
|
|
|
|
$out, $output, $opts, $title,
|
|
|
|
|
$metadataExpected, $metadataActual
|
|
|
|
|
);
|
2023-02-22 16:28:57 +00:00
|
|
|
}
|
2012-01-09 22:33:00 +00:00
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
ScopedCallback::consume( $teardownGuard );
|
2013-03-19 14:00:44 +00:00
|
|
|
|
2023-03-21 21:51:43 +00:00
|
|
|
$rawOut = $out;
|
2023-02-22 20:49:45 +00:00
|
|
|
$expected = $test->legacyHtml ?? '';
|
2016-03-09 04:42:33 +00:00
|
|
|
if ( count( $this->normalizationFunctions ) ) {
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$expected = ParserTestResultNormalizer::normalize(
|
2022-05-20 20:42:25 +00:00
|
|
|
$expected, $this->normalizationFunctions );
|
2016-03-09 04:42:33 +00:00
|
|
|
$out = ParserTestResultNormalizer::normalize( $out, $this->normalizationFunctions );
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
$testResult = new ParserTestResult( $test, $mode, $expected, $out );
|
2023-03-21 21:51:43 +00:00
|
|
|
|
|
|
|
|
if ( $this->options['update-tests'] && !$testResult->isSuccess() ) {
|
|
|
|
|
$test->knownFailures["$mode"] = $rawOut;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-20 18:41:18 +00:00
|
|
|
if ( $testResult->isSuccess() && $metadataExpected !== null ) {
|
|
|
|
|
$testResult = new ParserTestResult( $test, $mode, $metadataExpected, $metadataActual ?? '' );
|
|
|
|
|
|
|
|
|
|
if ( $this->options['update-tests'] && !$testResult->isSuccess() ) {
|
|
|
|
|
$test->knownFailures['metadata'] = $metadataActual;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
return $testResult;
|
2022-07-09 20:19:27 +00:00
|
|
|
}
|
2012-01-09 22:33:00 +00:00
|
|
|
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
private function getSkin( $name ) {
|
|
|
|
|
static $skinCache = [];
|
|
|
|
|
|
|
|
|
|
$skinCache[$name] ??= MediaWikiServices::getInstance()->getSkinFactory()->makeSkin( $name );
|
|
|
|
|
return $skinCache[$name];
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 01:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Add information from the parser output to the result string
|
|
|
|
|
*
|
2023-02-22 20:49:45 +00:00
|
|
|
* @param string &$out The "actual" parser output
|
|
|
|
|
* @param ParserOutput $output The "actual" parser metadata
|
|
|
|
|
* @param array $opts Test options
|
2023-12-22 17:28:24 +00:00
|
|
|
* @param ParsoidLinkTarget $title
|
2023-02-22 20:49:45 +00:00
|
|
|
* @param ?string $metadataExpected The contents of the !!metadata section,
|
|
|
|
|
* or null if it is missing
|
|
|
|
|
* @param ?string &$metadataActual The "actual" metadata output
|
2022-01-24 01:28:24 +00:00
|
|
|
*/
|
2023-02-22 20:49:45 +00:00
|
|
|
private function addParserOutputInfo(
|
2023-12-22 17:28:24 +00:00
|
|
|
&$out, ParserOutput $output, array $opts, ParsoidLinkTarget $title,
|
2023-02-22 20:49:45 +00:00
|
|
|
?string $metadataExpected, ?string &$metadataActual
|
|
|
|
|
) {
|
|
|
|
|
$before = [];
|
|
|
|
|
$after = [];
|
|
|
|
|
// The "before" entries may contain HTML.
|
2022-01-24 01:28:24 +00:00
|
|
|
if ( isset( $opts['showtitle'] ) ) {
|
|
|
|
|
if ( $output->getTitleText() ) {
|
|
|
|
|
$titleText = $output->getTitleText();
|
|
|
|
|
} else {
|
2023-12-22 17:28:24 +00:00
|
|
|
// TitleFormatter doesn't (yet) take ParsoidLinkTarget
|
|
|
|
|
// (which is identical to core's LinkTarget, but phan doesn't
|
|
|
|
|
// know that), so go through TitleValue for now.
|
|
|
|
|
$titleText = MediaWikiServices::getInstance()->getTitleFormatter()->getPrefixedText(
|
|
|
|
|
TitleValue::newFromLinkTarget( $title )
|
|
|
|
|
);
|
2022-01-24 01:28:24 +00:00
|
|
|
}
|
2023-02-22 20:49:45 +00:00
|
|
|
$before[] = $titleText;
|
2022-01-24 01:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $opts['showindicators'] ) ) {
|
|
|
|
|
foreach ( $output->getIndicators() as $id => $content ) {
|
2023-02-22 20:49:45 +00:00
|
|
|
$before[] = "$id=$content";
|
2022-01-24 01:28:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $opts['ill'] ) ) {
|
2023-02-22 20:49:45 +00:00
|
|
|
$after[] = implode( ' ', $output->getLanguageLinks() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $opts['cat'] ) ) {
|
2023-12-15 14:57:45 +00:00
|
|
|
$defaultSortKey = $output->getPageProperty( 'defaultsort' ) ?? '';
|
2023-09-21 17:06:50 +00:00
|
|
|
foreach ( $output->getCategoryNames() as $name ) {
|
2023-12-15 14:57:45 +00:00
|
|
|
$sortkey = $output->getCategorySortKey( $name ) ?: $defaultSortKey;
|
2023-02-22 20:49:45 +00:00
|
|
|
$after[] = "cat=$name sort=$sortkey";
|
2022-01-24 01:28:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $opts['extension'] ) ) {
|
2023-09-12 00:16:03 +00:00
|
|
|
$extList = $opts['extension'];
|
|
|
|
|
if ( !is_array( $extList ) ) {
|
|
|
|
|
$extList = [ $extList ];
|
|
|
|
|
}
|
|
|
|
|
foreach ( $extList as $ext ) {
|
2023-02-22 20:49:45 +00:00
|
|
|
$after[] = "extension[$ext]=" .
|
|
|
|
|
// XXX should use JsonCodec
|
2022-01-24 01:28:24 +00:00
|
|
|
json_encode(
|
|
|
|
|
$output->getExtensionData( $ext ),
|
|
|
|
|
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $opts['property'] ) ) {
|
2023-09-12 00:16:03 +00:00
|
|
|
$propList = $opts['property'];
|
|
|
|
|
if ( !is_array( $propList ) ) {
|
|
|
|
|
$propList = [ $propList ];
|
|
|
|
|
}
|
|
|
|
|
foreach ( $propList as $prop ) {
|
2023-02-22 20:49:45 +00:00
|
|
|
$after[] = "property[$prop]=" .
|
2022-02-16 22:03:26 +00:00
|
|
|
( $output->getPageProperty( $prop ) ?? '' );
|
2022-01-24 01:28:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-02-09 19:42:49 +00:00
|
|
|
if ( isset( $opts['showflags'] ) ) {
|
|
|
|
|
$actualFlags = [];
|
|
|
|
|
foreach ( ParserOutputFlags::cases() as $name ) {
|
2023-01-26 20:27:36 +00:00
|
|
|
if ( $output->getOutputFlag( $name ) ) {
|
|
|
|
|
$actualFlags[] = $name;
|
2023-02-09 19:42:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sort( $actualFlags );
|
2023-02-22 20:49:45 +00:00
|
|
|
$after[] = "flags=" . implode( ', ', $actualFlags );
|
2023-02-09 19:42:49 +00:00
|
|
|
# In 1.21 we deprecated the use of arbitrary keys for
|
|
|
|
|
# ParserOutput::setFlag() by extensions; if we find anyone
|
|
|
|
|
# still doing that complain about it.
|
|
|
|
|
$oldFlags = array_diff_key(
|
|
|
|
|
TestingAccessWrapper::newFromObject( $output )->mFlags,
|
|
|
|
|
array_fill_keys( ParserOutputFlags::cases(), true )
|
|
|
|
|
);
|
|
|
|
|
if ( $oldFlags ) {
|
|
|
|
|
wfDeprecated( 'Arbitrary flags in ParserOutput', '1.39' );
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-22 16:28:57 +00:00
|
|
|
if ( isset( $opts['showtocdata'] ) ) {
|
2023-03-01 21:03:44 +00:00
|
|
|
$tocData = $output->getTOCData();
|
|
|
|
|
if ( $tocData !== null ) {
|
|
|
|
|
$after[] = $tocData->prettyPrint();
|
2023-02-22 20:49:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-02-22 20:38:29 +00:00
|
|
|
if ( isset( $opts['showmedia'] ) ) {
|
|
|
|
|
$after[] = 'images=' . implode( ', ', array_keys( $output->getImages() ) );
|
|
|
|
|
}
|
2023-02-22 20:49:45 +00:00
|
|
|
if ( $metadataExpected === null ) {
|
|
|
|
|
// legacy format, add $before and $after to $out
|
|
|
|
|
if ( $before ) {
|
|
|
|
|
$before = implode( "\n", $before );
|
|
|
|
|
$out = "$before\n$out";
|
2023-02-22 16:28:57 +00:00
|
|
|
}
|
2023-02-22 20:49:45 +00:00
|
|
|
if ( $after ) {
|
|
|
|
|
if ( $out && !str_ends_with( $out, "\n" ) ) {
|
|
|
|
|
$out .= "\n";
|
|
|
|
|
}
|
|
|
|
|
$out .= implode( "\n", $after );
|
2023-02-22 16:28:57 +00:00
|
|
|
}
|
2023-02-22 20:49:45 +00:00
|
|
|
} else {
|
|
|
|
|
$metadataActual = implode( "\n", array_merge( $before, $after ) );
|
2023-02-22 16:28:57 +00:00
|
|
|
}
|
2022-01-24 01:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
/**
|
|
|
|
|
* This processes test results and updates the known failures info for the test
|
|
|
|
|
*
|
|
|
|
|
* @param ParserTest $test
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTestMode $mode
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
* @param string|null|callable $rawExpected
|
2022-05-20 20:42:25 +00:00
|
|
|
* If null, indicates that the normalizer should look for the expected
|
|
|
|
|
* output in the $test object.
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
* @param string $rawActual
|
|
|
|
|
* @param callable $normalizer normalizer of expected & actual output strings
|
2022-07-19 01:04:31 +00:00
|
|
|
* @return ParserTestResult|false
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
*/
|
|
|
|
|
private function processResults(
|
2022-05-20 20:42:25 +00:00
|
|
|
ParserTest $test, ParserTestMode $mode, $rawExpected, string $rawActual, callable $normalizer
|
2022-07-19 01:04:31 +00:00
|
|
|
) {
|
|
|
|
|
if ( $mode->isCachingMode() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-14 05:06:03 +00:00
|
|
|
if ( !$this->options['knownFailures'] ) {
|
|
|
|
|
$expectedFailure = null;
|
|
|
|
|
} else {
|
2022-05-20 20:42:25 +00:00
|
|
|
$expectedFailure = $test->knownFailures["$mode"] ?? null;
|
2022-05-14 05:06:03 +00:00
|
|
|
}
|
2022-07-27 18:18:17 +00:00
|
|
|
|
|
|
|
|
$expectedToFail = $expectedFailure !== null;
|
|
|
|
|
$knownFailureChanged = $expectedToFail && $expectedFailure !== $rawActual;
|
|
|
|
|
|
|
|
|
|
if ( is_callable( $rawExpected ) ) {
|
|
|
|
|
$rawExpected = $rawExpected();
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
}
|
2022-07-27 18:18:17 +00:00
|
|
|
[ $actual, $expected ] = $normalizer( $rawActual, $rawExpected, false /* standalone */ );
|
|
|
|
|
$passed = $actual === $expected;
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
|
2022-07-27 18:18:17 +00:00
|
|
|
$unexpectedPass = $expectedToFail && $passed;
|
|
|
|
|
$unexpectedFail = !$expectedToFail && !$passed;
|
|
|
|
|
|
|
|
|
|
if ( $unexpectedPass ) {
|
|
|
|
|
$this->recorder->warning( "{$test->testName}: $mode: EXPECTED TO FAIL, BUT PASSED!" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->options['updateKnownFailures'] && (
|
|
|
|
|
$knownFailureChanged || $unexpectedFail || $unexpectedPass
|
|
|
|
|
) ) {
|
|
|
|
|
if ( $unexpectedPass ) {
|
|
|
|
|
unset( $test->knownFailures["$mode"] );
|
2022-07-19 01:04:31 +00:00
|
|
|
} else {
|
2022-07-27 18:18:17 +00:00
|
|
|
if ( $knownFailureChanged ) {
|
|
|
|
|
$this->recorder->warning( "{$test->testName}: $mode: KNOWN FAILURE CHANGED!" );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
}
|
2022-07-27 18:18:17 +00:00
|
|
|
$test->knownFailures["$mode"] = $rawActual;
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 21:51:43 +00:00
|
|
|
if ( $this->options['update-tests'] && !$passed ) {
|
|
|
|
|
$test->knownFailures["$mode"] = $rawActual;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-27 18:18:17 +00:00
|
|
|
if ( $unexpectedPass ) {
|
|
|
|
|
if ( !$this->options['updateKnownFailures'] ) {
|
|
|
|
|
$this->unexpectedTestPasses = true;
|
|
|
|
|
}
|
|
|
|
|
} elseif ( $expectedToFail && !$knownFailureChanged ) {
|
|
|
|
|
// Don't flag failures noisily when nothing really changed
|
|
|
|
|
$expected = $expectedFailure;
|
|
|
|
|
$actual = $rawActual;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
return new ParserTestResult( $test, $mode, $expected, $actual );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function fetchCachedDoc( $parsoid, $pageConfig, $test ) {
|
|
|
|
|
// If cachedBODYstr is not already set, create it here.
|
|
|
|
|
if ( $test->cachedBODYstr === null ) {
|
|
|
|
|
$this->wt2html( $parsoid, $pageConfig, $test, new ParserTestMode( 'cache' ) );
|
|
|
|
|
}
|
|
|
|
|
$doc = DOMUtils::parseHTML( $test->cachedBODYstr, true );
|
|
|
|
|
// XXX applyChanges calls functions in WTUtils which assume we
|
|
|
|
|
// have a DataBag associated with the document.
|
|
|
|
|
DOMDataUtils::prepareDoc( $doc );
|
|
|
|
|
return $doc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function fetchCachedWt( $parsoid, $pageConfig, $test ) {
|
|
|
|
|
// If cachedWTstr is not already set, set it here.
|
|
|
|
|
if ( ( $test->cachedWTstr ?? null ) === null ) {
|
|
|
|
|
$this->html2wt( $parsoid, $pageConfig, $test, new ParserTestMode( 'cache' ) );
|
|
|
|
|
}
|
|
|
|
|
return $test->cachedWTstr;
|
2022-04-02 06:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-14 18:36:57 +00:00
|
|
|
/**
|
|
|
|
|
* Run wt2html on the test
|
2020-07-24 04:41:09 +00:00
|
|
|
*
|
2022-03-14 18:36:57 +00:00
|
|
|
* @param Parsoid $parsoid
|
|
|
|
|
* @param PageConfig $pageConfig
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
* @param ParserTest $test
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTestMode $mode
|
2020-07-24 04:41:09 +00:00
|
|
|
* @return ParserTestResult|false false if skipped
|
|
|
|
|
*/
|
2022-05-20 20:42:25 +00:00
|
|
|
private function wt2html( Parsoid $parsoid, PageConfig $pageConfig, ParserTest $test, ParserTestMode $mode ) {
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
$html = $test->sections['html/parsoid+integrated'] ?? $test->parsoidHtml;
|
2022-05-20 20:42:25 +00:00
|
|
|
Assert::invariant(
|
|
|
|
|
$test->wikitext !== null,
|
|
|
|
|
"All tests include a wikitext section"
|
|
|
|
|
);
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
|
2023-02-22 20:01:56 +00:00
|
|
|
if ( $html === null && !$mode->isCachingMode() && !isset( $test->options['nohtml'] ) ) {
|
2022-05-20 20:42:25 +00:00
|
|
|
// Nothing to test, but if mode is 'cache' we're executing this
|
|
|
|
|
// in order to set cachedBODYstr (say, for a wt2wt test)
|
2023-02-22 20:01:56 +00:00
|
|
|
// If the 'nohtml' option is set, we're executing this in order
|
|
|
|
|
// to test metadata.
|
2022-05-20 20:42:25 +00:00
|
|
|
return false;
|
2020-07-24 04:41:09 +00:00
|
|
|
}
|
2022-03-14 18:36:57 +00:00
|
|
|
|
2023-02-22 20:01:56 +00:00
|
|
|
$metadata = new ParserOutput( 'parsoid' );
|
2022-03-14 18:36:57 +00:00
|
|
|
$origOut = $parsoid->wikitext2html( $pageConfig, [
|
|
|
|
|
'body_only' => true,
|
2022-04-02 06:27:47 +00:00
|
|
|
'wrapSections' => $test->options['parsoid']['wrapSections'] ?? false,
|
2022-10-03 16:44:33 +00:00
|
|
|
'traceFlags' => $this->options['traceFlags'],
|
|
|
|
|
'dumpFlags' => $this->options['dumpFlags']
|
2023-02-22 20:01:56 +00:00
|
|
|
], $headers, $metadata );
|
|
|
|
|
|
|
|
|
|
if ( isset( $test->options['nohtml'] ) ) {
|
|
|
|
|
// Suppress HTML (presumably because we want to test the metadata)
|
|
|
|
|
$origOut = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$metadataExpected = self::getParsoidMetadataSection( $test );
|
|
|
|
|
$metadataActual = null;
|
2023-07-14 20:07:22 +00:00
|
|
|
$titleParser = MediaWikiServices::getInstance()->getTitleParser();
|
2023-02-22 20:01:56 +00:00
|
|
|
$this->addParserOutputInfo(
|
|
|
|
|
$origOut, $metadata, $test->options,
|
2023-12-22 17:28:24 +00:00
|
|
|
$pageConfig->getLinkTarget(),
|
2023-02-22 20:01:56 +00:00
|
|
|
$metadataExpected, $metadataActual
|
|
|
|
|
);
|
|
|
|
|
|
2022-03-14 18:36:57 +00:00
|
|
|
$test->cachedBODYstr = $origOut;
|
|
|
|
|
|
2023-02-22 20:01:56 +00:00
|
|
|
$testResult = $this->processResults(
|
|
|
|
|
$test, $mode,
|
2022-05-20 20:42:25 +00:00
|
|
|
// Passing 'null' for expected output here asks normalizeHTML
|
|
|
|
|
// to look it up for us, based on parsoid-only & standalone status
|
2023-02-22 20:01:56 +00:00
|
|
|
isset( $test->options['nohtml'] ) ? '' : null,
|
|
|
|
|
$origOut, [ $test, "normalizeHTML" ]
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
);
|
2023-02-22 20:01:56 +00:00
|
|
|
if ( $metadataExpected !== null && !$mode->isCachingMode() ) {
|
|
|
|
|
$nullNormalizer = static function ( $actual, $expected, $ignore ) {
|
|
|
|
|
return [ $actual, $expected ];
|
|
|
|
|
};
|
|
|
|
|
$metadataResult = $this->processResults(
|
|
|
|
|
$test, new ParserTestMode( 'metadata' ), $metadataExpected, $metadataActual ?? '', $nullNormalizer
|
|
|
|
|
);
|
|
|
|
|
if ( $testResult === false || $testResult->isSuccess() ) {
|
|
|
|
|
// Ensure both results have to be successful
|
|
|
|
|
$testResult = $metadataResult;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $testResult;
|
2022-03-14 18:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-15 11:15:18 +00:00
|
|
|
/**
|
|
|
|
|
* @param Parsoid $parsoid
|
|
|
|
|
* @param PageConfig $pageConfig
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
* @param ParserTest $test
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTestMode $mode
|
2022-03-15 11:15:18 +00:00
|
|
|
* @return ParserTestResult|false false if skipped
|
|
|
|
|
*/
|
2022-05-20 20:42:25 +00:00
|
|
|
private function wt2wt( Parsoid $parsoid, PageConfig $pageConfig, ParserTest $test, ParserTestMode $mode ) {
|
2022-07-18 23:54:45 +00:00
|
|
|
$html = $test->sections['html/parsoid+integrated'] ?? $test->parsoidHtml;
|
|
|
|
|
if ( $html === null ) {
|
|
|
|
|
// We currently don't run this in standalone mode.
|
|
|
|
|
// The expectation is to add html/parsoid sections
|
|
|
|
|
// if we want to run these tests.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
Assert::invariant(
|
|
|
|
|
$test->wikitext !== null,
|
|
|
|
|
"All tests include a wikitext section"
|
|
|
|
|
);
|
2022-03-15 11:15:18 +00:00
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
// Handle a 'changes' option if present.
|
|
|
|
|
$doc = $this->fetchCachedDoc( $parsoid, $pageConfig, $test );
|
|
|
|
|
$testManualChanges = $test->options['parsoid']['changes'] ?? null;
|
|
|
|
|
if ( $testManualChanges ) {
|
|
|
|
|
$test->applyManualChanges( $doc );
|
2022-03-15 11:15:18 +00:00
|
|
|
}
|
|
|
|
|
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
$origWT = $parsoid->dom2wikitext( $pageConfig, $doc );
|
|
|
|
|
if ( isset( $test->options['parsoid']['changes'] ) ) {
|
|
|
|
|
$expectedWT = $test->sections['wikitext/edited'];
|
|
|
|
|
} else {
|
|
|
|
|
$expectedWT = $test->wikitext;
|
2022-03-15 11:15:18 +00:00
|
|
|
}
|
|
|
|
|
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
return $this->processResults(
|
2022-05-20 20:42:25 +00:00
|
|
|
$test, $mode, $expectedWT, $origWT, [ $test, "normalizeWT" ]
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
);
|
2022-04-02 06:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Parsoid $parsoid
|
|
|
|
|
* @param PageConfig $pageConfig
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
* @param ParserTest $test
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTestMode $mode
|
2022-04-02 06:27:47 +00:00
|
|
|
* @return ParserTestResult|false false if skipped
|
|
|
|
|
*/
|
2022-05-20 20:42:25 +00:00
|
|
|
private function html2wt( Parsoid $parsoid, PageConfig $pageConfig, ParserTest $test, ParserTestMode $mode ) {
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
$html = $test->sections['html/parsoid+integrated'] ?? $test->parsoidHtml;
|
|
|
|
|
if ( $html === null ) {
|
2022-05-20 20:42:25 +00:00
|
|
|
// Although ::getTestSkipMessage checks that parsoid-only tests
|
|
|
|
|
// have html sections, this test would have (eg) only an
|
|
|
|
|
// html/parsoid+standalone section, and we're executing in
|
|
|
|
|
// integrated mode.
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
return false; // Skip. Nothing to test.
|
|
|
|
|
}
|
2022-07-19 01:04:31 +00:00
|
|
|
if ( $test->wikitext === null && !$mode->isCachingMode() ) {
|
2022-05-20 20:42:25 +00:00
|
|
|
// If mode is 'cache' we're executing this in order to
|
|
|
|
|
// set cachedWTstr.
|
2023-06-03 15:25:27 +00:00
|
|
|
throw new RuntimeException( 'Error in the test setup' );
|
2022-04-02 06:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
$test->cachedWTstr = $origWT = $parsoid->html2wikitext( $pageConfig, $html );
|
2022-04-02 06:27:47 +00:00
|
|
|
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
return $this->processResults(
|
2022-05-20 20:42:25 +00:00
|
|
|
$test, $mode, $test->wikitext ?? '', $origWT, [ $test, "normalizeWT" ]
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
);
|
2022-04-02 06:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Parsoid $parsoid
|
|
|
|
|
* @param PageConfig $pageConfig
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
* @param ParserTest $test
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTestMode $mode
|
2022-04-02 06:27:47 +00:00
|
|
|
* @return ParserTestResult|false false if skipped
|
|
|
|
|
*/
|
2022-05-20 20:42:25 +00:00
|
|
|
private function html2html( Parsoid $parsoid, PageConfig $pageConfig, ParserTest $test, ParserTestMode $mode ) {
|
2022-04-02 06:27:47 +00:00
|
|
|
$html = $test->sections['html/parsoid+integrated'] ?? $test->parsoidHtml;
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
if ( $html === null ) {
|
2022-05-20 20:42:25 +00:00
|
|
|
// Although ::getTestSkipMessage checks that parsoid-only tests
|
|
|
|
|
// have html sections, this test would have (eg) only an
|
|
|
|
|
// html/parsoid+standalone section, and we're executing in
|
|
|
|
|
// integrated mode.
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
return false; // Skip. Nothing to test.
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
$wt = $this->fetchCachedWt( $parsoid, $pageConfig, $test );
|
2022-04-02 06:27:47 +00:00
|
|
|
|
|
|
|
|
// Construct a fresh PageConfig object with $wt
|
|
|
|
|
$oldWt = $test->wikitext;
|
|
|
|
|
$test->wikitext = $wt;
|
2022-09-26 22:13:37 +00:00
|
|
|
$pageConfig = $this->setupParserOptionsAndBuildPageConfig( $test );
|
2022-04-02 06:27:47 +00:00
|
|
|
$test->wikitext = $oldWt;
|
|
|
|
|
|
|
|
|
|
$newHtml = $parsoid->wikitext2html( $pageConfig, [
|
|
|
|
|
'body_only' => true,
|
|
|
|
|
'wrapSections' => $test->options['parsoid']['wrapSections'] ?? false,
|
|
|
|
|
] );
|
|
|
|
|
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
return $this->processResults(
|
2022-05-20 20:42:25 +00:00
|
|
|
$test, $mode, $test->cachedNormalizedHTML, $newHtml, [ $test, "normalizeHTML" ]
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
);
|
2022-04-02 06:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-04 10:44:11 +00:00
|
|
|
/**
|
|
|
|
|
* @param Parsoid $parsoid
|
|
|
|
|
* @param PageConfig $pageConfig
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
* @param ParserTest $test
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTestMode $mode
|
2022-04-04 10:44:11 +00:00
|
|
|
* @return ParserTestResult|false false if skipped
|
|
|
|
|
*/
|
2022-05-20 20:42:25 +00:00
|
|
|
private function selser( Parsoid $parsoid, PageConfig $pageConfig, ParserTest $test, ParserTestMode $mode ) {
|
2022-07-18 23:54:45 +00:00
|
|
|
$html = $test->sections['html/parsoid+integrated'] ?? $test->parsoidHtml;
|
|
|
|
|
if ( $html === null ) {
|
|
|
|
|
// We currently don't run this in standalone mode.
|
|
|
|
|
// The expectation is to add html/parsoid sections
|
|
|
|
|
// if we want to run these tests.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
Assert::invariant(
|
|
|
|
|
$test->wikitext !== null,
|
|
|
|
|
"All tests include a wikitext section"
|
|
|
|
|
);
|
2022-04-04 10:44:11 +00:00
|
|
|
|
2022-06-01 21:19:57 +00:00
|
|
|
if ( $test->changetree === [ 'manual' ] && !isset( $test->options['parsoid']['changes'] ) ) {
|
2023-06-03 15:25:27 +00:00
|
|
|
throw new RuntimeException( 'Error in the test setup!' );
|
2022-04-04 10:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply edits to the HTML.
|
|
|
|
|
// Always serialize to string and reparse before passing to selser/wt2wt.
|
2022-05-20 20:42:25 +00:00
|
|
|
$doc = $this->fetchCachedDoc( $parsoid, $pageConfig, $test );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
if ( $test->changetree === [ 'manual' ] ) {
|
2022-04-04 10:44:11 +00:00
|
|
|
$test->applyManualChanges( $doc );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
$expectedWT = $test->sections['wikitext/edited'];
|
2022-04-04 10:44:11 +00:00
|
|
|
} else {
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
// $test->changetree === [ 5 ]
|
2022-05-20 20:42:25 +00:00
|
|
|
$changetree = $test->changetree;
|
|
|
|
|
'@phan-var array $changetree'; // assert that this is not null
|
|
|
|
|
$test->applyChanges( [], $doc, $changetree );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
$expectedWT = $test->wikitext;
|
2022-04-04 10:44:11 +00:00
|
|
|
}
|
|
|
|
|
$editedHTML = ContentUtils::toXML( DOMCompat::getBody( $doc ) );
|
|
|
|
|
|
|
|
|
|
// Run selser on edited doc
|
|
|
|
|
$selserData = new SelserData( $test->wikitext, $test->cachedBODYstr );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
$origWT = $parsoid->html2wikitext( $pageConfig, $editedHTML, [], $selserData );
|
2022-04-04 10:44:11 +00:00
|
|
|
|
|
|
|
|
if ( $test->changetree === [ 5 ] ) {
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
$origWT = preg_replace( '/<!--' . ParserTest::STATIC_RANDOM_STRING . '-->/', '', $origWT );
|
2022-04-04 10:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
return $this->processResults(
|
2022-05-20 20:42:25 +00:00
|
|
|
$test, $mode, $expectedWT, $origWT, [ $test, "normalizeWT" ]
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Parsoid $parsoid
|
|
|
|
|
* @param PageConfig $pageConfig
|
|
|
|
|
* @param ParserTest $test
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTestMode $mode
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
* @param Document $doc
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
private function runSelserEditTest(
|
2022-05-20 20:42:25 +00:00
|
|
|
Parsoid $parsoid, PageConfig $pageConfig, ParserTest $test, ParserTestMode $mode, Document $doc
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
): array {
|
|
|
|
|
$test->applyChanges( [], $doc, $test->changetree );
|
|
|
|
|
$editedHTML = ContentUtils::toXML( DOMCompat::getBody( $doc ) );
|
|
|
|
|
|
|
|
|
|
// Run selser on edited doc
|
|
|
|
|
$selserData = new SelserData( $test->wikitext, $test->cachedBODYstr );
|
|
|
|
|
$origWT = $parsoid->html2wikitext( $pageConfig, $editedHTML, [], $selserData );
|
|
|
|
|
|
|
|
|
|
$ptResult = $this->processResults(
|
2022-05-20 20:42:25 +00:00
|
|
|
$test, $mode,
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
static function () use ( $parsoid, $pageConfig, $editedHTML ): string {
|
|
|
|
|
return $parsoid->html2wikitext( $pageConfig, $editedHTML );
|
|
|
|
|
},
|
|
|
|
|
$origWT, [ $test, "normalizeWT" ]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return [ $ptResult->actual, $ptResult->expected ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Parsoid $parsoid
|
|
|
|
|
* @param PageConfig $pageConfig
|
|
|
|
|
* @param ParserTest $test
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTestMode $mode
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
* @return ParserTestResult|false false if skipped
|
|
|
|
|
*/
|
2022-05-20 20:42:25 +00:00
|
|
|
private function selserAutoEdit( Parsoid $parsoid, PageConfig $pageConfig, ParserTest $test, ParserTestMode $mode ) {
|
2022-07-18 23:54:45 +00:00
|
|
|
$html = $test->sections['html/parsoid+integrated'] ?? $test->parsoidHtml;
|
|
|
|
|
if ( $html === null ) {
|
|
|
|
|
// We currently don't run this in standalone mode.
|
|
|
|
|
// The expectation is to add html/parsoid sections
|
|
|
|
|
// if we want to run these tests.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-05-20 20:42:25 +00:00
|
|
|
Assert::invariant(
|
|
|
|
|
$test->wikitext !== null,
|
|
|
|
|
"All tests include a wikitext section"
|
|
|
|
|
);
|
2022-05-14 05:06:03 +00:00
|
|
|
|
|
|
|
|
// Apply edits to the HTML.
|
|
|
|
|
// Always serialize to string and reparse before passing to selser/wt2wt.
|
2022-05-20 20:42:25 +00:00
|
|
|
$doc = $this->fetchCachedDoc( $parsoid, $pageConfig, $test );
|
2022-05-14 05:06:03 +00:00
|
|
|
if ( !$test->changetree ) {
|
|
|
|
|
$test->changetree = $test->generateChanges( $doc );
|
|
|
|
|
if ( !$test->changetree ) {
|
2022-05-20 20:42:25 +00:00
|
|
|
// No more changes to make
|
2022-05-14 05:06:03 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2022-05-20 20:42:25 +00:00
|
|
|
$mode = new ParserTestMode( 'selser', $test->changetree );
|
2022-05-14 05:06:03 +00:00
|
|
|
}
|
2022-05-20 20:42:25 +00:00
|
|
|
[ $out, $expected ] = $this->runSelserEditTest( $parsoid, $pageConfig, $test, $mode, $doc );
|
2023-04-06 01:15:20 +00:00
|
|
|
return new ParserTestResult( $test, $mode, $expected, $out );
|
2022-05-14 05:06:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Parsoid $parsoid
|
|
|
|
|
* @param PageConfig $pageConfig
|
|
|
|
|
* @param ParserTest $test
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTestMode $mode
|
2022-05-14 05:06:03 +00:00
|
|
|
* @return ParserTestResult|false false if skipped
|
|
|
|
|
*/
|
2022-05-20 20:42:25 +00:00
|
|
|
private function selserAutoEditComposite( Parsoid $parsoid, PageConfig $pageConfig, ParserTest $test, ParserTestMode $mode ) {
|
2024-01-25 22:08:56 +00:00
|
|
|
$html = $test->sections['html/parsoid+integrated'] ?? $test->parsoidHtml;
|
|
|
|
|
if ( $html === null ) {
|
|
|
|
|
// We currently don't run this in standalone mode.
|
|
|
|
|
// The expectation is to add html/parsoid sections
|
|
|
|
|
// if we want to run these tests.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-05-20 20:42:25 +00:00
|
|
|
Assert::invariant(
|
|
|
|
|
$test->wikitext !== null,
|
|
|
|
|
"All tests include a wikitext section"
|
|
|
|
|
);
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
|
|
|
|
|
if ( $test->changetree ) {
|
|
|
|
|
// Apply edits to the HTML.
|
|
|
|
|
// Always serialize to string and reparse before passing to selser/wt2wt.
|
2022-05-20 20:42:25 +00:00
|
|
|
$doc = $this->fetchCachedDoc( $parsoid, $pageConfig, $test );
|
|
|
|
|
Assert::invariant(
|
|
|
|
|
$mode->changetree === $test->changetree,
|
|
|
|
|
"changetree should be consistent with mode"
|
|
|
|
|
);
|
|
|
|
|
[ $out, $expected ] = $this->runSelserEditTest( $parsoid, $pageConfig, $test, $mode, $doc );
|
|
|
|
|
return new ParserTestResult( $test, $mode, $expected, $out );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
} else {
|
2022-05-20 20:42:25 +00:00
|
|
|
// this mode is a composite of multiple selser tests
|
|
|
|
|
$mode = new ParserTestMode( "selserAutoEdits" );
|
2024-01-25 22:08:56 +00:00
|
|
|
$runnerOpts = $this->getOptions();
|
2024-01-25 21:18:32 +00:00
|
|
|
$numChanges = $runnerOpts['numchanges'] ?: 20; // default in Parsoid
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
$bufOut = "";
|
|
|
|
|
$bufExpected = "";
|
|
|
|
|
for ( $i = 0; $i < $numChanges; $i++ ) {
|
|
|
|
|
// Apply edits to the HTML.
|
|
|
|
|
// Always serialize to string and reparse before passing to selser/wt2wt.
|
2022-05-20 20:42:25 +00:00
|
|
|
$doc = $this->fetchCachedDoc( $parsoid, $pageConfig, $test );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
$test->seed = $i . '';
|
|
|
|
|
$test->changetree = $test->generateChanges( $doc );
|
|
|
|
|
if ( $test->changetree ) {
|
2022-05-20 20:42:25 +00:00
|
|
|
// new mode with the generated changetree
|
|
|
|
|
$nmode = new ParserTestMode( 'selser', $test->changetree );
|
|
|
|
|
[ $out, $expected ] = $this->runSelserEditTest( $parsoid, $pageConfig, $test, $nmode, $doc );
|
|
|
|
|
$testTitle = "TEST: {$test->testName} ($nmode)\n";
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
$bufOut .= $testTitle;
|
|
|
|
|
$bufExpected .= $testTitle;
|
|
|
|
|
$bufOut .= "RESULT: $out\n";
|
|
|
|
|
$bufExpected .= "RESULT: $expected\n";
|
|
|
|
|
}
|
|
|
|
|
// $test->changetree can be [] which is a NOP for testing
|
|
|
|
|
// but not a NOP for duplicate change tree tests.
|
|
|
|
|
if ( $test->isDuplicateChangeTree( $test->changetree ) ) {
|
|
|
|
|
// Once we get a duplicate change tree, we can no longer
|
|
|
|
|
// generate and run new tests. So, be done now!
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
$test->selserChangeTrees[$i] = $test->changetree;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-20 20:42:25 +00:00
|
|
|
return new ParserTestResult( $test, $mode, $bufExpected, $bufOut );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
}
|
2022-04-04 10:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-26 22:13:37 +00:00
|
|
|
private function setupParserOptionsAndBuildPageConfig( ParserTest $test ): PageConfig {
|
2022-04-21 10:54:28 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$pageConfigFactory = $services->get( 'ParsoidPageConfigFactory' );
|
|
|
|
|
$pageConfig = null;
|
|
|
|
|
$runner = $this;
|
2023-02-04 21:16:31 +00:00
|
|
|
$this->setupParserOptions(
|
2022-04-21 10:54:28 +00:00
|
|
|
$test,
|
2022-08-27 21:28:14 +00:00
|
|
|
static function ( $context, $title, $revProps ) use ( $runner, $pageConfigFactory, &$pageConfig ) {
|
2022-04-21 10:54:28 +00:00
|
|
|
$user = $context->getUser();
|
2022-08-27 21:28:14 +00:00
|
|
|
$revRecord = $revProps['rev'] ?? null;
|
|
|
|
|
if ( !$revRecord ) {
|
|
|
|
|
// Unlike the legacy parser which doesn't need an actual revrecord to parse
|
|
|
|
|
// wikitext, Parsoid creates a PageConfig which needs an actual revrecord.
|
|
|
|
|
// So create a fake mutable on here.
|
|
|
|
|
$revRecord = $runner->createRevRecord( $title, $user, $revProps );
|
|
|
|
|
}
|
2023-07-14 20:07:22 +00:00
|
|
|
$page = MediaWikiServices::getInstance()->getTitleFactory()->newFromLinkTarget( $title );
|
2022-04-21 10:54:28 +00:00
|
|
|
$pageConfig = $pageConfigFactory->create(
|
2023-07-14 20:07:22 +00:00
|
|
|
$page, $user, $revRecord, null, null
|
2022-04-21 10:54:28 +00:00
|
|
|
);
|
|
|
|
|
return $pageConfig->getParserOptions();
|
|
|
|
|
} );
|
2022-09-26 22:13:37 +00:00
|
|
|
'@phan-var PageConfig $pageConfig'; // assert that this is not null
|
|
|
|
|
return $pageConfig;
|
2022-04-21 10:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
/**
|
|
|
|
|
* Helper function to register a Parsoid extension module in such a
|
|
|
|
|
* way that it can be cleaned up after the test is complete.
|
|
|
|
|
* @param SiteConfig $siteConfig
|
|
|
|
|
* @param class-string<ExtensionModule> $moduleName
|
|
|
|
|
* @return callable
|
|
|
|
|
*/
|
|
|
|
|
private static function registerExtensionModule( SiteConfig $siteConfig, string $moduleName ): callable {
|
|
|
|
|
$id = $siteConfig->registerExtensionModule( $moduleName );
|
|
|
|
|
return static function () use ( $siteConfig, $id ) {
|
|
|
|
|
$siteConfig->unregisterExtensionModule( $id );
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 18:36:57 +00:00
|
|
|
/**
|
|
|
|
|
* Run a given wikitext input through a freshly-constructed Parsoid parser,
|
|
|
|
|
* running in 'integrated' mode, and compare the output against the
|
|
|
|
|
* expected results.
|
|
|
|
|
*
|
|
|
|
|
* Prints status and explanatory messages to stdout.
|
|
|
|
|
*
|
|
|
|
|
* staticSetup() and setupWikiData() must be called before this function
|
|
|
|
|
* is entered.
|
|
|
|
|
*
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
* @param ParserTest $test The test parameters:
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTestMode $mode Parsoid test mode to run (including specific
|
|
|
|
|
* changetree to run selser test in, if applicable)
|
2022-03-14 18:36:57 +00:00
|
|
|
*
|
|
|
|
|
* @return ParserTestResult|false false if skipped
|
|
|
|
|
*/
|
2022-05-20 20:42:25 +00:00
|
|
|
public function runParsoidTest( ParserTest $test, ParserTestMode $mode ) {
|
|
|
|
|
wfDebug( __METHOD__ . ": running {$test->testName} [$mode]" );
|
2023-02-09 21:15:04 +00:00
|
|
|
$opts = $test->options;
|
2022-03-15 11:15:18 +00:00
|
|
|
|
|
|
|
|
// Skip tests targetting features Parsoid doesn't (yet) support
|
|
|
|
|
// @todo T270312
|
|
|
|
|
if ( isset( $opts['styletag'] ) || isset( $opts['pst'] ) ||
|
|
|
|
|
isset( $opts['msg'] ) || isset( $opts['section'] ) ||
|
|
|
|
|
isset( $opts['replace'] ) || isset( $opts['comment'] ) ||
|
2023-02-22 20:01:56 +00:00
|
|
|
isset( $opts['preload'] )
|
2022-03-15 11:15:18 +00:00
|
|
|
) {
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
return false;
|
2022-03-15 11:15:18 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
$teardownGuard = $this->perTestSetup( $test );
|
2022-09-26 22:13:37 +00:00
|
|
|
$pageConfig = $this->setupParserOptionsAndBuildPageConfig( $test );
|
|
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
$teardown = [];
|
2020-07-24 04:41:09 +00:00
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
// Register any special extensions required by this test case
|
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$siteConfig = $services->get( 'ParsoidSiteConfig' );
|
2022-10-03 16:44:33 +00:00
|
|
|
$siteConfig->getLogger()->log( 'debug', "\n------ LOGS for {$test->testName} [$mode] ------" );
|
2022-05-20 20:42:25 +00:00
|
|
|
$teardown[] = self::registerExtensionModule( $siteConfig, ParsoidParserHook::class );
|
|
|
|
|
if ( ( $test->options['wgrawhtml'] ?? null ) === '1' ) {
|
|
|
|
|
$teardown[] = self::registerExtensionModule( $siteConfig, ParsoidRawHTML::class );
|
2022-03-15 11:15:18 +00:00
|
|
|
}
|
2022-05-20 20:42:25 +00:00
|
|
|
if ( isset( $test->options['styletag'] ) ) {
|
|
|
|
|
$teardown[] = self::registerExtensionModule( $siteConfig, ParsoidStyleTag::class );
|
|
|
|
|
}
|
|
|
|
|
// unregister these after this test
|
|
|
|
|
$teardownGuard = $this->createTeardownObject( $teardown, $teardownGuard );
|
|
|
|
|
|
|
|
|
|
// Create the Parsoid object. (This is cheap, since the SiteConfig
|
|
|
|
|
// and DataAccess are cached by the ServiceContainer.)
|
|
|
|
|
$dataAccess = $services->get( 'ParsoidDataAccess' );
|
|
|
|
|
$parsoid = new Parsoid( $siteConfig, $dataAccess );
|
|
|
|
|
switch ( $mode->mode ) {
|
2022-04-02 06:27:47 +00:00
|
|
|
case 'wt2html':
|
|
|
|
|
case 'wt2html+integrated':
|
2022-05-20 20:42:25 +00:00
|
|
|
$res = $this->wt2html( $parsoid, $pageConfig, $test, $mode );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
break;
|
2022-04-02 06:27:47 +00:00
|
|
|
|
|
|
|
|
case 'wt2wt':
|
2022-05-20 20:42:25 +00:00
|
|
|
$res = $this->wt2wt( $parsoid, $pageConfig, $test, $mode );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
break;
|
2022-04-02 06:27:47 +00:00
|
|
|
|
|
|
|
|
case 'html2wt':
|
2022-05-20 20:42:25 +00:00
|
|
|
$res = $this->html2wt( $parsoid, $pageConfig, $test, $mode );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
break;
|
2022-04-02 06:27:47 +00:00
|
|
|
|
|
|
|
|
case 'html2html':
|
2022-05-20 20:42:25 +00:00
|
|
|
$res = $this->html2html( $parsoid, $pageConfig, $test, $mode );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
break;
|
2022-04-02 06:27:47 +00:00
|
|
|
|
2022-04-04 10:44:11 +00:00
|
|
|
case 'selser':
|
2022-05-20 20:42:25 +00:00
|
|
|
$test->changetree = $mode->changetree;
|
|
|
|
|
$res = $this->selser( $parsoid, $pageConfig, $test, $mode );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
$test->changetree = null; // Reset after each selser test
|
|
|
|
|
break;
|
|
|
|
|
|
2022-05-14 05:06:03 +00:00
|
|
|
case 'selser-auto-composite':
|
2022-05-20 20:42:25 +00:00
|
|
|
$test->changetree = $mode->changetree;
|
|
|
|
|
$res = $this->selserAutoEditComposite( $parsoid, $pageConfig, $test, $mode );
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
$test->changetree = null; // Reset after each selser test
|
|
|
|
|
break;
|
2022-04-04 10:44:11 +00:00
|
|
|
|
2022-05-14 05:06:03 +00:00
|
|
|
case 'selser-auto':
|
2022-05-20 20:42:25 +00:00
|
|
|
$test->changetree = $mode->changetree;
|
|
|
|
|
$res = $this->selserAutoEdit( $parsoid, $pageConfig, $test, $mode );
|
2024-01-25 04:39:35 +00:00
|
|
|
if ( $res === false && !$test->changetree ) {
|
|
|
|
|
// TEMPORARY HACK
|
|
|
|
|
// If we don't run any selser tests, ensure changetree is not null
|
|
|
|
|
// because we are going to call Test::isDuplicateChangeTree() on it
|
|
|
|
|
// This ensures that we continue to crash if change tree is null
|
|
|
|
|
// for any other reason!
|
|
|
|
|
$test->changetree = [];
|
|
|
|
|
}
|
2022-05-14 05:06:03 +00:00
|
|
|
// Don't reset changetree here -- it is used to detect duplicate trees
|
|
|
|
|
// and stop selser test generation in Test.php::testAllModes
|
|
|
|
|
break;
|
|
|
|
|
|
2022-04-02 06:27:47 +00:00
|
|
|
default:
|
|
|
|
|
// Unsupported Mode
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
$res = false;
|
|
|
|
|
break;
|
2020-07-24 04:41:09 +00:00
|
|
|
}
|
ParserTest runner improvements (improve feature parity with Parsoid)
This patch improves the parser test runner in the following ways:
1. Adds Parsoid selser auto-edit test support
Since it isn't possible to dynamically add tests in PHPUnit
(unlike the home-grown parser test runners), to support selser
auto-edit tests, we create a single composite test that includes
all the individual edits. If a single test fails, the whole test
is considering failing.
The test output from all the individual tests are combined into
composite expected / actual strings and test failure diffs reveals
diffs for individual tests.
Future patches could enhance output further.
2. Ensure that we skip HTML-based Parsoid test modes without appropriate
input HTML
3. Pass additional options to the parser test runner via the
ParserTestTopLevelSuite constructor. These support extended
functionality of the Parsoid parser test runner which are being
made available to core.
At the moment the constructor will attempt to JSON-decode the
PARSERTEST_FLAGS environment variable to supply defaults for
these flags, which provides a hacky sort of way to pass arguments
on the command line. This will be integrated with the existing
$flags passed to ParserTestTopLevelSuite in the future (T308367).
4. Add support for running tests in specific modes as well
as ability to update the known failures json file.
This includes some missing code to run per-test teardown functions
in runParsoidTest.
Unlike the Parsoid parser test runner, you can combine
updateKnownFailures with --filter as well as with subset of
test modes, including possibly specific selser changetrees.
If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var,
you can also update the knownFailures result for only the tests
that are run.
However, note that this could change the sort order in the
*-knownFailures.json file. This leads to dirty (git) diffs when
a full updateKnownFailures is run on the file. I am not going to
tackle this issue for now since this is an obscure use case that
is unlikely to be used much, if at all.
Overall, if I copy over the -knownFailures.json file from the Parsoid
repo into the Cite repo and update it with a phpunit.php run in core,
it updates the known failures to reflect changes to test results from
an integrated test run. A second run doesn't lead to any additional
changes to the knownFailures.json file or to any test failures. I had
to fix some bugs (referenced in the previous paragraph) to ensure
this idempotence beyond the first run.
This patch also cleans up some function signatures to use Test object
It maps the Test object from the Parsoid repo to an associative array
that a bunch of (legacy) parser test functions expect.
This patch squashes the following previous patches:
I2f46b4b94b44aec76e33403455eb466899376a6b
Ib01991089ec410dd45f77a20b136c8e05d855fa4
Id0ef01e333580892aa6d415b8f66c4393b06870d
Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
2022-04-06 09:36:37 +00:00
|
|
|
|
|
|
|
|
ScopedCallback::consume( $teardownGuard );
|
|
|
|
|
return $res;
|
2020-07-24 04:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-09 22:33:00 +00:00
|
|
|
/**
|
|
|
|
|
* Use a regex to find out the value of an option
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string $key Name of option val to retrieve
|
|
|
|
|
* @param array $opts Options array to look in
|
|
|
|
|
* @param mixed $default Default value returned if not found
|
2014-08-25 16:50:35 +00:00
|
|
|
* @return mixed
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
|
|
|
|
private static function getOptionValue( $key, $opts, $default ) {
|
|
|
|
|
$key = strtolower( $key );
|
2019-03-24 21:40:49 +00:00
|
|
|
return $opts[$key] ?? $default;
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* Do any required setup which is dependent on test options.
|
|
|
|
|
*
|
|
|
|
|
* @see staticSetup() for more information about setup/teardown
|
|
|
|
|
*
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTest $test Test info supplied by TestFileReader
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* @param callable|null $nextTeardown
|
|
|
|
|
* @return ScopedCallback
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
2022-05-20 20:42:25 +00:00
|
|
|
public function perTestSetup( ParserTest $test, $nextTeardown = null ) {
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$teardown = [];
|
|
|
|
|
|
2020-12-23 18:52:12 +00:00
|
|
|
$this->checkSetupDone( 'setupDatabase' );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$teardown[] = $this->markSetupDone( 'perTestSetup' );
|
|
|
|
|
|
2022-05-20 20:42:25 +00:00
|
|
|
$opts = $test->options;
|
2023-03-17 08:54:00 +00:00
|
|
|
$mwServices = MediaWikiServices::getInstance();
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
|
|
|
|
|
// Find out values for some special options.
|
|
|
|
|
$langCode =
|
2012-01-09 22:33:00 +00:00
|
|
|
self::getOptionValue( 'language', $opts, 'en' );
|
2023-10-17 19:54:32 +00:00
|
|
|
$variant = // old deprecated option name
|
2012-01-09 22:33:00 +00:00
|
|
|
self::getOptionValue( 'variant', $opts, false );
|
2023-10-17 19:54:32 +00:00
|
|
|
$variant =
|
|
|
|
|
self::getOptionValue( 'htmlVariantLanguage', $opts, $variant );
|
2012-01-09 22:33:00 +00:00
|
|
|
$maxtoclevel =
|
|
|
|
|
self::getOptionValue( 'wgMaxTocLevel', $opts, 999 );
|
|
|
|
|
$linkHolderBatchSize =
|
|
|
|
|
self::getOptionValue( 'wgLinkHolderBatchSize', $opts, 1000 );
|
2024-07-12 01:19:12 +00:00
|
|
|
$timezone =
|
|
|
|
|
self::getOptionValue( 'wgLocaltimezone', $opts, 'UTC' );
|
2012-01-09 22:33:00 +00:00
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$setup = [
|
2012-01-09 22:33:00 +00:00
|
|
|
'wgEnableUploads' => self::getOptionValue( 'wgEnableUploads', $opts, true ),
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
'wgLanguageCode' => $langCode,
|
2013-07-10 22:10:14 +00:00
|
|
|
'wgRawHtml' => self::getOptionValue( 'wgRawHtml', $opts, false ),
|
2017-02-23 21:14:54 +00:00
|
|
|
'wgNamespacesWithSubpages' => array_fill_keys(
|
2023-03-17 08:54:00 +00:00
|
|
|
$mwServices->getNamespaceInfo()->getValidNamespaces(),
|
2018-08-05 17:58:51 +00:00
|
|
|
isset( $opts['subpage'] )
|
2017-02-23 21:14:54 +00:00
|
|
|
),
|
2012-01-09 22:33:00 +00:00
|
|
|
'wgMaxTocLevel' => $maxtoclevel,
|
2013-07-10 22:10:14 +00:00
|
|
|
'wgAllowExternalImages' => self::getOptionValue( 'wgAllowExternalImages', $opts, true ),
|
2022-04-13 09:19:47 +00:00
|
|
|
'wgThumbLimits' => [ 0, 0, 0, 0, 0, self::getOptionValue( 'thumbsize', $opts, 180 ) ],
|
2012-01-09 22:33:00 +00:00
|
|
|
'wgDefaultLanguageVariant' => $variant,
|
|
|
|
|
'wgLinkHolderBatchSize' => $linkHolderBatchSize,
|
2016-09-09 07:28:49 +00:00
|
|
|
// Set as a JSON object like:
|
|
|
|
|
// wgEnableMagicLinks={"ISBN":false, "PMID":false, "RFC":false}
|
|
|
|
|
'wgEnableMagicLinks' => self::getOptionValue( 'wgEnableMagicLinks', $opts, [] )
|
|
|
|
|
+ [ 'ISBN' => true, 'PMID' => true, 'RFC' => true ],
|
2017-06-30 00:13:12 +00:00
|
|
|
// Test with legacy encoding by default until HTML5 is very stable and default
|
|
|
|
|
'wgFragmentMode' => [ 'legacy' ],
|
2022-10-13 21:03:32 +00:00
|
|
|
// Use legacy headings for a while until tests in extensions are updated
|
|
|
|
|
'wgParserEnableLegacyHeadingDOM' => true,
|
2024-07-12 01:19:12 +00:00
|
|
|
'wgLocaltimezone' => $timezone,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-01-09 22:33:00 +00:00
|
|
|
|
ParserTestRunner: Fix handling of externallinktarget option
* There are two places in the parser test runner where test options
are processed: perTestSetup, and setupParserOptions. There isn't
enough guidance as to what should be set up where and why.
But, anything that is really a wiki config/global should ideally
be set up in perTestSetup because the ParserOptions object loads
all its defaults from the config values anyway.
* Parsoid gets wiki-specific options from SiteConfig and page-specific
options from PageConfig.
In 61c14054, "externallinktarget" was treated as a wiki-specific opt
by adding it to SiteConfig. So, if Parsoid is to see a test opt,
(a) the corresponding config/global should be initialized
(b) it should be processed before SiteConfig is constructed
* So, all that said, any test option that impacts Parsoid's SiteConfig
should therefore be set in perTestSetup as well whch also matches
my understanding of how it should be set up for legacy tests as well.
* This fix now ensures that external link target tests pass in Parsoid's
integrated mode as well.
* Based on above, couple other things that I'll fix up in followups:
- There are a couple other configs (maxtemplatedepth, maxincludesize)
that are being initialized in setupParserOptions which should
probably be moved to perTestSetup.
- runLegacyTest calls perTestSetup and setupParserOptions back-to-back
but runParsoidTest doesn't do that. Those are separated by code
that sets up SiteConfig and DataAccess. This shouldn't matter if the
above guidelines for initialization are followed appropriately,
but just for consistency's sake, I might try to move those two
closer together in another followup.
Followup-To: f7d6c0190d18d2337080f041a4a64efd45737236
Change-Id: I776b22a973fbcc945106fbe807376b858dd79e48
2022-09-26 21:16:14 +00:00
|
|
|
if ( isset( $opts['externallinktarget'] ) ) {
|
|
|
|
|
$setup['wgExternalLinkTarget'] = self::getOptionValue( 'externallinktarget', $opts, '' );
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-27 05:57:55 +00:00
|
|
|
$nonIncludable = self::getOptionValue( 'wgNonincludableNamespaces', $opts, false );
|
|
|
|
|
if ( $nonIncludable !== false ) {
|
|
|
|
|
$setup['wgNonincludableNamespaces'] = [ $nonIncludable ];
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 15:09:32 +00:00
|
|
|
if ( $test->config ) {
|
|
|
|
|
foreach ( $test->config as $var => $value ) {
|
|
|
|
|
$setup[$var] = $value;
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 14:55:28 +00:00
|
|
|
/** @since 1.20 */
|
2023-05-06 20:01:10 +00:00
|
|
|
( new HookRunner( $mwServices->getHookContainer() ) )->onParserTestGlobals( $setup );
|
2012-08-20 14:55:28 +00:00
|
|
|
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
// Take care of the content language and variant
|
|
|
|
|
$resetVariant = $variant !== false || isset( $test->config['wgUsePigLatinVariant'] );
|
|
|
|
|
if ( $langCode !== 'en' || $resetVariant ) {
|
|
|
|
|
$this->resetLanguageServices( $setup, $teardown, $resetVariant );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Other services that can be configured per test
|
2023-03-17 08:54:00 +00:00
|
|
|
$reset = function () use ( $mwServices ) {
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
// Configurations changed above
|
2023-06-26 08:22:46 +00:00
|
|
|
$this->resetTitleServices();
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
$mwServices->resetServiceForTesting( 'MagicWordFactory' );
|
2020-09-17 00:31:54 +00:00
|
|
|
$mwServices->resetServiceForTesting( 'ParserFactory' );
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
// Depends on $wgParserEnableLegacyMediaDOM
|
|
|
|
|
$mwServices->resetServiceForTesting( 'Tidy' );
|
2022-10-13 21:03:32 +00:00
|
|
|
// Depends on $wgParserEnableLegacyHeadingDOM
|
|
|
|
|
$mwServices->resetServiceForTesting( 'DefaultOutputPipeline' );
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
// The SiteConfig depends on various services that reset above,
|
2023-06-26 08:22:46 +00:00
|
|
|
// so reset it as well.
|
|
|
|
|
// T310283: be more selective about resetting SiteConfig if
|
|
|
|
|
// performance is a concern.
|
|
|
|
|
$mwServices->resetServiceForTesting( 'ParsoidSiteConfig' );
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
// Depends on the legacy ParserFactory
|
2023-06-26 08:22:46 +00:00
|
|
|
$mwServices->resetServiceForTesting( 'ParsoidDataAccess' );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
};
|
|
|
|
|
$setup[] = $reset;
|
|
|
|
|
$teardown[] = $reset;
|
|
|
|
|
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
// Clear language conversion tables
|
|
|
|
|
$teardown[] = static function () use ( $mwServices, $langCode ) {
|
|
|
|
|
$lang = $mwServices->getLanguageFactory()->getLanguage( $langCode );
|
2017-06-27 21:09:12 +00:00
|
|
|
$wrapper = TestingAccessWrapper::newFromObject(
|
2023-03-17 08:54:00 +00:00
|
|
|
$mwServices->getLanguageConverterFactory()
|
2023-01-26 16:54:24 +00:00
|
|
|
->getLanguageConverter( $lang )
|
2017-06-27 21:09:12 +00:00
|
|
|
);
|
2022-02-24 19:57:59 +00:00
|
|
|
@$wrapper->reloadTables();
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
};
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2023-09-06 06:01:54 +00:00
|
|
|
// Reset OOUI auto-increment IDs (T345515)
|
|
|
|
|
OOUI\Tag::resetElementId();
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$teardown[] = $this->executeSetupSnippets( $setup );
|
2016-04-25 05:41:32 +00:00
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
return $this->createTeardownObject( $teardown, $nextTeardown );
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
private function resetLanguageServices( array &$setup, array &$teardown, $resetVariant = false ) {
|
|
|
|
|
$mwServices = MediaWikiServices::getInstance();
|
|
|
|
|
$reset = static function () use ( $mwServices, $resetVariant ) {
|
|
|
|
|
$mwServices->resetServiceForTesting( 'ContentLanguage' );
|
|
|
|
|
|
|
|
|
|
if ( $resetVariant ) {
|
|
|
|
|
// If !!config touches $wgUsePigLatinVariant, these need to be reset
|
|
|
|
|
$mwServices->resetServiceForTesting( 'LanguageConverterFactory' );
|
|
|
|
|
$mwServices->resetServiceForTesting( 'LanguageFactory' );
|
|
|
|
|
$mwServices->resetServiceForTesting( 'LanguageNameUtils' );
|
|
|
|
|
$mwServices->resetServiceForTesting( 'LocalisationCache' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Content language invalidates a lot of services.
|
|
|
|
|
$mwServices->resetServiceForTesting( 'UserOptionsManager' );
|
|
|
|
|
$mwServices->resetServiceForTesting( 'UserOptionsLookup' );
|
|
|
|
|
$mwServices->resetServiceForTesting( 'MessageCache' );
|
|
|
|
|
|
|
|
|
|
// Purge the cached Language object
|
|
|
|
|
$context = RequestContext::getMain();
|
|
|
|
|
$context->setUser( $context->getUser() );
|
|
|
|
|
};
|
|
|
|
|
$setup[] = $reset;
|
|
|
|
|
$teardown[] = $reset;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-09 22:33:00 +00:00
|
|
|
/**
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* Set up temporary DB tables.
|
|
|
|
|
*
|
|
|
|
|
* For best performance, call this once only for all tests. However, it can
|
|
|
|
|
* be called at the start of each test if more isolation is desired.
|
|
|
|
|
*
|
|
|
|
|
*
|
2020-12-23 18:52:12 +00:00
|
|
|
* Do not call this function from a MediaWikiIntegrationTestCase subclass,
|
|
|
|
|
* since MediaWikiIntegrationTestCase does its own DB setup.
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
*
|
|
|
|
|
* @see staticSetup() for more information about setup/teardown
|
|
|
|
|
*
|
|
|
|
|
* @param ScopedCallback|null $nextTeardown The next teardown object
|
|
|
|
|
* @return ScopedCallback The teardown object
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
public function setupDatabase( $nextTeardown = null ) {
|
2012-01-09 22:33:00 +00:00
|
|
|
global $wgDBprefix;
|
|
|
|
|
|
2020-12-23 18:52:12 +00:00
|
|
|
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
2022-06-21 20:29:51 +00:00
|
|
|
$this->db = $lb->getConnectionInternal( DB_PRIMARY );
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2020-12-23 18:52:12 +00:00
|
|
|
$suspiciousPrefixes = [ self::DB_PREFIX, MediaWikiIntegrationTestCase::DB_PREFIX ];
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
if ( in_array( $wgDBprefix, $suspiciousPrefixes ) ) {
|
2023-06-03 15:25:27 +00:00
|
|
|
throw new RuntimeException( "\$wgDBprefix=$wgDBprefix suggests DB setup is already done" );
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$teardown = [];
|
|
|
|
|
$teardown[] = $this->markSetupDone( 'setupDatabase' );
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2020-12-23 18:52:12 +00:00
|
|
|
// Set up a test DB just for parser tests
|
|
|
|
|
MediaWikiIntegrationTestCase::setupAllTestDBs(
|
|
|
|
|
$this->db,
|
|
|
|
|
self::DB_PREFIX,
|
|
|
|
|
true // postgres requires that we use temporary tables
|
|
|
|
|
);
|
|
|
|
|
MediaWikiIntegrationTestCase::resetNonServiceCaches();
|
2021-02-06 19:40:52 +00:00
|
|
|
$teardown[] = static function () {
|
2020-12-23 18:52:12 +00:00
|
|
|
MediaWikiIntegrationTestCase::teardownTestDB();
|
|
|
|
|
};
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2020-12-23 18:52:12 +00:00
|
|
|
MediaWikiIntegrationTestCase::installMockMwServices();
|
2021-02-06 19:40:52 +00:00
|
|
|
$teardown[] = static function () {
|
2020-12-23 18:52:12 +00:00
|
|
|
MediaWikiIntegrationTestCase::restoreMwServices();
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Wipe some DB query result caches on setup and teardown
|
2021-02-06 19:40:52 +00:00
|
|
|
$reset = static function () {
|
2020-03-14 12:58:53 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$services->getLinkCache()->clear();
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
|
|
|
|
|
// Clear the message cache
|
2020-03-14 12:58:53 +00:00
|
|
|
$services->getMessageCache()->clear();
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
};
|
|
|
|
|
$reset();
|
|
|
|
|
$teardown[] = $reset;
|
|
|
|
|
return $this->createTeardownObject( $teardown, $nextTeardown );
|
|
|
|
|
}
|
2012-01-09 22:33:00 +00:00
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
/**
|
|
|
|
|
* Add data about uploads to the new test DB, and set up the upload
|
2020-12-23 18:52:12 +00:00
|
|
|
* directory. This should be called after setupDatabase().
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
*
|
|
|
|
|
* @param ScopedCallback|null $nextTeardown The next teardown object
|
|
|
|
|
* @return ScopedCallback The teardown object
|
|
|
|
|
*/
|
|
|
|
|
public function setupUploads( $nextTeardown = null ) {
|
|
|
|
|
$teardown = [];
|
|
|
|
|
|
2020-12-23 18:52:12 +00:00
|
|
|
$this->checkSetupDone( 'setupDatabase' );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$teardown[] = $this->markSetupDone( 'setupUploads' );
|
2012-01-09 22:33:00 +00:00
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
// Create the files in the upload directory (or pretend to create them
|
|
|
|
|
// in a MockFileBackend). Append teardown callback.
|
|
|
|
|
$teardown[] = $this->setupUploadBackend();
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2023-07-14 19:18:01 +00:00
|
|
|
// Create a authority
|
|
|
|
|
$performer = new UltimateAuthority( new UserIdentityValue( 0, User::MAINTENANCE_SCRIPT_USER ) );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
|
|
|
|
|
// Register the uploads in the database
|
2020-03-08 21:47:14 +00:00
|
|
|
$localRepo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
|
2023-07-14 20:07:22 +00:00
|
|
|
$image = $localRepo->newFile( new TitleValue( NS_FILE, 'Foobar.jpg' ) );
|
2013-02-27 00:12:12 +00:00
|
|
|
# note that the size/width/height/bits/etc of the file
|
|
|
|
|
# are actually set by inspecting the file itself; the arguments
|
2020-06-16 01:45:46 +00:00
|
|
|
# to recordUpload3 have no effect. That said, we try to make things
|
2013-02-27 00:12:12 +00:00
|
|
|
# match up so it is less confusing to readers of the code & tests.
|
2020-06-16 01:45:46 +00:00
|
|
|
$image->recordUpload3(
|
|
|
|
|
'',
|
|
|
|
|
'Upload of some lame file', 'Some lame file',
|
2023-07-14 19:18:01 +00:00
|
|
|
$performer,
|
2020-06-16 01:45:46 +00:00
|
|
|
[
|
|
|
|
|
'size' => 7881,
|
|
|
|
|
'width' => 1941,
|
|
|
|
|
'height' => 220,
|
|
|
|
|
'bits' => 8,
|
|
|
|
|
'media_type' => MEDIATYPE_BITMAP,
|
|
|
|
|
'mime' => 'image/jpeg',
|
Use the unserialized form of image metadata internally
Image metadata is usually a serialized string representing an array.
Passing the string around internally and having everything unserialize
it is an awkward convention.
Also, many image handlers were reading the file twice: once for
getMetadata() and again for getImageSize(). Often getMetadata()
would actually read the width and height and then throw it away.
So, in filerepo:
* Add File::getMetadataItem(), which promises to allow partial
loading of metadata per my proposal on T275268 in a future commit.
* Add File::getMetadataArray(), which returns the unserialized array.
Some file handlers were returning non-serializable strings from
getMetadata(), so I gave them a legacy array form ['_error' => ...]
* Changed MWFileProps to return the array form of metadata.
* Deprecate the weird File::getImageSize(). It was apparently not
called by anything, but was overridden by UnregisteredLocalFile.
* Wrap serialize/unserialize with File::getMetadataForDb() and
File::loadMetadataFromDb() in preparation for T275268.
In MediaHandler:
* Merged MediaHandler::getImageSize() and MediaHandler::getMetadata()
into getSizeAndMetadata(). Deprecated the old methods.
* Instead of isMetadataValid() we now have isFileMetadataValid(), which
only gets a File object, so it can decide what data it needs to load.
* Simplified getPageDimensions() by having it return false for non-paged
media. It was not called in that case, but was implemented anyway.
In specific handlers:
* Rename DjVuHandler::getUnserializedMetadata() and
extractTreesFromMetadata() for clarity. "Metadata" in these function
names meant an XML string.
* Updated DjVuImage::getImageSize() to provide image sizes in the new
style.
* In ExifBitmapHandler, getRotationForExif() now takes just the
Orientation tag, rather than a serialized string. Also renamed for
clarity.
* In GIFMetadataExtractor, return the width, height and bits per channel
instead of throwing them away. There was some conflation in
decodeBPP() which I picked apart. Refer to GIF89a section 18.
* In JpegMetadataExtractor, process the SOF0/SOF2 segment to extract
bits per channel, width, height and components (channel count). This
is essentially a port of PHP's getimagesize(), so should be bugwards
compatible.
* In PNGMetadataExtractor, return the width and height, which were
previously assigned to unused local variables. I verified the
implementation by referring to the specification.
* In SvgHandler, retain the version validation from unpackMetadata(),
but rename the function since it now takes an array as input.
In tests:
* In ExifBitmapTest, refactored some tests by using a provider.
* In GIFHandlerTest and PNGHandlerTest, I removed the tests in which
getMetadata() returns null, since it doesn't make sense when ported to
getMetadataArray(). I added tests for empty arrays instead.
* In tests, I retained serialization of input data since I figure it's
useful to confirm that existing database rows will continue to be read
correctly. I removed serialization of expected values, replacing them
with plain data.
* In tests, I replaced access to private class constants like
BROKEN_FILE with string literals, since stability is essential. If
the class constant changes, the test should fail.
Elsewhere:
* In maintenance/refreshImageMetadata.php, I removed the check for
shrinking image metadata, since it's not easy to implement and is
not future compatible. Image metadata is expected to shrink in
future.
Bug: T275268
Change-Id: I039785d5b6439d71dcc21dcb972177dba5c3a67d
2021-05-19 00:24:32 +00:00
|
|
|
'metadata' => [],
|
2020-06-16 01:45:46 +00:00
|
|
|
'sha1' => Wikimedia\base_convert( '1', 16, 36, 31 ),
|
|
|
|
|
'fileExists' => true
|
|
|
|
|
],
|
|
|
|
|
$this->db->timestamp( '20010115123500' )
|
|
|
|
|
);
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2023-07-14 20:07:22 +00:00
|
|
|
$image = $localRepo->newFile( new TitleValue( NS_FILE, 'Thumb.png' ) );
|
2013-02-27 00:12:12 +00:00
|
|
|
# again, note that size/width/height below are ignored; see above.
|
2020-06-16 01:45:46 +00:00
|
|
|
$image->recordUpload3(
|
|
|
|
|
'',
|
|
|
|
|
'Upload of some lame thumbnail',
|
|
|
|
|
'Some lame thumbnail',
|
2023-07-14 19:18:01 +00:00
|
|
|
$performer,
|
2020-06-16 01:45:46 +00:00
|
|
|
[
|
|
|
|
|
'size' => 22589,
|
|
|
|
|
'width' => 135,
|
|
|
|
|
'height' => 135,
|
|
|
|
|
'bits' => 8,
|
|
|
|
|
'media_type' => MEDIATYPE_BITMAP,
|
|
|
|
|
'mime' => 'image/png',
|
Use the unserialized form of image metadata internally
Image metadata is usually a serialized string representing an array.
Passing the string around internally and having everything unserialize
it is an awkward convention.
Also, many image handlers were reading the file twice: once for
getMetadata() and again for getImageSize(). Often getMetadata()
would actually read the width and height and then throw it away.
So, in filerepo:
* Add File::getMetadataItem(), which promises to allow partial
loading of metadata per my proposal on T275268 in a future commit.
* Add File::getMetadataArray(), which returns the unserialized array.
Some file handlers were returning non-serializable strings from
getMetadata(), so I gave them a legacy array form ['_error' => ...]
* Changed MWFileProps to return the array form of metadata.
* Deprecate the weird File::getImageSize(). It was apparently not
called by anything, but was overridden by UnregisteredLocalFile.
* Wrap serialize/unserialize with File::getMetadataForDb() and
File::loadMetadataFromDb() in preparation for T275268.
In MediaHandler:
* Merged MediaHandler::getImageSize() and MediaHandler::getMetadata()
into getSizeAndMetadata(). Deprecated the old methods.
* Instead of isMetadataValid() we now have isFileMetadataValid(), which
only gets a File object, so it can decide what data it needs to load.
* Simplified getPageDimensions() by having it return false for non-paged
media. It was not called in that case, but was implemented anyway.
In specific handlers:
* Rename DjVuHandler::getUnserializedMetadata() and
extractTreesFromMetadata() for clarity. "Metadata" in these function
names meant an XML string.
* Updated DjVuImage::getImageSize() to provide image sizes in the new
style.
* In ExifBitmapHandler, getRotationForExif() now takes just the
Orientation tag, rather than a serialized string. Also renamed for
clarity.
* In GIFMetadataExtractor, return the width, height and bits per channel
instead of throwing them away. There was some conflation in
decodeBPP() which I picked apart. Refer to GIF89a section 18.
* In JpegMetadataExtractor, process the SOF0/SOF2 segment to extract
bits per channel, width, height and components (channel count). This
is essentially a port of PHP's getimagesize(), so should be bugwards
compatible.
* In PNGMetadataExtractor, return the width and height, which were
previously assigned to unused local variables. I verified the
implementation by referring to the specification.
* In SvgHandler, retain the version validation from unpackMetadata(),
but rename the function since it now takes an array as input.
In tests:
* In ExifBitmapTest, refactored some tests by using a provider.
* In GIFHandlerTest and PNGHandlerTest, I removed the tests in which
getMetadata() returns null, since it doesn't make sense when ported to
getMetadataArray(). I added tests for empty arrays instead.
* In tests, I retained serialization of input data since I figure it's
useful to confirm that existing database rows will continue to be read
correctly. I removed serialization of expected values, replacing them
with plain data.
* In tests, I replaced access to private class constants like
BROKEN_FILE with string literals, since stability is essential. If
the class constant changes, the test should fail.
Elsewhere:
* In maintenance/refreshImageMetadata.php, I removed the check for
shrinking image metadata, since it's not easy to implement and is
not future compatible. Image metadata is expected to shrink in
future.
Bug: T275268
Change-Id: I039785d5b6439d71dcc21dcb972177dba5c3a67d
2021-05-19 00:24:32 +00:00
|
|
|
'metadata' => [],
|
2020-06-16 01:45:46 +00:00
|
|
|
'sha1' => Wikimedia\base_convert( '2', 16, 36, 31 ),
|
|
|
|
|
'fileExists' => true
|
|
|
|
|
],
|
|
|
|
|
$this->db->timestamp( '20130225203040' )
|
|
|
|
|
);
|
2013-02-27 00:12:12 +00:00
|
|
|
|
2023-07-14 20:07:22 +00:00
|
|
|
$image = $localRepo->newFile( new TitleValue( NS_FILE, 'Foobar.svg' ) );
|
2020-06-16 01:45:46 +00:00
|
|
|
$image->recordUpload3(
|
|
|
|
|
'',
|
|
|
|
|
'Upload of some lame SVG',
|
|
|
|
|
'Some lame SVG',
|
2023-07-14 19:18:01 +00:00
|
|
|
$performer,
|
2020-06-16 01:45:46 +00:00
|
|
|
[
|
2013-05-24 12:56:06 +00:00
|
|
|
'size' => 12345,
|
|
|
|
|
'width' => 240,
|
|
|
|
|
'height' => 180,
|
2014-06-03 19:44:53 +00:00
|
|
|
'bits' => 0,
|
2013-05-24 12:56:06 +00:00
|
|
|
'media_type' => MEDIATYPE_DRAWING,
|
|
|
|
|
'mime' => 'image/svg+xml',
|
Use the unserialized form of image metadata internally
Image metadata is usually a serialized string representing an array.
Passing the string around internally and having everything unserialize
it is an awkward convention.
Also, many image handlers were reading the file twice: once for
getMetadata() and again for getImageSize(). Often getMetadata()
would actually read the width and height and then throw it away.
So, in filerepo:
* Add File::getMetadataItem(), which promises to allow partial
loading of metadata per my proposal on T275268 in a future commit.
* Add File::getMetadataArray(), which returns the unserialized array.
Some file handlers were returning non-serializable strings from
getMetadata(), so I gave them a legacy array form ['_error' => ...]
* Changed MWFileProps to return the array form of metadata.
* Deprecate the weird File::getImageSize(). It was apparently not
called by anything, but was overridden by UnregisteredLocalFile.
* Wrap serialize/unserialize with File::getMetadataForDb() and
File::loadMetadataFromDb() in preparation for T275268.
In MediaHandler:
* Merged MediaHandler::getImageSize() and MediaHandler::getMetadata()
into getSizeAndMetadata(). Deprecated the old methods.
* Instead of isMetadataValid() we now have isFileMetadataValid(), which
only gets a File object, so it can decide what data it needs to load.
* Simplified getPageDimensions() by having it return false for non-paged
media. It was not called in that case, but was implemented anyway.
In specific handlers:
* Rename DjVuHandler::getUnserializedMetadata() and
extractTreesFromMetadata() for clarity. "Metadata" in these function
names meant an XML string.
* Updated DjVuImage::getImageSize() to provide image sizes in the new
style.
* In ExifBitmapHandler, getRotationForExif() now takes just the
Orientation tag, rather than a serialized string. Also renamed for
clarity.
* In GIFMetadataExtractor, return the width, height and bits per channel
instead of throwing them away. There was some conflation in
decodeBPP() which I picked apart. Refer to GIF89a section 18.
* In JpegMetadataExtractor, process the SOF0/SOF2 segment to extract
bits per channel, width, height and components (channel count). This
is essentially a port of PHP's getimagesize(), so should be bugwards
compatible.
* In PNGMetadataExtractor, return the width and height, which were
previously assigned to unused local variables. I verified the
implementation by referring to the specification.
* In SvgHandler, retain the version validation from unpackMetadata(),
but rename the function since it now takes an array as input.
In tests:
* In ExifBitmapTest, refactored some tests by using a provider.
* In GIFHandlerTest and PNGHandlerTest, I removed the tests in which
getMetadata() returns null, since it doesn't make sense when ported to
getMetadataArray(). I added tests for empty arrays instead.
* In tests, I retained serialization of input data since I figure it's
useful to confirm that existing database rows will continue to be read
correctly. I removed serialization of expected values, replacing them
with plain data.
* In tests, I replaced access to private class constants like
BROKEN_FILE with string literals, since stability is essential. If
the class constant changes, the test should fail.
Elsewhere:
* In maintenance/refreshImageMetadata.php, I removed the check for
shrinking image metadata, since it's not easy to implement and is
not future compatible. Image metadata is expected to shrink in
future.
Bug: T275268
Change-Id: I039785d5b6439d71dcc21dcb972177dba5c3a67d
2021-05-19 00:24:32 +00:00
|
|
|
'metadata' => [
|
2018-10-06 00:56:53 +00:00
|
|
|
'version' => SvgHandler::SVG_METADATA_VERSION,
|
|
|
|
|
'width' => 240,
|
|
|
|
|
'height' => 180,
|
|
|
|
|
'originalWidth' => '100%',
|
|
|
|
|
'originalHeight' => '100%',
|
|
|
|
|
'translations' => [
|
|
|
|
|
'en' => SVGReader::LANG_FULL_MATCH,
|
|
|
|
|
'ru' => SVGReader::LANG_FULL_MATCH,
|
|
|
|
|
],
|
Use the unserialized form of image metadata internally
Image metadata is usually a serialized string representing an array.
Passing the string around internally and having everything unserialize
it is an awkward convention.
Also, many image handlers were reading the file twice: once for
getMetadata() and again for getImageSize(). Often getMetadata()
would actually read the width and height and then throw it away.
So, in filerepo:
* Add File::getMetadataItem(), which promises to allow partial
loading of metadata per my proposal on T275268 in a future commit.
* Add File::getMetadataArray(), which returns the unserialized array.
Some file handlers were returning non-serializable strings from
getMetadata(), so I gave them a legacy array form ['_error' => ...]
* Changed MWFileProps to return the array form of metadata.
* Deprecate the weird File::getImageSize(). It was apparently not
called by anything, but was overridden by UnregisteredLocalFile.
* Wrap serialize/unserialize with File::getMetadataForDb() and
File::loadMetadataFromDb() in preparation for T275268.
In MediaHandler:
* Merged MediaHandler::getImageSize() and MediaHandler::getMetadata()
into getSizeAndMetadata(). Deprecated the old methods.
* Instead of isMetadataValid() we now have isFileMetadataValid(), which
only gets a File object, so it can decide what data it needs to load.
* Simplified getPageDimensions() by having it return false for non-paged
media. It was not called in that case, but was implemented anyway.
In specific handlers:
* Rename DjVuHandler::getUnserializedMetadata() and
extractTreesFromMetadata() for clarity. "Metadata" in these function
names meant an XML string.
* Updated DjVuImage::getImageSize() to provide image sizes in the new
style.
* In ExifBitmapHandler, getRotationForExif() now takes just the
Orientation tag, rather than a serialized string. Also renamed for
clarity.
* In GIFMetadataExtractor, return the width, height and bits per channel
instead of throwing them away. There was some conflation in
decodeBPP() which I picked apart. Refer to GIF89a section 18.
* In JpegMetadataExtractor, process the SOF0/SOF2 segment to extract
bits per channel, width, height and components (channel count). This
is essentially a port of PHP's getimagesize(), so should be bugwards
compatible.
* In PNGMetadataExtractor, return the width and height, which were
previously assigned to unused local variables. I verified the
implementation by referring to the specification.
* In SvgHandler, retain the version validation from unpackMetadata(),
but rename the function since it now takes an array as input.
In tests:
* In ExifBitmapTest, refactored some tests by using a provider.
* In GIFHandlerTest and PNGHandlerTest, I removed the tests in which
getMetadata() returns null, since it doesn't make sense when ported to
getMetadataArray(). I added tests for empty arrays instead.
* In tests, I retained serialization of input data since I figure it's
useful to confirm that existing database rows will continue to be read
correctly. I removed serialization of expected values, replacing them
with plain data.
* In tests, I replaced access to private class constants like
BROKEN_FILE with string literals, since stability is essential. If
the class constant changes, the test should fail.
Elsewhere:
* In maintenance/refreshImageMetadata.php, I removed the check for
shrinking image metadata, since it's not easy to implement and is
not future compatible. Image metadata is expected to shrink in
future.
Bug: T275268
Change-Id: I039785d5b6439d71dcc21dcb972177dba5c3a67d
2021-05-19 00:24:32 +00:00
|
|
|
],
|
2015-11-24 22:51:42 +00:00
|
|
|
'sha1' => Wikimedia\base_convert( '', 16, 36, 31 ),
|
2013-05-24 12:56:06 +00:00
|
|
|
'fileExists' => true
|
2020-06-16 01:45:46 +00:00
|
|
|
],
|
|
|
|
|
$this->db->timestamp( '20010115123500' )
|
|
|
|
|
);
|
2013-05-24 12:56:06 +00:00
|
|
|
|
2021-03-29 04:22:24 +00:00
|
|
|
# This image will be prohibited via the list in [[MediaWiki:Bad image list]]
|
2023-07-14 20:07:22 +00:00
|
|
|
$image = $localRepo->newFile( new TitleValue( NS_FILE, 'Bad.jpg' ) );
|
2020-06-16 01:45:46 +00:00
|
|
|
$image->recordUpload3(
|
|
|
|
|
'',
|
|
|
|
|
'zomgnotcensored',
|
|
|
|
|
'Borderline image',
|
2023-07-14 19:18:01 +00:00
|
|
|
$performer,
|
2020-06-16 01:45:46 +00:00
|
|
|
[
|
|
|
|
|
'size' => 12345,
|
|
|
|
|
'width' => 320,
|
|
|
|
|
'height' => 240,
|
|
|
|
|
'bits' => 24,
|
|
|
|
|
'media_type' => MEDIATYPE_BITMAP,
|
|
|
|
|
'mime' => 'image/jpeg',
|
Use the unserialized form of image metadata internally
Image metadata is usually a serialized string representing an array.
Passing the string around internally and having everything unserialize
it is an awkward convention.
Also, many image handlers were reading the file twice: once for
getMetadata() and again for getImageSize(). Often getMetadata()
would actually read the width and height and then throw it away.
So, in filerepo:
* Add File::getMetadataItem(), which promises to allow partial
loading of metadata per my proposal on T275268 in a future commit.
* Add File::getMetadataArray(), which returns the unserialized array.
Some file handlers were returning non-serializable strings from
getMetadata(), so I gave them a legacy array form ['_error' => ...]
* Changed MWFileProps to return the array form of metadata.
* Deprecate the weird File::getImageSize(). It was apparently not
called by anything, but was overridden by UnregisteredLocalFile.
* Wrap serialize/unserialize with File::getMetadataForDb() and
File::loadMetadataFromDb() in preparation for T275268.
In MediaHandler:
* Merged MediaHandler::getImageSize() and MediaHandler::getMetadata()
into getSizeAndMetadata(). Deprecated the old methods.
* Instead of isMetadataValid() we now have isFileMetadataValid(), which
only gets a File object, so it can decide what data it needs to load.
* Simplified getPageDimensions() by having it return false for non-paged
media. It was not called in that case, but was implemented anyway.
In specific handlers:
* Rename DjVuHandler::getUnserializedMetadata() and
extractTreesFromMetadata() for clarity. "Metadata" in these function
names meant an XML string.
* Updated DjVuImage::getImageSize() to provide image sizes in the new
style.
* In ExifBitmapHandler, getRotationForExif() now takes just the
Orientation tag, rather than a serialized string. Also renamed for
clarity.
* In GIFMetadataExtractor, return the width, height and bits per channel
instead of throwing them away. There was some conflation in
decodeBPP() which I picked apart. Refer to GIF89a section 18.
* In JpegMetadataExtractor, process the SOF0/SOF2 segment to extract
bits per channel, width, height and components (channel count). This
is essentially a port of PHP's getimagesize(), so should be bugwards
compatible.
* In PNGMetadataExtractor, return the width and height, which were
previously assigned to unused local variables. I verified the
implementation by referring to the specification.
* In SvgHandler, retain the version validation from unpackMetadata(),
but rename the function since it now takes an array as input.
In tests:
* In ExifBitmapTest, refactored some tests by using a provider.
* In GIFHandlerTest and PNGHandlerTest, I removed the tests in which
getMetadata() returns null, since it doesn't make sense when ported to
getMetadataArray(). I added tests for empty arrays instead.
* In tests, I retained serialization of input data since I figure it's
useful to confirm that existing database rows will continue to be read
correctly. I removed serialization of expected values, replacing them
with plain data.
* In tests, I replaced access to private class constants like
BROKEN_FILE with string literals, since stability is essential. If
the class constant changes, the test should fail.
Elsewhere:
* In maintenance/refreshImageMetadata.php, I removed the check for
shrinking image metadata, since it's not easy to implement and is
not future compatible. Image metadata is expected to shrink in
future.
Bug: T275268
Change-Id: I039785d5b6439d71dcc21dcb972177dba5c3a67d
2021-05-19 00:24:32 +00:00
|
|
|
'metadata' => [],
|
2020-06-16 01:45:46 +00:00
|
|
|
'sha1' => Wikimedia\base_convert( '3', 16, 36, 31 ),
|
|
|
|
|
'fileExists' => true
|
|
|
|
|
],
|
|
|
|
|
$this->db->timestamp( '20010115123500' )
|
|
|
|
|
);
|
2013-12-18 17:56:15 +00:00
|
|
|
|
2024-04-26 02:10:50 +00:00
|
|
|
$image = $localRepo->newFile( new TitleValue( NS_FILE, 'Hi-ho.jpg' ) );
|
|
|
|
|
$image->recordUpload3(
|
|
|
|
|
'',
|
|
|
|
|
'Hi',
|
|
|
|
|
'ho',
|
|
|
|
|
$performer,
|
|
|
|
|
[
|
|
|
|
|
'size' => 7881,
|
|
|
|
|
'width' => 1941,
|
|
|
|
|
'height' => 220,
|
|
|
|
|
'bits' => 8,
|
|
|
|
|
'media_type' => MEDIATYPE_BITMAP,
|
|
|
|
|
'mime' => 'image/jpeg',
|
|
|
|
|
'metadata' => [],
|
|
|
|
|
'sha1' => Wikimedia\base_convert( '1', 16, 36, 31 ),
|
|
|
|
|
'fileExists' => true
|
|
|
|
|
],
|
|
|
|
|
$this->db->timestamp( '20010115123500' )
|
|
|
|
|
);
|
|
|
|
|
|
2023-07-14 20:07:22 +00:00
|
|
|
$image = $localRepo->newFile( new TitleValue( NS_FILE, 'Video.ogv' ) );
|
2020-06-16 01:45:46 +00:00
|
|
|
$image->recordUpload3(
|
|
|
|
|
'',
|
|
|
|
|
'A pretty movie',
|
|
|
|
|
'Will it play',
|
2023-07-14 19:18:01 +00:00
|
|
|
$performer,
|
2020-06-16 01:45:46 +00:00
|
|
|
[
|
|
|
|
|
'size' => 12345,
|
|
|
|
|
'width' => 320,
|
|
|
|
|
'height' => 240,
|
|
|
|
|
'bits' => 0,
|
|
|
|
|
'media_type' => MEDIATYPE_VIDEO,
|
|
|
|
|
'mime' => 'application/ogg',
|
Use the unserialized form of image metadata internally
Image metadata is usually a serialized string representing an array.
Passing the string around internally and having everything unserialize
it is an awkward convention.
Also, many image handlers were reading the file twice: once for
getMetadata() and again for getImageSize(). Often getMetadata()
would actually read the width and height and then throw it away.
So, in filerepo:
* Add File::getMetadataItem(), which promises to allow partial
loading of metadata per my proposal on T275268 in a future commit.
* Add File::getMetadataArray(), which returns the unserialized array.
Some file handlers were returning non-serializable strings from
getMetadata(), so I gave them a legacy array form ['_error' => ...]
* Changed MWFileProps to return the array form of metadata.
* Deprecate the weird File::getImageSize(). It was apparently not
called by anything, but was overridden by UnregisteredLocalFile.
* Wrap serialize/unserialize with File::getMetadataForDb() and
File::loadMetadataFromDb() in preparation for T275268.
In MediaHandler:
* Merged MediaHandler::getImageSize() and MediaHandler::getMetadata()
into getSizeAndMetadata(). Deprecated the old methods.
* Instead of isMetadataValid() we now have isFileMetadataValid(), which
only gets a File object, so it can decide what data it needs to load.
* Simplified getPageDimensions() by having it return false for non-paged
media. It was not called in that case, but was implemented anyway.
In specific handlers:
* Rename DjVuHandler::getUnserializedMetadata() and
extractTreesFromMetadata() for clarity. "Metadata" in these function
names meant an XML string.
* Updated DjVuImage::getImageSize() to provide image sizes in the new
style.
* In ExifBitmapHandler, getRotationForExif() now takes just the
Orientation tag, rather than a serialized string. Also renamed for
clarity.
* In GIFMetadataExtractor, return the width, height and bits per channel
instead of throwing them away. There was some conflation in
decodeBPP() which I picked apart. Refer to GIF89a section 18.
* In JpegMetadataExtractor, process the SOF0/SOF2 segment to extract
bits per channel, width, height and components (channel count). This
is essentially a port of PHP's getimagesize(), so should be bugwards
compatible.
* In PNGMetadataExtractor, return the width and height, which were
previously assigned to unused local variables. I verified the
implementation by referring to the specification.
* In SvgHandler, retain the version validation from unpackMetadata(),
but rename the function since it now takes an array as input.
In tests:
* In ExifBitmapTest, refactored some tests by using a provider.
* In GIFHandlerTest and PNGHandlerTest, I removed the tests in which
getMetadata() returns null, since it doesn't make sense when ported to
getMetadataArray(). I added tests for empty arrays instead.
* In tests, I retained serialization of input data since I figure it's
useful to confirm that existing database rows will continue to be read
correctly. I removed serialization of expected values, replacing them
with plain data.
* In tests, I replaced access to private class constants like
BROKEN_FILE with string literals, since stability is essential. If
the class constant changes, the test should fail.
Elsewhere:
* In maintenance/refreshImageMetadata.php, I removed the check for
shrinking image metadata, since it's not easy to implement and is
not future compatible. Image metadata is expected to shrink in
future.
Bug: T275268
Change-Id: I039785d5b6439d71dcc21dcb972177dba5c3a67d
2021-05-19 00:24:32 +00:00
|
|
|
'metadata' => [],
|
2020-06-16 01:45:46 +00:00
|
|
|
'sha1' => Wikimedia\base_convert( '', 16, 36, 31 ),
|
|
|
|
|
'fileExists' => true
|
|
|
|
|
],
|
|
|
|
|
$this->db->timestamp( '20010115123500' )
|
|
|
|
|
);
|
2016-01-07 08:41:23 +00:00
|
|
|
|
2023-07-14 20:07:22 +00:00
|
|
|
$image = $localRepo->newFile( new TitleValue( NS_FILE, 'Audio.oga' ) );
|
2020-06-16 01:45:46 +00:00
|
|
|
$image->recordUpload3(
|
|
|
|
|
'',
|
|
|
|
|
'An awesome hitsong',
|
|
|
|
|
'Will it play',
|
2023-07-14 19:18:01 +00:00
|
|
|
$performer,
|
2020-06-16 01:45:46 +00:00
|
|
|
[
|
|
|
|
|
'size' => 12345,
|
|
|
|
|
'width' => 0,
|
|
|
|
|
'height' => 0,
|
|
|
|
|
'bits' => 0,
|
|
|
|
|
'media_type' => MEDIATYPE_AUDIO,
|
|
|
|
|
'mime' => 'application/ogg',
|
Use the unserialized form of image metadata internally
Image metadata is usually a serialized string representing an array.
Passing the string around internally and having everything unserialize
it is an awkward convention.
Also, many image handlers were reading the file twice: once for
getMetadata() and again for getImageSize(). Often getMetadata()
would actually read the width and height and then throw it away.
So, in filerepo:
* Add File::getMetadataItem(), which promises to allow partial
loading of metadata per my proposal on T275268 in a future commit.
* Add File::getMetadataArray(), which returns the unserialized array.
Some file handlers were returning non-serializable strings from
getMetadata(), so I gave them a legacy array form ['_error' => ...]
* Changed MWFileProps to return the array form of metadata.
* Deprecate the weird File::getImageSize(). It was apparently not
called by anything, but was overridden by UnregisteredLocalFile.
* Wrap serialize/unserialize with File::getMetadataForDb() and
File::loadMetadataFromDb() in preparation for T275268.
In MediaHandler:
* Merged MediaHandler::getImageSize() and MediaHandler::getMetadata()
into getSizeAndMetadata(). Deprecated the old methods.
* Instead of isMetadataValid() we now have isFileMetadataValid(), which
only gets a File object, so it can decide what data it needs to load.
* Simplified getPageDimensions() by having it return false for non-paged
media. It was not called in that case, but was implemented anyway.
In specific handlers:
* Rename DjVuHandler::getUnserializedMetadata() and
extractTreesFromMetadata() for clarity. "Metadata" in these function
names meant an XML string.
* Updated DjVuImage::getImageSize() to provide image sizes in the new
style.
* In ExifBitmapHandler, getRotationForExif() now takes just the
Orientation tag, rather than a serialized string. Also renamed for
clarity.
* In GIFMetadataExtractor, return the width, height and bits per channel
instead of throwing them away. There was some conflation in
decodeBPP() which I picked apart. Refer to GIF89a section 18.
* In JpegMetadataExtractor, process the SOF0/SOF2 segment to extract
bits per channel, width, height and components (channel count). This
is essentially a port of PHP's getimagesize(), so should be bugwards
compatible.
* In PNGMetadataExtractor, return the width and height, which were
previously assigned to unused local variables. I verified the
implementation by referring to the specification.
* In SvgHandler, retain the version validation from unpackMetadata(),
but rename the function since it now takes an array as input.
In tests:
* In ExifBitmapTest, refactored some tests by using a provider.
* In GIFHandlerTest and PNGHandlerTest, I removed the tests in which
getMetadata() returns null, since it doesn't make sense when ported to
getMetadataArray(). I added tests for empty arrays instead.
* In tests, I retained serialization of input data since I figure it's
useful to confirm that existing database rows will continue to be read
correctly. I removed serialization of expected values, replacing them
with plain data.
* In tests, I replaced access to private class constants like
BROKEN_FILE with string literals, since stability is essential. If
the class constant changes, the test should fail.
Elsewhere:
* In maintenance/refreshImageMetadata.php, I removed the check for
shrinking image metadata, since it's not easy to implement and is
not future compatible. Image metadata is expected to shrink in
future.
Bug: T275268
Change-Id: I039785d5b6439d71dcc21dcb972177dba5c3a67d
2021-05-19 00:24:32 +00:00
|
|
|
'metadata' => [],
|
2020-06-16 01:45:46 +00:00
|
|
|
'sha1' => Wikimedia\base_convert( '', 16, 36, 31 ),
|
|
|
|
|
'fileExists' => true
|
|
|
|
|
],
|
|
|
|
|
$this->db->timestamp( '20010115123500' )
|
|
|
|
|
);
|
2016-05-18 15:48:04 +00:00
|
|
|
|
2013-12-18 17:56:15 +00:00
|
|
|
# A DjVu file
|
2023-07-14 20:07:22 +00:00
|
|
|
$image = $localRepo->newFile( new TitleValue( NS_FILE, 'LoremIpsum.djvu' ) );
|
2021-11-21 08:50:59 +00:00
|
|
|
$djvuMetadata = [
|
|
|
|
|
'data' => [
|
|
|
|
|
'pages' => [
|
|
|
|
|
[ 'height' => 3508, 'width' => 2480, 'dpi' => 300, 'gamma' => 2.2 ],
|
|
|
|
|
[ 'height' => 3508, 'width' => 2480, 'dpi' => 300, 'gamma' => 2.2 ],
|
|
|
|
|
[ 'height' => 3508, 'width' => 2480, 'dpi' => 300, 'gamma' => 2.2 ],
|
|
|
|
|
[ 'height' => 3508, 'width' => 2480, 'dpi' => 300, 'gamma' => 2.2 ],
|
|
|
|
|
[ 'height' => 3508, 'width' => 2480, 'dpi' => 300, 'gamma' => 2.2 ],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
2020-06-16 01:45:46 +00:00
|
|
|
$image->recordUpload3(
|
|
|
|
|
'',
|
|
|
|
|
'Upload a DjVu',
|
|
|
|
|
'A DjVu',
|
2023-07-14 19:18:01 +00:00
|
|
|
$performer,
|
2020-06-16 01:45:46 +00:00
|
|
|
[
|
|
|
|
|
'size' => 3249,
|
|
|
|
|
'width' => 2480,
|
|
|
|
|
'height' => 3508,
|
|
|
|
|
'bits' => 0,
|
2020-12-21 16:52:41 +00:00
|
|
|
'media_type' => MEDIATYPE_OFFICE,
|
2020-06-16 01:45:46 +00:00
|
|
|
'mime' => 'image/vnd.djvu',
|
2021-11-21 08:50:59 +00:00
|
|
|
'metadata' => $djvuMetadata,
|
2020-06-16 01:45:46 +00:00
|
|
|
'sha1' => Wikimedia\base_convert( '', 16, 36, 31 ),
|
|
|
|
|
'fileExists' => true
|
|
|
|
|
],
|
|
|
|
|
$this->db->timestamp( '20010115123600' )
|
|
|
|
|
);
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
|
|
|
|
|
return $this->createTeardownObject( $teardown, $nextTeardown );
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* Upload test files to the backend created by createRepoGroup().
|
2012-01-09 22:33:00 +00:00
|
|
|
*
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* @return callable The teardown callback
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
private function setupUploadBackend() {
|
2012-01-09 22:33:00 +00:00
|
|
|
global $IP;
|
|
|
|
|
|
2020-03-08 21:47:14 +00:00
|
|
|
$repo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$base = $repo->getZonePath( 'public' );
|
|
|
|
|
$backend = $repo->getBackend();
|
|
|
|
|
$backend->prepare( [ 'dir' => "$base/3/3a" ] );
|
2020-11-13 05:19:43 +00:00
|
|
|
$backend->quickStore( [
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
'src' => "$IP/tests/phpunit/data/parser/headbg.jpg",
|
|
|
|
|
'dst' => "$base/3/3a/Foobar.jpg"
|
|
|
|
|
] );
|
|
|
|
|
$backend->prepare( [ 'dir' => "$base/e/ea" ] );
|
2020-11-13 05:19:43 +00:00
|
|
|
$backend->quickStore( [
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
'src' => "$IP/tests/phpunit/data/parser/wiki.png",
|
|
|
|
|
'dst' => "$base/e/ea/Thumb.png"
|
|
|
|
|
] );
|
|
|
|
|
$backend->prepare( [ 'dir' => "$base/0/09" ] );
|
2020-11-13 05:19:43 +00:00
|
|
|
$backend->quickStore( [
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
'src' => "$IP/tests/phpunit/data/parser/headbg.jpg",
|
|
|
|
|
'dst' => "$base/0/09/Bad.jpg"
|
|
|
|
|
] );
|
|
|
|
|
$backend->prepare( [ 'dir' => "$base/5/5f" ] );
|
2020-11-13 05:19:43 +00:00
|
|
|
$backend->quickStore( [
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
'src' => "$IP/tests/phpunit/data/parser/LoremIpsum.djvu",
|
|
|
|
|
'dst' => "$base/5/5f/LoremIpsum.djvu"
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
// No helpful SVG file to copy, so make one ourselves
|
|
|
|
|
$data = '<?xml version="1.0" encoding="utf-8"?>' .
|
2014-03-18 17:00:11 +00:00
|
|
|
'<svg xmlns="http://www.w3.org/2000/svg"' .
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
' version="1.1" width="240" height="180"/>';
|
2012-01-09 22:33:00 +00:00
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$backend->prepare( [ 'dir' => "$base/f/ff" ] );
|
|
|
|
|
$backend->quickCreate( [
|
|
|
|
|
'content' => $data, 'dst' => "$base/f/ff/Foobar.svg"
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
return function () use ( $backend ) {
|
|
|
|
|
if ( $backend instanceof MockFileBackend ) {
|
|
|
|
|
// In memory backend, so dont bother cleaning them up.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$this->teardownUploadBackend();
|
|
|
|
|
};
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the dummy uploads directory
|
|
|
|
|
*/
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
private function teardownUploadBackend() {
|
2012-01-09 22:33:00 +00:00
|
|
|
if ( $this->keepUploads ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-08 21:47:14 +00:00
|
|
|
$public = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
|
|
|
|
|
->getZonePath( 'public' );
|
2012-01-09 22:33:00 +00:00
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$this->deleteFiles(
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
"$public/3/3a/Foobar.jpg",
|
|
|
|
|
"$public/e/ea/Thumb.png",
|
|
|
|
|
"$public/0/09/Bad.jpg",
|
|
|
|
|
"$public/5/5f/LoremIpsum.djvu",
|
|
|
|
|
"$public/f/ff/Foobar.svg",
|
|
|
|
|
"$public/0/00/Video.ogv",
|
|
|
|
|
"$public/4/41/Audio.oga",
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2012-01-09 22:33:00 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* Delete the specified files and their parent directories
|
2024-01-20 19:24:35 +00:00
|
|
|
* @param string[] $files File backend URIs mwstore://...
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
private function deleteFiles( $files ) {
|
|
|
|
|
// Delete the files
|
2020-03-08 21:47:14 +00:00
|
|
|
$backend = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()->getBackend();
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
foreach ( $files as $file ) {
|
2020-11-13 05:19:43 +00:00
|
|
|
$backend->quickDelete( [ 'src' => $file ], [ 'force' => 1 ] );
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
// Delete the parent directories
|
|
|
|
|
foreach ( $files as $file ) {
|
|
|
|
|
$tmp = FileBackend::parentStoragePath( $file );
|
|
|
|
|
while ( $tmp ) {
|
|
|
|
|
if ( !$backend->clean( [ 'dir' => $tmp ] )->isOK() ) {
|
|
|
|
|
break;
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$tmp = FileBackend::parentStoragePath( $tmp );
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-18 17:56:15 +00:00
|
|
|
/**
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* Add articles to the test DB.
|
2013-12-18 17:56:15 +00:00
|
|
|
*
|
2020-12-21 22:30:52 +00:00
|
|
|
* @see staticSetup() for more information about setup/teardown
|
|
|
|
|
*
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTestArticle[] $articles Article info array from TestFileReader
|
2020-12-21 22:30:52 +00:00
|
|
|
* @param ?ScopedCallback $nextTeardown The next teardown object
|
|
|
|
|
* @return ScopedCallback The teardown object
|
2013-12-18 17:56:15 +00:00
|
|
|
*/
|
2020-12-21 22:30:52 +00:00
|
|
|
public function addArticles(
|
|
|
|
|
array $articles, ?ScopedCallback $nextTeardown = null
|
|
|
|
|
): ScopedCallback {
|
2020-12-23 18:52:12 +00:00
|
|
|
$this->checkSetupDone( 'setupDatabase' );
|
2020-12-21 22:30:52 +00:00
|
|
|
$this->checkSetupDone( 'staticSetup' );
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
foreach ( $articles as $info ) {
|
2022-05-20 20:42:25 +00:00
|
|
|
$this->addArticle( $info->title, $info->text, $info->filename, $info->lineNumStart );
|
2016-03-09 04:42:33 +00:00
|
|
|
}
|
2012-01-09 22:33:00 +00:00
|
|
|
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
$teardown = [];
|
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
// Wipe WANObjectCache process cache, which is invalidated by article insertion
|
|
|
|
|
// due to T144706
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
$services->getMainWANObjectCache()->clearProcessCache();
|
2023-08-06 11:10:37 +00:00
|
|
|
// Avoid reuse of lazy-loaded Title::mArticleId after page creation
|
|
|
|
|
Title::clearCaches();
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2024-02-12 15:44:14 +00:00
|
|
|
$reset = static function () use ( $services ) {
|
|
|
|
|
// Reset the service so that any "MediaWiki:bad image list" articles
|
|
|
|
|
// added get fetched
|
Cleanup ParserTestRunner - take 2
This reapplied commit b4e797510c8c02dd7f2307610ccb15f14cdb1f5a with
some fixes for the parsoid tests, which can be checked by diff the
patchset 1 and the latest patchset.
- Factored out resetting of services that only related to language
and variant into a function, sorted all services roughly by their
dependency relationship.
Also, only reset when the language or variant is configured by the
test case.
- Replaced manual redefine of ContentLanguage service with reset
method like others.
- Reset necessary services after setting the default language code in
staticSetup(), so the override in addArticles() can be removed.
- Use the 'skin' param of getText() for setting skin, so we don't need
to touch the context.
- Removed the override of wgUser, wgLang, and wgOut. They didn't live
in parser-related codes anymore.
- Setting user option is not the correct way here, the problem is
UserOption(Lookup|Manager) didn't get reset, so the default user
language is wrong; and the context have a cached Language object.
When the default language option updated, purge the cache with
setUser() should be sufficient.
Change-Id: I4ebeaef98ed9b7682701c0385c68145ee1e78951
2023-06-14 06:23:02 +00:00
|
|
|
$services->resetServiceForTesting( 'BadFileLookup' );
|
|
|
|
|
// Depends on BadFileLookup, also reset here in case it no longer
|
|
|
|
|
// depends on the legacy ParserFactory which reset per test.
|
|
|
|
|
$services->resetServiceForTesting( 'ParsoidDataAccess' );
|
2022-04-12 18:21:23 +00:00
|
|
|
};
|
2024-02-12 15:44:14 +00:00
|
|
|
$reset();
|
2022-04-12 18:21:23 +00:00
|
|
|
|
2024-02-12 15:44:14 +00:00
|
|
|
$teardown[] = $reset;
|
|
|
|
|
$teardown[] = function () use ( $articles ) {
|
2020-12-21 22:30:52 +00:00
|
|
|
$this->cleanupArticles( $articles );
|
2024-02-12 15:44:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return $this->createTeardownObject( $teardown, $nextTeardown );
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
2020-08-18 03:41:34 +00:00
|
|
|
/**
|
|
|
|
|
* Remove articles from the test DB. This prevents independent parser
|
|
|
|
|
* test files from having conflicts when they choose the same names
|
|
|
|
|
* for article or template test fixtures.
|
|
|
|
|
*
|
2022-05-20 20:42:25 +00:00
|
|
|
* @param ParserTestArticle[] $articles Article info array from TestFileReader
|
2020-08-18 03:41:34 +00:00
|
|
|
*/
|
|
|
|
|
public function cleanupArticles( $articles ) {
|
2020-12-23 18:52:12 +00:00
|
|
|
$this->checkSetupDone( 'setupDatabase' );
|
2020-12-21 22:30:52 +00:00
|
|
|
$this->checkSetupDone( 'staticSetup' );
|
2023-07-14 19:18:01 +00:00
|
|
|
$deleter = new UltimateAuthority( new UserIdentityValue( 0, User::MAINTENANCE_SCRIPT_USER ) );
|
2021-10-30 15:45:49 +00:00
|
|
|
$wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
|
2023-07-14 20:07:22 +00:00
|
|
|
$titleParser = MediaWikiServices::getInstance()->getTitleParser();
|
2021-10-30 15:45:49 +00:00
|
|
|
$delPageFactory = MediaWikiServices::getInstance()->getDeletePageFactory();
|
2020-08-18 03:41:34 +00:00
|
|
|
foreach ( $articles as $info ) {
|
2022-05-20 20:42:25 +00:00
|
|
|
$name = self::chomp( $info->title );
|
2023-07-14 20:07:22 +00:00
|
|
|
$title = $titleParser->parseTitle( $name );
|
|
|
|
|
$page = $wikiPageFactory->newFromLinkTarget( $title );
|
2023-07-14 19:18:01 +00:00
|
|
|
$delPageFactory->newDeletePage( $page, $deleter )->deleteUnsafe( 'cleaning up' );
|
2020-08-18 03:41:34 +00:00
|
|
|
}
|
2023-08-06 11:10:37 +00:00
|
|
|
|
|
|
|
|
// Clear the static cache that Title class maintains.
|
|
|
|
|
// This ensures that Parsoid test runs that follow legacy parser test runs
|
|
|
|
|
// don't reuse titles. This matters because it looks like legacy test run
|
|
|
|
|
// and Parsoid test run differ in the number of articles they create in the db.
|
|
|
|
|
// We need to investigate that separately, but given that they differ, titles
|
|
|
|
|
// will get different article and revision ids across test runs.
|
|
|
|
|
// While we could add this to resetTitleServices(), there is really
|
|
|
|
|
// no reason to clear this for every test. Sufficient to clear this
|
|
|
|
|
// once per test file.
|
|
|
|
|
// Also the LinkCache is cleared which holds some information about titles
|
|
|
|
|
Title::clearCaches();
|
2020-08-18 03:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-09 22:33:00 +00:00
|
|
|
/**
|
|
|
|
|
* Insert a temporary test article
|
2020-12-23 18:52:12 +00:00
|
|
|
*
|
2023-08-07 13:29:39 +00:00
|
|
|
* @todo Refactor to share more code w/ ::editPage
|
2020-12-23 18:52:12 +00:00
|
|
|
*
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string $name The title, including any prefix
|
|
|
|
|
* @param string $text The article text
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* @param string $file The input file name
|
2014-12-24 13:49:20 +00:00
|
|
|
* @param int|string $line The input line number, for reporting errors
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
private function addArticle( $name, $text, $file, $line ) {
|
2012-01-09 22:33:00 +00:00
|
|
|
$text = self::chomp( $text );
|
|
|
|
|
$name = self::chomp( $name );
|
|
|
|
|
|
2023-07-14 20:07:22 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
|
|
|
|
|
$title = $services->getTitleParser()->parseTitle( $name );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
wfDebug( __METHOD__ . ": adding $name" );
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $title === null ) {
|
2023-06-03 15:25:27 +00:00
|
|
|
throw new RuntimeException( "invalid title '$name' at $file:$line\n" );
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-14 19:18:01 +00:00
|
|
|
$performer = new UltimateAuthority( new UserIdentityValue( 0, User::MAINTENANCE_SCRIPT_USER ) );
|
2020-12-23 18:52:12 +00:00
|
|
|
|
2023-07-14 20:07:22 +00:00
|
|
|
$page = $services->getWikiPageFactory()->newFromLinkTarget( $title );
|
2024-01-25 14:58:57 +00:00
|
|
|
$page->loadPageData( IDBAccessObject::READ_LATEST );
|
2023-07-14 20:07:22 +00:00
|
|
|
$newContent = $page->getContentHandler()->unserializeContent( $text );
|
2012-01-09 22:33:00 +00:00
|
|
|
|
|
|
|
|
if ( $page->exists() ) {
|
2020-07-03 00:20:38 +00:00
|
|
|
$content = $page->getContent( RevisionRecord::RAW );
|
2017-09-16 12:34:15 +00:00
|
|
|
// Only reject the title, if the content/content model is different.
|
|
|
|
|
// This makes it easier to create Template:(( or Template:)) in different extensions
|
|
|
|
|
if ( $newContent->equals( $content ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-06-03 15:25:27 +00:00
|
|
|
throw new RuntimeException(
|
2017-09-16 12:34:15 +00:00
|
|
|
"duplicate article '$name' with different content at $file:$line\n"
|
|
|
|
|
);
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-20 02:03:48 +00:00
|
|
|
// Optionally use mock parser, to make debugging of actual parser tests simpler.
|
2016-10-06 05:41:15 +00:00
|
|
|
// But initialise the MessageCache clone first, don't let MessageCache
|
|
|
|
|
// get a reference to the mock object.
|
2018-07-20 02:03:48 +00:00
|
|
|
if ( $this->disableSaveParse ) {
|
2022-01-27 20:19:18 +00:00
|
|
|
$services->getMessageCache()->getParser();
|
2019-12-30 06:58:16 +00:00
|
|
|
$services->disableService( 'Parser' );
|
|
|
|
|
$services->disableService( 'ParserFactory' );
|
|
|
|
|
$services->redefineService(
|
|
|
|
|
'Parser',
|
|
|
|
|
static function () {
|
|
|
|
|
return new ParserTestMockParser;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
$restore = static function () {
|
|
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'Parser' );
|
|
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'ParserFactory' );
|
|
|
|
|
};
|
2018-07-20 02:03:48 +00:00
|
|
|
} else {
|
|
|
|
|
$restore = false;
|
|
|
|
|
}
|
2022-05-20 20:42:25 +00:00
|
|
|
$status = null;
|
2017-09-11 10:58:13 +00:00
|
|
|
try {
|
2021-06-24 08:42:19 +00:00
|
|
|
$status = $page->doUserEditContent(
|
2017-09-16 12:34:15 +00:00
|
|
|
$newContent,
|
2023-07-14 19:18:01 +00:00
|
|
|
$performer,
|
2017-09-11 10:58:13 +00:00
|
|
|
'',
|
2021-06-24 08:42:19 +00:00
|
|
|
EDIT_NEW | EDIT_SUPPRESS_RC | EDIT_INTERNAL
|
2017-09-11 10:58:13 +00:00
|
|
|
);
|
|
|
|
|
} finally {
|
2018-07-20 02:03:48 +00:00
|
|
|
if ( $restore ) {
|
|
|
|
|
$restore();
|
|
|
|
|
}
|
2017-09-11 10:58:13 +00:00
|
|
|
}
|
2016-10-06 05:41:15 +00:00
|
|
|
|
2016-09-14 00:22:44 +00:00
|
|
|
if ( !$status->isOK() ) {
|
2024-03-01 16:48:16 +00:00
|
|
|
throw new RuntimeException( $status->__toString() );
|
2016-09-14 00:22:44 +00:00
|
|
|
}
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2020-12-23 18:52:12 +00:00
|
|
|
// an edit always attempt to purge backlink links such as history
|
|
|
|
|
// pages. That is unnecessary.
|
2022-01-27 20:19:18 +00:00
|
|
|
$jobQueueGroup = $services->getJobQueueGroup();
|
|
|
|
|
$jobQueueGroup->get( 'htmlCacheUpdate' )->delete();
|
2020-12-23 18:52:12 +00:00
|
|
|
// WikiPages::doEditUpdates randomly adds RC purges
|
2022-01-27 20:19:18 +00:00
|
|
|
$jobQueueGroup->get( 'recentChangesUpdate' )->delete();
|
2020-12-23 18:52:12 +00:00
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
// The RepoGroup cache is invalidated by the creation of file redirects
|
2016-09-28 03:29:54 +00:00
|
|
|
if ( $title->inNamespace( NS_FILE ) ) {
|
2022-01-27 20:19:18 +00:00
|
|
|
$services->getRepoGroup()->clearCache( $title );
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
}
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* Check if a hook is installed
|
2012-01-09 22:33:00 +00:00
|
|
|
*
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string $name
|
|
|
|
|
* @return bool True if tag hook is present
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
|
|
|
|
public function requireHook( $name ) {
|
2019-04-11 13:36:15 +00:00
|
|
|
$parser = MediaWikiServices::getInstance()->getParser();
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2020-12-21 16:52:41 +00:00
|
|
|
if ( preg_match( '/^[Ee]xtension:(.*)$/', $name, $matches ) ) {
|
2020-07-15 18:29:55 +00:00
|
|
|
$extName = $matches[1];
|
|
|
|
|
if ( ExtensionRegistry::getInstance()->isLoaded( $extName ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
$this->recorder->warning( " Skipping this test suite because it requires the '$extName' " .
|
|
|
|
|
"extension, which isn't loaded." );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-18 22:07:33 +00:00
|
|
|
if ( in_array( $name, $parser->getTags(), true ) ) {
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
return true;
|
2012-01-09 22:33:00 +00:00
|
|
|
} else {
|
2020-12-16 23:50:51 +00:00
|
|
|
$this->recorder->warning( " Skipping this test suite because it requires the '$name' hook, " .
|
2020-07-15 18:29:55 +00:00
|
|
|
"which isn't provided by any loaded extension." );
|
2012-01-09 22:33:00 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* Check if a function hook is installed
|
2012-01-09 22:33:00 +00:00
|
|
|
*
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string $name
|
|
|
|
|
* @return bool True if function hook is present
|
2012-01-09 22:33:00 +00:00
|
|
|
*/
|
|
|
|
|
public function requireFunctionHook( $name ) {
|
2019-04-11 13:36:15 +00:00
|
|
|
$parser = MediaWikiServices::getInstance()->getParser();
|
2012-01-09 22:33:00 +00:00
|
|
|
|
2021-02-18 22:36:51 +00:00
|
|
|
if ( in_array( $name, $parser->getFunctionHooks(), true ) ) {
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
return true;
|
2012-01-09 22:33:00 +00:00
|
|
|
} else {
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
$this->recorder->warning( " This test suite requires the '$name' function " .
|
|
|
|
|
"hook extension, skipping." );
|
2012-01-09 22:33:00 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
/**
|
2017-07-07 01:02:47 +00:00
|
|
|
* Fake constant timestamp to make sure time-related parser
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
* functions give a persistent value.
|
2017-07-07 01:02:47 +00:00
|
|
|
*
|
Deprecate Parser implementation methods (will be private in next release)
The following public methods were renamed and made private; the old name
is hard-deprecated and calls the new renamed private method:
Parser::doMagicLinks() => handleMagicLinks()
Parser::doDoubleUnderscore() => handleMagicLinks()
Parser::doHeadings() => handleHeadings()
Parser::doAllQuotes() => handleAllQuotes()
Parser::replaceExternalLinks() => handleExternalLinks()
Parser::replaceInternalLinks() => handleInternalLinks()
Parser::replaceInternalLinks2() => handleInternalLinks2()
Parser::getVariableValue() => expandMagicVariable()
Parser::initialiseVariables() => initializeVariables()
Parser::formatHeadings() => finalizeHeadings()
Parser::test{Pst,Preprocess,Srvus}() => fuzzTest{Pst,Preprocess,Srvus}()
Additionally, the following methods are not used externally, but are
used outside the Parser class by core code. They have been marked
@internal:
Parser::doQuotes() (used by {{#displaytitle}}),
Parser::getExternalLink{Rel,Attribs}() (used by Linker),
Parser::normalizeLinkUrl() (used by Special:LinkSearch and elsewhere).
Parser::{brace,arg,extension}Substitution() (used by PPFrame)
Code search query:
https://codesearch.wmflabs.org/deployed/?q=do%28MagicLinks%7CDoubleUnderscore%7CHeadings%7CAllQuotes%29%7Creplace%28ExternalLinks%7CInternalLinks%28%7C2%29%29%7CgetVariableValue%7CinitialiseVariables%7CformatHeadings%7Ctest%28Pst%7CPreprocess%7CSrvus%29%7CdoQuotes%7CgetExternalLink%28Rel%7CAttribs%29%7CnormalizeLinkUrl%7C%28brace%2Carg%2Cextension%29Substitution&i=nope&files=&repos=
Bug: T236810
Change-Id: I19a43ffc5dcfdd2981b51079c33422c964acb076
2019-10-28 19:52:50 +00:00
|
|
|
* - Parser::expandMagicVariable (via ParserGetVariableValueTs hook)
|
2017-07-07 01:02:47 +00:00
|
|
|
* - Parser::preSaveTransform (via ParserOptions)
|
2020-01-09 23:38:41 +00:00
|
|
|
* @return int Fake constant timestamp.
|
Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.
Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.
General:
* Split out the pre-Setup.php global variable configuration from
phpunit.php into a new class called TestSetup, also called it from
parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
Maintenance.
* In Setup.php improved "caches" debug output.
PHPUnit frontend:
* Delete the entire contents of NewParserTest and replace it with a
small wrapper around ParserTestRunner. It doesn't inherit from
MediaWikiTestCase anymore since integrating the setup code was an
unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
instantiable TestSuite class instead of just a static method. Got rid
of the eval(), just construct TestCase objects directly with a
specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
support them anymore. Note that --filter now works just as well as
--regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
once, as is implied by the documentation.
parserTests.php frontend:
* Made parserTests.php into a Maintenance subclass, moved CLI-specific
code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
to the old default behaviour
Test file reading and interpretation:
* Rename TestFileIterator to TestFileReader, and make it read and buffer
an entire file, instead of iterating.
* The previous code had an associative array representation of test
specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
unnecessary now that all extensions use ParserFirstCallInit. Resurrect
an old interpretation of the feature which was accidentally broken: if
a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
articles in them. This greatly speeds up execution time when --regex
matches a small number of tests. It may possibly break extensions, but
they would have been randomly broken anyway since there is no
guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
link formatting, life is complicated enough already. It can go in
OutputPageTest if that's a thing we really need.
Result recording and display:
* Make TestRecorder into a generic plugin interface for progress output
etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
a long inheritance chain. All test recorders now directly inherit from
TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
frontend. Most events are ignored since they are never emitted in the
PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.
Setup and teardown:
* Introduce a new API for setup/teardown where setup functions return a
ScopedCallback object which automatically performs the corresponding
teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
here which was simply copied from Setup.php without review, and had
nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
performance, give staticSetup() precedence in cases where they were
both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
now! Also, the relevant parser tests were removed from the Math
extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
allows setup/teardown to be done once for each batch of articles
instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
copied in from Setup.php in 2010, and are redundant since we do
actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
this alone.
Fuzz tests:
* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
where they used to reside.
Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-08 01:25:22 +00:00
|
|
|
*/
|
2017-07-07 01:02:47 +00:00
|
|
|
private function getFakeTimestamp() {
|
|
|
|
|
// parsed as '1970-01-01T00:02:03Z'
|
|
|
|
|
return 123;
|
2012-01-09 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
}
|