Commit graph

221 commits

Author SHA1 Message Date
Umherirrender
e00a52e6f5 Clean up line indent with mixed tabs and whitespaces
Change-Id: Ifcd15ecc4212d4ebfc26b2e18d6f1da47abf2a86
2022-07-09 22:21:53 +02:00
C. Scott Ananian
a55d21d7d8 ParserTestRunner: Follow up to 5f5b4cbb; regression when page language is set
Don't pass the page language string as the (ignored) wikitext override
string.

Change-Id: Ifa575df17403411b8528ece3a70d67c11e335831
2022-06-17 15:55:59 -04:00
Subramanya Sastry
5f5b4cbbb4 Have Parsoid\Config\PageConfigFactory take a rev instead of wikitext
* This let us pass mocked revisions in the parser test runner while
  running in Parsoid mode.

* This leads to improvement in wt2html tests results where a revision
  id is queried. I've verified this in the Cite extension repo as
  also the main parserTests.text file but I cannot enable Parsoid
  integrated testing on the main parser tests file without doing a
  sweep over all parser tests and adding appropriate test sections

* Currently, PageConfigFactory doesn't have unit tests. Will look
  into adding them separately in a followup.

* Moved the setupParsoidTransform function to a more suitable place
  in the ParserTestRunner.php file.

Bug: T270310
Change-Id: I94d68c8528bb2f7b367c68d80d14ebc1ab904a7f
2022-06-15 22:55:28 -05:00
Subramanya Sastry
29578f449e ParserTestRunner: Reset DataAccess for each test
* 3 more tests now pass that would only fail when run with other tests
  but pass when run with --filter.

Change-Id: Ib0f97cd29b55ff27d891eee1160b66da1e95129c
2022-06-15 22:55:28 -05:00
Subramanya Sastry
e9acc7c060 ParserTestRunner: Fix wiki url for Parsoid-specific config
* This makes 3 more tests match Parsoid's standalone run output

Change-Id: I12f6557c865a3bf8de234c9a084f188fc9320558
2022-06-09 10:00:25 -04:00
Subramanya Sastry
61b54be68c ParserTests: Reset ParsoidSiteConfig always
When a test sets options to change global config, we have to rebuild
the ParsoidSiteConfig instance to pick up the test options since
the service container caches the SiteConfig instance.

For now, we are unconditionally resetting SiteConfig before every
<test,mode> combination. At a later time, we can figure out a way
to do it more conditionally; filed T310283 for that.

Bug: T310283
Change-Id: Ia2dfd37e3da3e1e8b31ab917b1f831eaea5eb5c5
2022-06-09 09:59:33 -04:00
C. Scott Ananian
5fdcdd307a Follow up to d522079c: Fix crashes with skipped tests.
This is an alternative to I55280b0d57d689bb7b43adde5025749f64a2683a.

Change-Id: Ib825c2e968256803dd402937862b1cd8b32cf2fc
2022-06-07 18:41:20 -04:00
Subramanya Sastry
0442728ed8 ParserTestRuner: Init 'selser' to prevent 'Undefined index' warnings
Change-Id: I81135bb7974a5434fd3180ef942cdd1a03868789
2022-06-06 11:34:19 -05:00
C. Scott Ananian
d522079c9f ParserTestRunner: move more common code into ::runTest()
Move the TestRecorder calls into runTest() to DRY out the parsoid and
legacy test runners a bit.

Change-Id: Ice91811c9106f07a95a0f8910f439eb784b35d7e
2022-06-03 17:44:26 -04:00
C. Scott Ananian
760c2fe94b Parser tests: the Test::$config property is now always an array
Previously versions of Parsoid represented the !!config section as
a string which then had to be parsed by the ParserTestRunner.

Bug: T307720
Depends-On: Ieaac08e8171fd4c2a233646a84caac70ec30db6f
Change-Id: I3c5666d061c469049bf150ff0fa3010cb907a493
2022-06-03 17:16:24 -04:00
C. Scott Ananian
a5a04f56bd Pass <Test,TestMode> as argument pair, deprecate old TestFileReader
We introduced a new type for "ParserTestMode" and then uniformly pass
this around alongside the ParserTest object itself.  (We started by
using a string for the $mode but the "explicit changetree" mode
requires more structured data.  We *could* encode this in JSON just to
keep the string type around, but it seems cleaner and more future
proof to wrap this in a proper class type.)

