Commit graph

9861 commits

Author SHA1 Message Date
Timo Tijhof
f7e8bc6a69 exception: Add test for MWExceptionHandler trace formatting
Change-Id: I00b9607ba7e17c1f75ef065e83b83d2e1a82870c
2021-01-13 23:26:48 +00:00
Timo Tijhof
eae704846b exception: Minor clean up in MWExceptionHandler test case
* Use yield in data providers.
* Use consistent inline comment syntax.
* Provide a description of the value in assertion.
  This should not be a negated error message, which can be
  confusing at times when it describes the opposite of what is
  expected. PHPUnit is in charge of explaining the error for most
  assertions.

Change-Id: Ib0e138aa029f00ce7f4ce53cf2cb480045e5e8d2
2021-01-12 20:27:07 +00:00
daniel
68968305e3 Fix undefined index error in ApiQueryInfo
The code didn't properly handle requests for info about non-existing
pages.

Bug: T271804
Bug: T271815
Change-Id: If4e56ff5ecb4a048767833c89847bb58269cad43
2021-01-12 15:29:52 +00:00
jenkins-bot
0259ec87a7 Merge "Safer autoloading with respect to file-scope code" 2021-01-12 10:23:28 +00:00
jenkins-bot
065aaa3ddc Merge "Revert "Enhance GroupPermissionsLookup and use it."" 2021-01-12 05:39:15 +00:00
jenkins-bot
7200e36c9f Merge "parser: convert Preprocessor to WANCache and inject dependencies" 2021-01-12 05:04:47 +00:00
jenkins-bot
ca34763bb8 Merge "WikiPage: Add process cache for content model" 2021-01-12 04:54:06 +00:00
Ppchelko
bdb5f394d3 Revert "Enhance GroupPermissionsLookup and use it."
This reverts commit 900c6663b0.

Reason for revert: breaks Parsoid CI. Instead of fixing the test in presence of the FlaggedRevs hook, I would rather convert DefaultPreferencesFactory to Authority and fix the tests once instead of doing it twice.

Change-Id: Iaa440a9804c9ed97339e737162ef64ccf29ceb51
2021-01-12 04:48:49 +00:00
Aaron Schulz
de6eeead21 parser: convert Preprocessor to WANCache and inject dependencies
Make the caching logic use getWithSetCallback() and simplify
the code given that there is only one Preprocessor subclass.
Also, keep the cached values JSON serializable but rely on
the serialization in BagOStuff instead for simplicity.

Add related class constants for injecting preprocessor flags.

Bug: T254608
Change-Id: I72f9f0c0bc352ed5120469090c71294ff0c24999
2021-01-11 20:21:10 -08:00
jenkins-bot
87f373579c Merge "WatchedItemStore: use UserFactory" 2021-01-12 00:28:58 +00:00
Petr Pchelko
900c6663b0 Enhance GroupPermissionsLookup and use it.
Added new methods:
- ::getGroupsWithAnyPermissions
- ::getGroupsWithAllPermissions
- ::groupHasAnyPermission
- ::groupHasAllPermission

Replaced relevant calls to PermissionManager with
calls to GroupPermissionsLookup.

Bug: T254537
Change-Id: I0b9c3352c5bebc94e1649239fe0527144e7c2eb2
2021-01-11 11:05:54 -06:00
Tim Starling
20d06b34bb Safer autoloading with respect to file-scope code
Many files were in the autoloader despite having potentially harmful
file-scope code.

* Exclude all CommandLineInc maintenance scripts from the autoloader.
* Introduce  "NO_AUTOLOAD" tag which excludes the file containing it
  from the autoloader. Use it on CommandLineInc.php and a few
  suspicious-looking files without classes in case they are refactored
  to add classes in the future.
* Add a test which parses all non-PSR4 class files and confirms that
  they do not contain dangerous file-scope code. It's slow (15s) but
  its results were enlightening.
* Several maintenance scripts define constants in the file scope,
  intending to modify the behaviour of MediaWiki. Either move the
  define() to a later setup function, or protect with NO_AUTOLOAD.
