Commit graph

253 commits

Author SHA1 Message Date
Umherirrender
f65e6bb488 Replace deprecated Linker::commentBlock/revComment
Bug: T324906
Change-Id: I8cf96c3b7a03127ce1243f7a7e849b6d5a5d3dfa
2022-12-11 01:33:56 +01:00
Amir Sarabadani
2d60ba0c63 Reorg: Move DummyLinker and Linker to linker/
This feels like a no-brainer unless I'm missing something obvious

Bug: T321882
Change-Id: Id49c3d0dd6ea4593211048850856b5b8e05a8fb3
2022-12-08 06:38:17 +01:00
jenkins-bot
064851a643 Merge "Followup to 02d13afa: Respect parsoid-compatible options in CLI runs" 2022-10-26 01:28:02 +00:00
jenkins-bot
f4e063617a Merge "ParserTests: Add --dir option as a complement to the --file option" 2022-10-25 22:13:12 +00:00
Subramanya Sastry
3115940e2d Followup to 02d13afa: Respect parsoid-compatible options in CLI runs
It was possible to run non-compatible tests via the CLI which, among
other things, would have caused a "--parsoid --updateKnownFailures"
test run to add bogus entries to the knownFailures json file.

Change-Id: Ie3c51b97edb9839f775301670018bb4ba3290fbe
2022-10-25 17:05:22 -05:00
Subramanya Sastry
6591c2e74d ParserTests: Add --dir option as a complement to the --file option
This lets us run parser tests on specific directories. This is
particularly useful when syncing tests between Parsoid and core
since it lets us rerun tests for all synced files as well as
update known failures if requires for Parsoid integrated mode
test runs.

Change-Id: I9030ddd63997b0b197991860aeb850ebf54d4dd7
2022-10-25 15:43:26 -05:00
Amir Sarabadani
0fff5089ba Reorg: Move StubObject classes in includes to its own directory
Bug: T166010
Change-Id: Idcf0e9dc6e0841e4f132207bce0f96774dad898c
2022-10-25 16:04:48 -04:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
C. Scott Ananian
d96207ab86 Auto-discover core parser test files
Make parser test discover in core work the same way as it does in
extensions: any file ending with *.txt under tests/parser is run
as a parser test file.

This search is recursive, which is motivation to also move some
unrelated files under tests/parser/preprocess over to
tests/phpunit/data/preprocess where they belong; they are used
by tests/phpunit/includes/parser/PreprocessorTest.php and are
unrelated to the parser test infrastructure.

Change-Id: I8c84b4b853e1309929dceb700aab1e79a598d8ab
2022-10-13 10:41:15 -04:00
C. Scott Ananian
4cb3957cf0 Remove $wgParserTestFiles, deprecated in MW 1.30
This global variable was replaced by auto-discovery of parser test
files in extensions and is no longer needed (or used).

Change-Id: Ib616e60f36db32ffd8bc69c71a096f23c0a27910
2022-10-13 09:22:22 -04:00
C. Scott Ananian
e6be4e55d5 Sync up core repo with Parsoid
This now aligns with Parsoid commit a3d35adf78c3c7e6a8f04e9a55b76f3efefaedb8

The monolithic parserTests.txt have been split up into a number of smaller
test files (more splitting to come) and three existing parser test files have
been renamed:
  mediaParserTests.txt => media.txt
  legacyMediaParserTests.txt => legacyMedia.txt
  extraParserTests.txt => badCharacters.txt

This reduces redundancy and filename length now that we've got a dozen or so
of these.

Change-Id: I2c1461341fcb3f3cef8e49b5575cd30f3a38e500
2022-10-12 16:33:10 -04:00
Subramanya Sastry
d8f609ef74 ParserTestRunner: Do all Parsoid-specific test setup together
* Unclear if this is actually useful or helpful, but at least the
  legacy and Parsoid test modes do all setup close together now.

* See I776b22a973fbcc945106fbe807376b858dd79e48 for a more detailed
  explanation. This patch is a followup from that patch.

Change-Id: I720d31c3573b57b66956bdd98d11e4f89df9cca0
2022-09-28 11:55:38 -05:00
Subramanya Sastry
7774651214 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: f7d6c0190d
Change-Id: I776b22a973fbcc945106fbe807376b858dd79e48
2022-09-26 17:01:04 -05:00
C. Scott Ananian
5cb4693772 Unify no-arg and 1-arg forms of {{REVISIONTIMESTAMP}} and friends
Eliminate a difference between the magic variable (no-arg) and
parser function (1-arg) forms; aka the difference between
{REVISIONTIMESTAMP}} and {{REVISIONTIMESTAMP:{{PAGENAME}}}}.