Removed the old TestFileReader wrapper class, which served only as
a thunk to convert the new Test class into the same sort of array
which the legacy parser test runner code expected.  There's still
some remaining ::testToArray() usage here for the TestRecorder
framework, but that will be cleaned up in a future patch.

Also updated the TestRecorder with stronger types: use the same
<Test,TestMode> pair when invoking the TestRecorder, instead of the
loosely typed array we'd used previously.

Change-Id: Iec4c0c7972a655b4faccacc67bdc3ca66d4c163d
2022-06-03 17:15:38 -04:00
Umherirrender
3acc9e63c0 tests/parser: Run phan
Run phan over classes in tests/parser

The dependency of classes between parser and phpunit is not clear.
Classes used by both possible needs part of /common/

Change-Id: I2ceca6b7cd447876c127ed3b14e09f479defbd93
2022-06-02 00:13:30 +02:00
jenkins-bot
203e12d3a3 Merge "Revert "ParserTestRunner: undo class rename of TestFileReader"" 2022-06-01 16:51:51 +00:00
Subramanya Sastry
3e22c5b975 Revert "ParserTestRunner: undo class rename of TestFileReader"
This reverts commit 123f785cdf.

Reason for revert: This breaks parserTests.php script since the ParserTestRunner script has references to both TestFileReader classes and this patch ends up using the same reader everywhere.

Change-Id: I22bdd05f9a86674e88335cc9055f1ce6cfa128d1
2022-06-01 00:00:19 +00:00
Umherirrender
770f905900 tests: Use namespaced IDatabase class
Change-Id: I7171ff26faee00d9eaabc33c2f3d91049ea0b40d
2022-05-28 00:09:55 +02:00
C. Scott Ananian
1e64e2f6f0 ParserTestRunner: Use standard PHP mechanism for array defaults in constructor
The ParserTestRunner code was old enough that it used a number of different
mechanisms to supply defaults for options passed via an array; uniformly use
the standard PHP "array add" mechanism instead.

Change-Id: I1791f7f8b1ae2cc6f4dd23351e9810a98b598be1
2022-05-27 10:12:56 -04:00
C. Scott Ananian
123f785cdf ParserTestRunner: undo class rename of TestFileReader
Long term there isn't going to be a "TestFileReader" and
"ParsoidTestFileReader", the legacy test file reader is just a
temporary hack.  And these aren't "Parsoid Test Files" they
are *parser test files* (ie, implementation independent,
more or less).  Long story short, adding "Parsoid" to the
class name is a step in the wrong direction.

Change-Id: I9b520c39c6c5b52334c658ec2a97bd38612dbf61
2022-05-23 10:53:46 -04:00
Subramanya Sastry
9e6b7156bc Add Parsoid capabilities to parserTests.php script
* This adds all of Parsoid's abilities to the parserTests.php script
* Parsoid testing mode requires a "--parsoid" CLI option.
* This supports "--wt2html" and the other testing modes,
  "--updateKnownFailures", "--knownFailures", and "--changetree"
  options that are part of the Parsoid's parserTests.php script.
* Verified that the output of parserTests.php test run matches
  the output of the PHPUnit test run on the Cite extensions'
  citeParserTests.txt file.

Change-Id: I87a1f621d0a2579ac47fa80d34cf74d4456bcf62
2022-05-20 20:37:50 +00:00
Subramanya Sastry
b5bcc0dec3 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-05-20 16:23:16 -04:00
jenkins-bot
63c77060a0 Merge "Language: Inject NamespaceInfo" 2022-05-12 18:34:50 +00:00
jenkins-bot
9a0d234e05 Merge "Add partial support for running Parsoid selser tests" 2022-05-12 02:15:58 +00:00
jenkins-bot
cb0dec9c1c Merge "Add support for Parsoid html2wt & html2html testing modes" 2022-05-12 02:12:08 +00:00
Bartosz Dziewoński
252a1c8e5f Language: Inject NamespaceInfo
Change-Id: I90eee60467698bbefb619bfa69abfaa10c759fea
2022-05-11 17:24:17 +02:00
C. Scott Ananian
226f7c185f Accomodate a future change to config information in the ParserTest class
Instead of parsing the configuration section here in ParserTestRunner,
it should be done by the parser test file parser.