* Use require_once consistently with Maintenance.php and
  doMaintenance.php, per the original convention which is supposed to
  allow one maintenance script to use the class of another maintenance
  script. Using require breaks autoloading of these maintenance class
  files.
* When Maintenance.php is included, check if MediaWiki has already
  started, and if so, return early. Revert the fix for T250003 which
  is incompatible with this safety measure. Hopefully it was superseded
  by splitting out the class file.
* In runScript.php add a redundant PHP_SAPI check since it does some
  things in file-scope code before any other check will be run.
* Change the if(false) class_alias(...) to something more hackish and
  more compatible with the new test.
* Some site-related scripts found Maintenance.php in a non-standard way.
  Use the standard way.
* fileOpPerfTest.php called error_reporting(). Probably debugging code
  left in; removed.
* Moved mediawiki.compress.7z registration from the class file to the
  caller.

Change-Id: I1b1be90343a5ab678df6f1b1bdd03319dcf6537f
2021-01-11 11:59:36 +11:00
DannyS712
b40ca337c9 WatchedItemStore: use UserFactory
Will allow for converting to true Unit tests

Change-Id: I0ef2ada0d5ee9a80a104cb9b07a50e3887d02dd3
2021-01-10 03:12:25 +00:00
jenkins-bot
44252a899c Merge "Add helpful @var tags to BlockManagerTest" 2021-01-08 20:45:38 +00:00
Timo Tijhof
a53a38ec5e phpunit: Remove odd "MediaWiki" group from tests using it
Doesn't appear to have any meaning.

Change-Id: Id12599874f7f5bd727693b9decb190e9d5c7305d
2021-01-08 18:35:30 +00:00
jenkins-bot
7b7082f9c0 Merge "Introduce GroupPermissionsLookup" 2021-01-08 17:47:26 +00:00
Thiemo Kreuz
7166284835 Add helpful @var tags to BlockManagerTest
Without these IDEs mark method calls on the wrapped objects
as errors.

Change-Id: I4d7ee0d7475174c20a18df99ebda7ef1a3afbd56
2021-01-08 17:13:13 +01:00
jenkins-bot
7e3c1e6629 Merge "ApiQueryInfo: Return watchlist expiry when applicable for inprop=watched" 2021-01-08 07:52:13 +00:00
jenkins-bot
a34e301357 Merge "ParserTestRunner: share more code w/ MediaWikiIntegrationTestCase" 2021-01-08 05:42:37 +00:00
C. Scott Ananian
665eae14ac ParserTestRunner: share more code w/ MediaWikiIntegrationTestCase
Refactor the database setup code to share more code between
ParserTestRunner and MediaWikiIntegrationTestCase.  Made
`::setupAllTestDBs` static so it can be reused from
ParserTestRunner.

Made ParserTestRunner::addArticle more like
MediaWikiIntegrationTestCase::addCoreDBData().  Some additional
refactoring work could be done here in the future to share more code.

After the refactoring the ParserTestTables hook is no longer necessary
and so has been (soft) deprecated.  MediaWikiIntegrationTestCase
clones all database tables, so ParserTestRunner no longer needs to ask
extensions for a list of specific tables it should clone.  Cleaning up
the handful of extensions which define this hook will be left to a
future patch set.

Change-Id: I5124789fac333a664b73b4b4a1e801ecc0a618ca
2021-01-07 23:31:12 -05:00
jenkins-bot
e00dc65892 Merge "exception: Move remaiming MWExceptionHandler tests to its test case" 2021-01-08 01:21:00 +00:00
Timo Tijhof
8ad97d7c32 resourceloader: Fail gracefully if a LESS message is not found
The message cache is originally meant for mw.messages in JS,
which expects non-existent messages to be cleanly omitted.
There is minimal server-side and client-side handling in place for this.

For LESS, however, we were assuming that the blob is complete,
thus not feeding anything to the LESS compiler, thus leading to
a run-time failure where the LESS file can't be parsed at all
due to an undeclared variable.

This could happen sometimes during development or after upgrading
a wiki with a stale LocalisationCache that is still being updated
at that time.