This is a follow up to I8d25755e4d92bd91988cfb706d85bdb170abb207.

The magic variable contains a MAX_TTS optimisation which reduces
the use of vary-revision-timestamp, since it has severe performance
implications; this patch applies the same optimisation to the
parser function.

The ParserTestRunner has a small issue with test setup:
ParserOptions::setTimestamp() was called with a unix-format timestamp,
where it expected a TS_MW format timestamp.  This issue was
fixed, along with tweaking the test timestamps so that a timestamp
coming from ParserOptions would still be distinguishable from one
coming from the revision.

Bug: T204370
Change-Id: I883d42d67013b6fb0da57c61e715b51d3a807879
2022-09-21 17:02:22 -04:00
Isabelle Hurbain-Palatin
f7d6c0190d Add support of ParserOptions::setExternalLinkTarget() in legacy parser tests
As a follow-up to Ife14d7319ecbb7b588cbac97fae109b14230c44a, we want to
check that the legacy parser and Parsoid align on what's expected for
nofollow/noreferrer/noopener. Since the wgExternalLinkTarget setting is
modified on the Parsoid side during specific tests, we align the test
runner on the legacy parser to be able to test for this.

Bug: T186241
Change-Id: I2824182eaa5c50cd3e8e0193726d896da285a3a8
2022-09-12 11:37:51 -04:00
Umherirrender
6555923b08 tests: Replace deprecated WikiPage::factory
Bug: T297688
Change-Id: Ic84d491c5603f3590e26cb56a305508b2b0ca109
2022-09-02 19:34:02 +00:00
Subramanya Sastry
6d36e1eb2d ParserTestRunner: Clear title cache in cleanupArticles
* This ensures that titles don't conflict across test runs.
  I am surprised this hasn't bitten any one in non parsoid
  parser test runs in case titles are repeated across test files.

* I wonder if this was also the source of some of the transient
  errors seen in T312709 and T312517.