Change-Id: I75473106cd7dcde6cc289a904f5669eaac717be8
2022-05-05 11:51:38 -04:00
jenkins-bot
4a8ee34f09 Merge "Use str_starts_with/str_ends_with" 2022-05-03 02:37:12 +00:00
jenkins-bot
6139f984d2 Merge "Move bad file tests to mediaParserTests" 2022-05-02 23:02:26 +00:00
Aryeh Gregor
7b4b0135b9 Use str_starts_with/str_ends_with
All the other ways of doing it were ridiculous and much harder to read,
and usually required repeating the needle expression (to get its
length). I found these occurrences by grepping for various expressions,
but I undoubtedly missed some.

I didn't try replacing the many instances of strpos(...) === 0 with
str_starts_with(...), because I think they're readable enough as-is
(although less efficient). Likewise I didn't try porting strpos(...) !==
false to str_contains(...). For case-insensitive comparisons, Tim
Starling requested that we stick with substr_compare() because it's more
efficient than calling strtolower().

On PHP < 8 these functions will be included with a polyfill via
vendor/autoload.php. This is included at the beginning of
includes/AutoLoader.php, so if our autoloader has been included the
polyfill will be available. This means it should be safe to call these
functions from any code that would not be usable without our autoloader.

Three uses that Tim Starling identified as being performance-sensitive
have been split out to a separate commit for porting after the switch to
PHP 8.

Change-Id: I113a8d052b6845852c15969a2f0e6fbbe3e9f8d9
2022-05-02 10:59:58 +03:00
Aryeh Gregor
79fc95d39c Use MainConfigNames instead of string literals, #5
This should be the last of the usages in core, although I'm sure a few
are hiding somehow.

Change-Id: I7bf0b24bf23d3efb4c56a891830bbfe67945e899
2022-04-27 18:46:29 +03:00
Arlo Breault
baf72a9b6c Move bad file tests to mediaParserTests
Move resetting the bad file lookup service into addArticles, since it
needs to be reset whenever articles are added, and that happens in the
setUp of ParserTestFileSuite as well.

Bug: T75581
Change-Id: Iedc4cfe9b76762d64f9c0f9d813c64de5fb98dce
2022-04-25 15:49:42 -04:00
Subramanya Sastry
e818b00c9e Add partial support for running Parsoid selser tests
* This patch only adds support for
  - selser manual edits tests
  - selser changetree [5] tests
  Both these types of selser tests are known statically.

* This doesn't yet add support for selser auto-edit tests since
  they cannot be determined statically.

  There is some code already in place in the test runner to apply
  change trees, but it will all likely get refactored in a future
  patch.

Bug: T270311
Depends-On: I3be7826e08be120043f3bcd9151bade930b65fb7
Change-Id: Ic824dae6ee49867c766d40c11acfda117c7e2689
2022-04-21 16:28:10 +05:30
Subramanya Sastry
99d9dd2a0f Add support for Parsoid html2wt & html2html testing modes
* Did a bunch of DRYing out and extracted helper functions.
* The actual wt2html, wt2wt, html2wt, and html2html functions
  are much simpler to grok.
* Fix handling of knownFailures.

Bug: T270311
Depends-On: Iff4a45bf35e35f6980e73567538b164e3f0b03bc
Depends-On: If083275fe8ca0beb2ba8ddb883297b6f221cc466
Depends-On: I1e7d61e9d0fd9d7d3aa7f2f55ea718d808c985cb
Change-Id: I904b22c44bf5a7522d92cf761d5a0a82713b834e
2022-04-21 16:28:10 +05:30
Subramanya Sastry
60288ceeda ParserTestRunner: Get rid of user-specific option
* Parsoid currently doesn't have user state in SiteConfig and if test
  config add user-specific state, Parsoid's tests will fail since
  Parsoid\Config\SiteConfig::widthOption uses default options and not
  user-specific state.

  Alternatively, we would have to change SiteConfig code to use $wgUser
  to fetch the option value.

  But, since there is no real reason to use user-specific state in
  parser tests, we can disable this for now.

* Discovered when I enabled Parsoid testing modes for Cite and ran into
  a bunch of crashers.