Bug: T267785
Change-Id: I60ff4eb7dce1fee56470acc177afd29ee14b764f
2021-01-07 15:41:02 -08:00
Timo Tijhof
8819f3293c exception: Move remaiming MWExceptionHandler tests to its test case
These were left behind during the initial sprint (344481f60d) for
UnitTestCase as it used a global variable. Since then, UnitTestCase
has gained support for resetting these automatically for simple
cases like this. No need to bring in IntegrationTestCase for it.

Change-Id: Id8717c1f4148510ae4a67aec7a2dc0d23679a5ac
2021-01-07 15:09:12 -08:00
DannyS712
52359768c5 Convert or split some tests to MediaWikiUnitTestCase
Don't require any integration

Change-Id: I293a84ce8fe87fc6932f8a6400d6ca443ccc6235
2021-01-07 17:51:27 +00:00
Petr Pchelko
ae0b6c6a1e Introduce GroupPermissionsLookup
In order to break up cyclic dependency between UserGroupManager
and PermissionManager, introduce a lightweight service for checking
group permissions.

Bug: T254537
Depends-On: I99ab3a69c41b3ec6721f9504ad6c77d3122df591
Change-Id: I1acd55c07d07b4a0d43fd838e11374b6d9be98d9
2021-01-06 17:12:28 -06:00
C. Scott Ananian
df1ddd6f9c LanguageLinksHandlerTest: use wgInterwikiCache instead of mutating database
Mutating the interwiki table invalidates the Title codec and in
general leads to a bunch of complications.  Easier to just use the
`wgInterwikiCache` mechanism, as a lot of other phpunit tests do.

Bug: T271287
Change-Id: Id1899a89ae6b55e7032befe73990d215370828d8
2021-01-06 17:07:47 -05:00
MusikAnimal
21d6f1cd6a ApiQueryInfo: Return watchlist expiry when applicable for inprop=watched
The expiry is returned as a separate key, 'watchlistexpiry', to match
other APIs, and because some clients might expect 'watched' to be a
boolean (or blank string depending on the formatversion).

Bug: T268834
Change-Id: I227d6ed42e70ba1ddec0139e8198f536dfba0b46
2021-01-06 13:51:27 -05:00
jenkins-bot
0be01c1777 Merge "Don't show action links for IP ranges outside block limit" 2021-01-05 21:06:37 +00:00
jenkins-bot
b259dab3fe Merge "Add option to allow SpecialPageExecutor return the full HTML content" 2021-01-05 19:04:23 +00:00
Máté Szabó
899b6bd721 WikiPage: Add process cache for content model
WikiPage::getContentModel() gets called several times per request via
Action::getActionName(), triggering memcached I/O on each call. Excimer icicle
graphs for index.php indicate about 1.26% of time is spent in this method, so
let's add process caching to avoid redundant memcached fetches on subsequent
invocations.

Change-Id: Icdb9ffb849a0a0a264083957431495f8f4fb783e
2021-01-05 15:43:11 +01:00
jenkins-bot
452bff212c Merge "Improve assertArrayEquals() logic in test trait" 2021-01-05 12:53:53 +00:00
Ammarpad
bf75f31779 Improve assertArrayEquals() logic in test trait
The previous logic obsfucates the issue about these remaining args
and the fact that they are all deprecated.

This patch makes it clear what's deprecated and the remaining
acceptable args count and position.

Change-Id: Ia7cef161fb990fac700fd2360c170d6ff1c4a8d0
2021-01-05 04:36:10 +01:00
C. Scott Ananian
105bd70eab Don't silently discard exceptions in test suite setUp/tearDown methods
This implementation is based on the upstream code in
\PHPUnit\Framework\TestSuite -- but upstream only calls the
beforeClass/afterClass methods.

Bug: T192167
Bug: T270777
Followup-To: Ia12658554c94497a204b7f65f1a6f7b1fa0310ac
Depends-On: I9eee817abb35f5bd3650d93a11ca208b1e3d8bf0
Change-Id: I9c4d89f9f54808b0415c9af7e7b0ac9df69c2389
2021-01-04 13:24:40 -05:00
Umherirrender
3aade9e40a Use expectWarning/Deprecation/Notice/Error() in phpunit tests
It is deprecated in newer phpunit versions