* Scribunto calls fetchModuleFromParser in two places and passes
  it a title. In one case, the title comes from Title::newFromText
  (in the call in LuaEngine.php when asked to load a module from
  within Lua code). In another case, the title comes from
  Title::makeTitleSafe (in Hooks.php to run #invoke on a module).

  Title::newFromText uses a title cache whereas Title::makeTitleSafe
  constructs a new title.

  And, it turned out that in Parsoid runs, the revision lookup
  for the module had the wrong revid when it came from Lua code.
  This then caused the package lookup to fail only when the module
  was loaded in Lua code.

  That this test only failed in Parsoid test runs is because we
  ran Parsoid tests after legacy parser tests. If we had switched
  the order, legacy parser tests would have failed.

  I haven't connected all the dots from the cached title in Title.php
  to it getting an incorrect revid (but not an incorrect pageid).
  But, clearing caches in the parser test runner seems to fix
  this problem.

  I welcome someone else helping with fleshing out this trail as to
  how the title caching leads to only the revid going out of sync.

* Since I could only reproduce this in Jenkins CI (and not locally),
  debugging this turned out to be painful.

Bug: T316331
Change-Id: I7c419e1d508c337328db1d5132454fb805bfb1b5
2022-09-01 20:04:14 +00:00
Subramanya Sastry
db5b905851 ParserTests: Clean up some duplicate revrecord logic
* This should hopefully make the code a bit dryer and easier to read.
* While this should not matter in practice, when testing against Parsoid,
  don't create two different mutable revision records  for tests where
  'lastsavedrevision' option is set.

Change-Id: I5da7ec9ec688df0a1f84f7c1817775fd94a1e092
2022-09-01 14:54:33 -04:00
Arlo Breault
4703724fe8 Don't reconstruct formatting elements in figures
Similar to I3c55eb5fb8055016f8c4f76d27d953f65ff621be in Parsoid

Bug: T314059
Change-Id: I7b4e9df8490357f44d31d6a869fa9b7a15f029ea
2022-08-31 18:55:23 -04:00
jenkins-bot
53e3f0f547 Merge "Ensure that flags= output in ParserTestRunner is more complete" 2022-08-22 22:39:24 +00:00
jenkins-bot
05a9b04d2d Merge "tests/parser/TestMode: move parser test helper class to parsoid library" 2022-08-18 22:01:36 +00:00
jenkins-bot
d3408699b7 Merge "Revert "ParserTestRuner: Init 'selser' to prevent 'Undefined index' warnings"" 2022-08-18 14:09:35 +00:00
C. Scott Ananian
5a49745add tests/parser/TestMode: move parser test helper class to parsoid library
Depends-On: I6a653889afd42fefb61daefd8ac842107dce8759
Depends-On: I73f320dfb03e5c26971a7bc36564021d2c9f3695
Change-Id: Id3e44a5b419d7f6917819e72c046f94a3a2286fe
2022-08-16 16:26:25 -04:00
C. Scott Ananian
f28e2541c6 Revert "ParserTestRuner: Init 'selser' to prevent 'Undefined index' warnings"
This reverts commit 0442728ed8, as the issue was fixed upstream in Parsoid.  Further, this "fix" inadvertently disabled all but "selser" test modes for Parsoid parser tests run by CI.

Depends-On: Iebd6f6b25aff779efaa55ce9c25eec117403884c
Change-Id: I34d719f43f11e1793b012395d359af2e260f8743
2022-08-11 23:17:12 +00:00
jenkins-bot
425303861f Merge "rdbms: add getDomainChangeException() call to DBConnRef::tablePrefix()" 2022-08-10 04:14:28 +00:00
Aaron Schulz
3e49c2029e rdbms: add getDomainChangeException() call to DBConnRef::tablePrefix()
This matches the DB domain logic enforcement in the other class methods.

Cleanup several type hints in related code.

Change-Id: I6668852ccebe16349b38b5a793543bd3ec0a35b8
2022-08-03 21:41:09 +00:00
TheSandDoctor
da38639658 Remove deprecated $wgParser
$wgParser, deprecated in 1.32, has been removed.

Bug: T160811
Change-Id: Iaf09d3e158e1fee8c0f541695b6d9b4233033c81
2022-08-03 14:40:16 +02:00
Subramanya Sastry
ac237bc68d Parsoid Parser Tests: Fix test processing to update knownFailures
* processResults continued to report failures even when a test was
  newly passing.

* Updated result processing to recognize newly passing tests.

* I removed the CI-focused performance optimization that recognized
  an expected failure and bailed early without trying to determine
  if there was an unexpected passing test. This could lead to devs
  not recognizing changes to test results and not updating the known
  failures file to remove newly passing tests.

Change-Id: Iee0b2b3388028b327c30d63b17394149dd8cdc42
2022-07-29 12:46:56 -05:00
Subramanya Sastry
c3ed85a0c8 Parsoid Testing: Use FormatJson to emit / update knownFailures json
* This lets us meet CI requirements that expect tabs instead of spaces
  in JSON files.

Change-Id: I91170d60753b083349fda044e268ef3933aa7abe
2022-07-28 12:18:57 -05:00
C. Scott Ananian
0397bb1675 Ensure that flags= output in ParserTestRunner is more complete
In particular, there was a test of __NEWSECTIONLINK__ added by
4e717c0158 (way back when) which seemed
to be intended to check that the appropriate ParserOutputFlag was set,
but that output flag was never included in the `flags=` parser test
output.  Address that to improve coverage.

Change-Id: Iccd80e63e9fd724bf7dfb7f243f823a2b9f9915d
2022-07-28 11:05:28 -04:00
Subramanya Sastry
ca6f07273a ParserTestRunner: Couple more fixes for Parsoid test runs
* Prevent crashers when selser tests are skipped.
* Don't run processResults when running in 'cache' mode.
* Added a isCachingMode() helper to TestMode.php -- not sure
  if this was overkill, but did it anyway.

Change-Id: I2b100bd852306b9ce1de69117c6ca7d7d9c9ce3f
2022-07-21 15:20:01 -05:00
Subramanya Sastry
f19d6a3ba8 Don't run wt2wt and selser on tests without Parsoid HTML
* This matches behavior in standalone mode.
* If we want to run these tests (especially selser),
  we should probably add html section. For wt2wt tests,
  we may end up tweaking the wikitext to reduce spurious
  wt2wt failures because of normalization.
* So for now, skip these tests.

Change-Id: I2b9444ecae1bbf012aebdb81a134ee07ed4582c7
2022-07-18 20:05:49 -05:00
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