* Maybe, in the not-so-distant future, we will probably have to figure
  out user-state based parsing since there are features that aren't
  amenable to html2html transformations (ex: {{int:}}) and at that time,
  we can revisit if we want to revert this change.

Change-Id: I316fe01608acf38a08df74bdff87040179461028
2022-04-14 13:43:18 +05:30
Arlo Breault
8d48b61ed3 Fix bad file tests in parserTests
Change-Id: I2ba4f41283c20d9d200ffbd62eb7c507c698ab5a
Enthusiastically-Suggested-By: Kunal Mehta <legoktm@debian.org>
Bug: T75581
2022-04-08 14:46:07 -04:00
Subramanya Sastry
ca5e95fe68 Add wt2wt test mode to ParsoidTestRunner
* Make use of caching support in the (Parsoid)Test object.

Bug: T270311
Change-Id: I76894c6633dc37fb08af089ea852862ca6a5e90f
2022-04-06 00:49:23 +05:30
Subramanya Sastry
3c59432f2d Refactor Parsoid test runner to simplify testing non-wt2html modes
* This creates a fresh PHPUnit test for every test mode of a test.
  Parsoid's native test runner does this a lot more efficiently by
  reusing pipelines, env objects, and also intermediate test results.

  That way of running tests is trickier in the PHPUnit test setup.

* Non-wt2html test modes will come in future patches.

Bug: T270311
Depends-On: Iacdff9e47e0d98ac3aa3a61757935d6ea3e91096
Change-Id: I58f63ebd53939b358cefe60ac34f26cded52697d
2022-04-06 00:48:35 +05:30
Ammarpad
e8d2f182e6 ParserTestRunner: Remove unused property $dbClone
Also fix type doc of $fileBackendName.

Change-Id: Ifac11a89c0a4bf8c8c0c6219d2751813cd52b3ea
2022-03-16 16:42:09 +00:00
Timo Tijhof
128debb64b tests: Change use of AtEase to at operator
Follows-up I361fde0de7f4406bce6ed075ed397effa5be3359.

Per T253461, not mass-changing source code, but the use of the native
error silencing operator (@) is especially useful in tests because:

1. It requires any/all statements to be explicitly marked. The
   suppressWarnings/restoreWarnings sections encourage developers to
   be "lazy" and thus encapsulate more than needed if there are multiple
   ones near each other, which would ignore potentially important
   warnings in a test case, which is generally exactly the time when
   it is really useful to get warnings etc.

2. It avoids leaking state, for example in LBFactoryTest the
   assertFalse call would throw a PHPUnit assertion error (not meant
   to be caught by the local catch), and thus won't reach
   AtEase::restoreWarnings. This then causes later code to end up
   in a mismatching state and creates a confusing error_reporting
   state.

See .phpcs.xml, where the at operator is allowed for all test code.

Change-Id: I68d1725d685e0a7586468bc9de6dc29ceea31b8a
2022-02-24 21:29:51 +00:00
Reedy
12aae45101 tests: Replace some usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: I361fde0de7f4406bce6ed075ed397effa5be3359
2022-02-24 12:55:25 +00:00
C. Scott Ananian
c39ef6c6c9 Change return value of ParserOutput::getPageProperty() when property is missing
The old ParserOutput::getProperty() method returned `false` when a property
was missing.  This requires callers to use the `?:` syntax to supply default
values, which then causes any falsey value to be treated as missing.
So, for example, setting the defaultsort to '0' will cause the default
sort to be ignored.

Modern php convention is to use `null` for missing values, and the `??`
syntax is a better/more restrictive alternative to `?:`.

We renamed `ParserOutput::getProperty()` to `::getPageProperty()` in
1.38 (Ie963eea5aa0f0e984ced7c4dfa0fd65d57313cfa/T287216) but kept the
return value convention.  Before this actually makes it into a 1.38
release, take the opportunity to fix the return value for the new
`ParserOutput::getPageProperty()` method to return `null` when the
property is missing.

We need to do some temporary workarounds to the places we'd
already swapped over to use the new `::getPageProperty()` method
to allow them to handle either `false` or `null` as a return value;
we'll clean that up once this is merged.

Code search:
https://codesearch.wmcloud.org/deployed/?q=-%3EgetPageProperty%5C%28|T301915&i=nope&files=&excludeFiles=&repos=