Bug: T271049
Change-Id: I3b2105cbd582ecc57ab8bc1bb1617300f15682ad
2021-01-04 00:16:51 +00:00
Umherirrender
4bdaf3af19 tests: Use ::class on exception names
Change-Id: Iadc2eabb7d132a21cffccf5468b92328a64acb4a
2021-01-03 20:47:49 +01:00
jenkins-bot
8ee4aa0df7 Merge "api: Add new 'raw' parameter type which avoids Unicode NFC normalization" 2021-01-01 00:33:14 +00:00
jenkins-bot
288b81ccc9 Merge "Create diff markers with CSS" 2020-12-31 01:23:40 +00:00
jenkins-bot
3c02841c94 Merge "TableDiffFormatter: Build HTML using utility class" 2020-12-31 01:09:13 +00:00
jenkins-bot
9c4e795546 Merge "[API] Ignore watchlist preferences for bot users" 2020-12-30 21:02:42 +00:00
Ed Sanders
27319def63 Create diff markers with CSS
Also put <br>s into empty lines so linebreaks are preserved when copying.

Bug: T192526
Change-Id: I926bedf71562c74a0aa33fbeb11f8d1a4e4130c7
2020-12-30 12:52:08 +00:00
Ed Sanders
351077388f TableDiffFormatter: Build HTML using utility class
Change-Id: Idab793bb1aabe8bffcbb2d00f68860d8b05172ef
2020-12-29 22:24:28 +00:00
Taavi Väänänen
b8d9f54028 Remove hard deprecated wfIsBadImage()
Bug: T249459
Change-Id: I363ec383295aff8a2d6cc89b1f0df5369a537473
2020-12-29 15:55:10 +02:00
DannyS712
334fb503d1 ParserPreloadTest: Remove unneeded unset calls
Change-Id: Ia21fac8232e79444ecfae47c1a53a81a08ef8395
2020-12-28 22:10:53 +00:00
jenkins-bot
eb38ad06c4 Merge "More misc test cleanup" 2020-12-28 17:43:21 +00:00
jenkins-bot
12e73d4beb Merge "Add tests for EditConstraintFactory" 2020-12-26 20:27:30 +00:00
DannyS712
7ef44935d8 Add tests for EditConstraintFactory
Bug: T157658
Change-Id: I175afe4d1217f9e57aaa8e8d8f93c70736dac801
2020-12-26 03:30:57 +00:00
DannyS712
e8b332eadb Bring SpamRegexConstraint test coverage to 100%
Bug: T157658
Change-Id: I89d08059937d2a84de0cbc53fd4ac56153018e40
2020-12-26 03:11:55 +00:00
C. Scott Ananian
6328600cdd MediaWikiIntegrationTestCase: use static:: for ::getTestSysop()/::getTestUser()
Also fix two places where we were using `$this->` in a corner case.

Using `static::` lets subclasses override these method definitions,
at least in theory.

Change-Id: I76a6d10ce463a5bc79e14051a31f469668924494
2020-12-24 09:52:54 -05:00
DannyS712
6a93b0ca93 More misc test cleanup
* parent::setUp() should be first, and ::tearDown()
  should be last
* Move tests that directly extend PHPUnit\Framework\TestCase
  to /unit

Change-Id: I1172855c58f4f52a8f624e6d596ec43beb8c93ff
2020-12-24 00:52:06 +00:00
C. Scott Ananian
71aa8e0e0d Add support for running parsertests with Parsoid in integrated mode
This allows us to move Parsoid-specific extension code from the
Parsoid repo into the extension's own repository and still have
Parsoid parser tests run on it via core's mechanism for running
extension tests.

Factored out some common ParserOptions setup into a common helper
function.  There are a number of features still missing from the
Parsoid test runner, which are marked with @todo comments and
phab task numbers.

Bug: T254181
Change-Id: Ifaf53862b96e9127d8f375ad8dd0cc362cba9f5b
2020-12-23 15:50:50 -05:00