Bug: T301915
Depends-On: I3f11ce604970e47b41fc1c123792df8c3045626f
Depends-On: Ie7533f49fe4cad01ebfda29760d23c61e9867b10
Depends-On: Ic5c09f5caa4c897bc553c614fbae9cee159566a2
Depends-On: I0278b2eafd90e77e4fee41c45a1165fb79ddf47e
Depends-On: I383abb6b7dc5e96c0061af13957609f6e31a1065
Depends-On: I79f9f4078e415284af29b15047bafd1c823d7f5b
Depends-On: I02276c48c49f5d2d241a69eb0a6cdf439b572d8b
Depends-On: I71628661b4539a4e35ae32846e719f92bcf782e0
Depends-On: I7e215cb43de0ce150a6bcc00f92481dcdcfed383
Change-Id: Iaa25c390118d2db2b6578cdd558f2defd5351d15
2022-02-18 21:15:58 +00:00
jenkins-bot
09621c6758 Merge "Parsoid output now respects thumbsize in parserTests" 2022-01-28 04:14:57 +00:00
Umherirrender
68808e5832 Replace deprecated JobQueueGroup::singleton()
Change-Id: Icdb301d352d302f70fefba9b40df2368cb217fd2
2022-01-27 21:37:50 +01:00
Arlo Breault
1054965edc Parsoid output now respects thumbsize in parserTests
Depends-On: I1ebfe6bf4d5a5be2ed3a1d7ab27cca1886aac3d6
Change-Id: Ic028b729c577bfd5dd30add0c0508e72fee0ca36
2022-01-27 15:06:47 -05:00
jenkins-bot
fd84c0f087 Merge "tests: Replace usages of deprecated WikiPage::doDeleteArticleReal" 2022-01-27 19:32:06 +00:00
Tim Starling
80a22645f6 Allow parser tests to test the value of extension data and properties
* Add "property" and "extension" options to parser tests
* Slightly refactor the relevant code since it's getting big.
* Slightly refactor the documentation too.

Change-Id: Idc4ac4eb4e20d8e3e2fdbd093ff75f26d3af0d57
2022-01-24 12:46:34 +11:00
Daimona Eaytoy
2688c59606 tests: Replace usages of deprecated WikiPage::doDeleteArticleReal
Add a new helper to MediaWikiIntegrationTestCase, since deleting pages
seems to be pretty common in tests.

Some calls to WikiPage::factory were also updated to use WikiPageFactory.

Change-Id: I5b5100273a00ac292a1900022ca79708fa254347
2022-01-17 15:38:02 +00:00
Subramanya Sastry
1593387f02 Parsoid's parser test runner no longer provides 'scrubWikitext' opt
Change-Id: Ic02221a4fbd9ed76d1f9b8e0968bc7d5500040b5
2022-01-13 16:43:19 -06:00
Kosta Harlan
0c2cc804e1 phpunit: Use is_file/is_dir instead of file_exists
Yes, it's a micro-optimization. See https://bugs.php.net/bug.php?id=78285
and https://thephp.cc/articles/caching-makes-everything-faster-right
for more info.

Change-Id: Ib8e8e9794e15066476f35cdb1236df8b983274d6
2022-01-03 21:47:56 +01:00
Alexander Vorwerk
9f9426697c Replace usages of deprecated wfWikiID()
The global function wfWikiID() is deprecated since 1.35 and it's usages
should be replaced with WikiMap::getCurrentWikiId().

Bug: T298059
Change-Id: I22d96b7aec17323d15a9bc401d4511ad2ee14165
2021-12-21 02:05:55 +00:00
Bartosz Dziewoński
dd4d1db814 TestRunner: Set local interwiki URLs to match wgServer, like in production
Matching Parsoid change I6e7bdcdea6bc2fd955f0a04f25f09314ec1230c8.

Change-Id: I6e7bdcdea6bc2fd955f0a04f25f09314ec1230c8
2021-12-07 16:20:26 -05:00
Arlo Breault
3b52802e52 Add project local interwiki to ParserTestRunner
Bug: T228616
Change-Id: Icd659d000445778d4d7c46ad67d96d6df22454e2
2021-12-03 14:47:50 -05:00