Commit graph

189 commits

Author SHA1 Message Date
DannyS712
6fb338ae40 MediaHandlerFactory: inject a logger
Instead of using wfDebug
Also normalize the entries

Change-Id: Ie539233c8b95eaae370732f97681989821157299
2021-03-31 17:45:51 +00:00
DannyS712
fb4627b84b WfExpandUrlTest use yield for test cases
Instead of needing to store them all
in $retval

Change-Id: I1d42375931cfb0b7afbbb15c79ec3fca07caf047
2021-03-01 15:45:33 +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
f4e21014ce Deprecate a bunch of global functions
* wfAcceptToPrefs
* wfClearOutputBuffers
* wfConfiguredReadOnlyReason
* wfDebugMem
* wfGetPrecompiledData
* wfNegotiateType

Bug: T264976
Bug: T264979
Bug: T264981
Bug: T264983
Bug: T264984
Bug: T264985
Change-Id: Ia05bc84e4d1be7c8a02472f32e2c009e4bb32032
2020-12-18 21:34:50 +00:00
Tim Starling
6b2a52181f Don't access $wgRequest from User
Some User methods fail if they are called before $wgRequest is
set. But according to the Setup.php comment, it is only set for b/c.
The global request object can be lazy-initialised at any time.

This is sufficient to avoid T263911 (loss/obfuscation of the $wgServer
error message).

In tests, try to keep $wgRequest and RequestContext::$request in sync.
Introduce MediaWikiIntegrationTestCase::setRequest() which sets both at
once, and use that instead of setMwGlobals() or direct assignment.

BlockManagerTest was accidentally exploiting the fact that the global
context request and $wgRequest were separate objects. Making them the
same causes session cookies to appear in the response, breaking the
cookie counts. Use a new response for the test.

Bug: T263911
Bug: T245940
Change-Id: I2be99f7251a837bc6b62be0b152038157dec10f2
2020-12-16 12:21:00 +11:00
Aaron Schulz
d1d952473c Remove deprecated wfMemcKey() function
Bug: T266502
Change-Id: I1e4b20cc30fa3ef4671d8b80e660b2ac3f469d80
2020-11-23 16:57:06 -08:00
Aaron Schulz
369a953e85 Remove deprecated wfForeignMemcKey()
Bug: T250407
Change-Id: Ie9352d297382689a2fc2634e1160d7fe7b91e89b
2020-10-26 19:33:29 +00:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00
Reedy
567e1bbb5d Hard deprecate wfIsBadImage()
Bug: T249459
Depends-On: Iec58118198864704b1860aeb630476391e3a2c23
Change-Id: I939ded72427adc973739e7b376ea85cbf4b3e258
2020-06-09 19:27:16 +00:00
Reedy
dc5fc0301a wfIsBadImage: Remove deprecated $blacklist parameter
wfIsBadImage still used in Flow\Parsoid\Fixer\BadImageRemover

Bug: T254646
Change-Id: Ieb1ba83593da5c7789b9da5b6a931eedcd391bf3
2020-06-09 00:14:42 +00:00
Daimona Eaytoy
2b37cfaf18 build: Bump mediawiki-codesniffer to 31.0.0
Done with `composer fix` and suppressing the rest (i.e. sniffs for
global variables, which for core should be suppressed anyway).

Additionally, add `-p` to `phpcbf`, as otherwise it just seems stuck.

Change-Id: Ide8d6cdd083655891b6d654e78440fbda81ab2bc
2020-05-30 14:56:28 +00:00
Max Semenik
2a21e99633 GlobalFunctions: Fix wfPercent() with negative accuracy
Format strings like "%.-1f" have never been valid, however
while previously it would have resulted in output being "1f",
in PHP 8 it's an exception. The existing unit test failed because
(float)"1f" evaluates to 1, which was rounded down to an expected 0.
Adding another test case to make sure it can return anything other
than "0%" on PHP 7.

While I'm at it, fix wrong phpdoc and add parameter types to this
function.

Bug: T248925
Change-Id: I018bc17a563c58535f6c84644d707251ab19cd0a
2020-05-04 18:48:08 +03:00
Max Semenik
3781f4113b tests: Refactor GlobalTest to use a data provider
Change-Id: Iba800edd9ca35650f79b933db48eb8f95bd09f04
2020-05-01 17:02:27 +03:00
Umherirrender
3161311c5a Use MediaWikiServices::getMessageCache
Change-Id: I07fcc9529991adc634c10e5ed8498ac138a1c2b7
2020-03-14 14:25:03 +01:00
Timo Tijhof
f081a71f2c debug: Remove $wgDebugTimestamps feature
MediaWiki provides at least a dozen distinct ways that debug logs
can be generated, augmented and displayed, and even more ways
for profiling information can be collected. This makes it difficult
to reason about overall and isn't helping with on-boarding.

Reduce investments to only a few methods and make them great,
starting by removing possibly the least useful profiler we have
today (relative to the others we've developed since then),
which is the "relative timestamps and memory use" prepended
to wfDebug messages, which would presumably be used in conjuction
with $wgDebugComments, $wgDebugToolbar or $wgDebugLogFile of
which the latter two already includes timestamps and/or offsets.
If this is truly useful, I suggest we (unconditionally) make use
of offsets in (one of) those instead.

Originally introduced in r61582 (b1e2b87b95).

Change-Id: I09d1cb0d3f5b0b3165ed4d299b71c051b78a1918
2020-02-24 13:08:33 +00:00
James D. Forrester
5e9fca47b9 Coding style: Auto-fix MediaWiki.Usage.PHPUnit*
Change-Id: I86fc55a4fc8ceafe368692173211bbcd6d8581d7
2020-01-10 10:17:12 +00:00
DannyS712
24b11bc7d3 Remove wfGlobalCacheKey global function, deprecated and unused
Bug: T241350
Change-Id: Icdb2512f3ec10bc4b26a6faa08f14d7603176c82
2020-01-08 01:08:55 +00:00
Daimona Eaytoy
7b946ffb4b Fixes for PHPUnit 8 compat in DB suite
Once again, this fixes all issues aside from assertArraySubset.

Bug: T192167
Change-Id: I45c91dc1cf23f04140576dc66233558bb6021324
2019-12-15 00:27:54 +00:00
Brad Jorsch
489bb4fb98 Tests for an old PHP bug in parse_url
It would get confused by URLs with a query portion but no path.

We no longer support any vulnerable versions of PHP, but it would still
be useful to have these tests.

Bug: T212067
Change-Id: I15c15161a668115d68eb2e2f8004826b47148fc1
2019-12-13 11:24:52 -05:00
Max Semenik
48a323f702 tests: Add explicit return type void to setUp() and tearDown()
Bug: T192167
Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43
Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
2019-10-30 14:31:22 -07:00
Thiemo Kreuz
e4272518f7 tests: Replace PHPUnit's loose assertEquals(false) with assertFalse()
assertEquals( false, … ) still succeeds when the actual value is 0, null,
an empty string, even an empty array. All these should be reported as a
failure, I would argue.

Note this patch previously also touched assertSame( false ). I reverted
these. The only benefit would have been consistency within this codebase,
but there is no strict reason to prefer one over the other. assertFalse()
and assertSame( false ) are functionally identical.

Change-Id: Ic5f1c7d504e7249002d3184520012e03313137b4
2019-10-04 00:30:36 +00:00
Aryeh Gregor
7fb4a95563 Remove unneeded overrideMwServices/resetServices
Change-Id: If6cbdec05b8f310ef3a0b4649aaa16d9fb80a047
2019-08-29 14:26:18 +03:00
Aryeh Gregor
47464abb4f Call resetServices() when setting globals in tests
Now that resetServices() will preserve (but reset) customized services,
it should be reasonably safe to call it every time globals are changed,
and much more effective than relying on tests to call it every time
themselves.

Depends-On: Iab8ea3a61bbc6803805d855ef23c071067646f71
Depends-On: I00e35ecea6a27468674b2a6e7d9d9eb6518e3bd5
Change-Id: Ie7a89f6ed7d52a0bc01672019ff92e7ee105a1f3
2019-08-29 14:26:13 +03:00
Aryeh Gregor
5e2199c5b0 BadFileLookup to replace wfIsBadImage
I think this probably shouldn't be directly in the MediaWiki namespace,
but I don't know where is a better place to put it.

In order to avoid gratuitous use of TitleFormatter, I changed the cache
format -- the old implementation used getPrefixedDBkey() and I switched
to an ns/dbkey pair. I also changed the cache keys to use SHA1 instead
of MD5, by Daniel's request.

The previous implementation cached the parsed blacklist for one minute
without invalidation, so it could return slightly stale results, but it
didn't retrieve the bad image list message on a cache hit. The new
implementation unconditionally retrieves the bad image list message, but
uses a hash of it in the cache key and caches for one day. The new
behavior happens to be more cleanly implementable in a service.

Bug: T200882
Bug: T139216
Change-Id: I69fed1b1f3cfc1aa149e0739780e67f6de01609d
2019-08-21 20:45:37 +03:00
Aryeh Gregor
5600df580a Rewrite integration test for wfIsBadImage()
In preparation for rewriting as a service. I didn't figure out how to
get file redirects to be tested.

Change-Id: Ic6669a19a13025744036f9f8adc4d1a25490fb42
2019-08-21 20:45:37 +03:00
Derick Alangi
99cf057e0f GlobalFunctions: Hard deprecate wfGlobalCacheKey() function
The only extension that used this was ConfirmEdit and it has been
cleaned up with Ia7b276ee65fdf58c, so is it time we hard deprecate
it?

Usage
=====

https://codesearch.wmflabs.org/search/?q=%5CbwfGlobalCacheKey%5Cb&i=nope&files=&repos=

Depends-On: Ia7b276ee65fdf58c4fc0859563930528d44a03ca
Change-Id: I3fda797c64ec62df4454625ad1a3bf89f6a88246
2019-07-18 09:41:23 +01:00
Amir Sarabadani
06f645c453 Load GlobalFunctions.php to tests/phpunit/bootstrap.php
That mostly enables testing global functions

Bug: T87781
Change-Id: Ib42c56a67926ebcdba53f4c6c54a5bff98cb77a3
2019-07-14 01:28:07 +02:00
RazeSoldier
af5df424fc Skip ::testT69870() under Windows system
Anonymous pipe under Windows does not support asynchronous read and write[1],
and the default buffer is too small (~4K), the test will definitely block it.

Before T69870, anonymous pipe for Windows can no longer hold more than 4K of data.

[1] https://docs.microsoft.com/en-us/windows/desktop/ipc/anonymous-pipe-operations

Bug: T209159
Change-Id: Ie9de36b1e6b68db95c35a0044c5b0d86c0050d33
2019-06-22 19:59:27 +00:00
Fomafix
110a5877e9 Use [...] instead of array(...) in PHP comments and documentation
Change-Id: I0c83783051bf35fe785bc01644eeb2946902b6b2
2019-06-17 21:15:09 +02:00
Legoktm
4e35134f7a Revert "Separate MediaWiki unit and integration tests"
This reverts commit 0a2b996278.

Reason for revert: Broke postgres tests.

Change-Id: I27d8e0c807ad5f0748b9611a4f3df84cc213fbe1
2019-06-13 23:00:08 +00:00
Máté Szabó
0a2b996278 Separate MediaWiki unit and integration tests
This changeset implements T89432 and related tickets and is based on exploration
done at the Prague Hackathon. The goal is to identify tests in MediaWiki core
that can be run without having to install & configure MediaWiki and its dependencies,
and provide a way to execute these tests via the standard phpunit entry point,
allowing for faster development and integration with existing tooling like IDEs.

The initial set of tests that met these criteria were identified using the work Amir did in
I88822667693d9e00ac3d4639c87bc24e5083e5e8. These tests were then moved into a new subdirectory
under phpunit/ and organized into a separate test suite. The environment for this suite
is set up via a PHPUnit bootstrap file without a custom entry point.

You can execute these tests by running:
$ vendor/bin/phpunit -d memory_limit=512M -c tests/phpunit/unit-tests.xml

Bug: T89432
Bug: T87781
Bug: T84948
Change-Id: Iad01033a0548afd4d2a6f2c1ef6fcc9debf72c0d
2019-06-13 22:56:31 +02:00
Timo Tijhof
4938038175 tests: Remove use of wfRandomString() for test fixtures
This reduces confidence in the test. There is no guruantee that
it won't return the same value twice during the duration of a full
PHPUnit run of all test suites, whether twice in a row or 20 minutes
apart.

For a test that needs a string of any kind, use an explicit, consinstent
and cheap literal value.

For a test that specifically needs some kind of uniqueness compared to
something else within the same test case, do so explicitly.

Tests that require something globally unique (for some undefined/vague
definition of "global") were not found, and should not exist anyway.

Also, in libs/objectcache tests, fix order of parameters in some
assertions (expected first, then actual), and use assertFalse/assertSame
instead of assertEqual for cases where false is expected to remove
tolerance of other loosely equal values.

Change-Id: Ifc60e88178da471330b94bfbf12e2731d2efc77d
2019-05-06 17:22:03 +00:00
Derick Alangi
3d2750b89f GlobalFunctions: Remove usage of wfArrayFilter & wfArrayFilterByKey
These functions were hard deprecated in 1.32 and usage no longer exist
and seems to have been completely removed from all repos. See below;

Usage
=====

https://codesearch.wmflabs.org/search/?q=%5B%5E%3E%5D(wfArrayFilterByKey%5C(%7CwfArrayFilter%5C()&i=nope&files=&repos=

Bug: T42485
Change-Id: I28092eeb8dec058c5dba2fb63f3602249c137b31
2019-04-27 07:48:07 +01:00
Aryeh Gregor
9d5e3ad0f5 Drop clearCache() from (Configured)ReadOnlyMode
These are services, so tests should just override services to reset
them.

Change-Id: Icb1a041f8fac1ea0b7421e69b7b31b24171d868b
2019-04-10 19:39:34 +03:00
Brad Jorsch
d65e96b763 Use new externallinks.el_index_60 field
This adds a method to LinkFilter to build the query conditions necessary
to properly use it, and adjusts code to use it.

This also takes the opportunity to clean up the calculation of el_index:
IPs are handled more sensibly and IDNs are canonicalized.

Also weird edge cases for invalid hosts like "http://.example.com" and
corresponding searches like "http://*..example.com" are now handled more
regularly instead of being treated as if the extra dot were omitted,
while explicit specification of the DNS root like "http://example.com./"
is canonicalized to the usual implicit specification.

Note that this patch will break link searches for links where the host
is an IP or IDN until refreshExternallinksIndex.php is run.

Bug: T59176
Bug: T130482
Change-Id: I84d224ef23de22dfe179009ec3a11fd0e4b5f56d
2018-11-12 22:33:18 +00:00
Tim Starling
6d1ea3e057 Fix wfDebug() test so that it works with overridden SPI
Fix testDebugFunctionTest() so that it works when LocalSettings.php
sets $wgMWLoggerDefaultSpi

Change-Id: I5e573b0ce1ce037c3505d3b44d9710395c9af8d6
2018-08-31 15:02:38 +10:00
Fomafix
186c984ab6 tests: Replace Bugddddd with Tddddd in test names, test strings
Change-Id: Ic6fbc5e14b1a756f62dd6cc3a6b2acc0d47db498
2018-08-20 21:27:20 +00:00
Timo Tijhof
962770f14a GlobalFunctions: Enable patch-coverage for wfExpandUrl test
Change-Id: I3b4594dab0aba659cc47233f7be3da751066b7de
2018-07-25 18:25:27 +01:00
jenkins-bot
1655c86faf Merge "$wgHttpsPort should only be used in very special cases" 2018-07-24 01:13:32 +00:00
Max Semenik
9b0c621d7f Deprecate wfArrayFilter() and wfArrayFilterByKey()
Now that all our supported PHP versions have array_filter()
with a third parameter, these functions aren't needed anymore.

Depends-On: I3b097a1a048baabcaca15dc214a3a1bb06e746cc
Depends-On: I0187e27ac47cbab099249572201d1a649226a734
Change-Id: I7cabd0252691a083cb749cf9d3a7a23f1d076c39
2018-07-19 08:40:46 +02:00
Tim Starling
8962915449 $wgHttpsPort should only be used in very special cases
When expanding a URL, don't overwrite an explicitly specified port or
add a port to a foreign URL. $wgHttpsPort is only useful for a very
specific case: when $wgServer is protocol-relative and HTTPS is
requested.

Documented correct use of $wgHttpsPort in DefaultSettings.php. Fixed
invalid "@see", in Doxygen it can only point to "classes, functions,
methods, variables, files or URL".

Added test cases which previously failed.

Change-Id: Id65c58300d22712212b6605711ff916916e8768b
2018-07-11 12:31:48 +10:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Umherirrender
63d96c15fd build: Updating mediawiki/mediawiki-codesniffer to 16.0.0
Change-Id: I59b59f79bbf3ce4feff3b3a20c1c31bc16370531
2018-02-17 13:29:13 +01:00
Reedy
39f0f919c5 Update suppressWarning()/restoreWarning() calls
Bug: T182273
Change-Id: I9e1b628fe5949ca54258424c2e45b2fb6d491d0f
2018-02-10 08:50:12 +00:00
Timo Tijhof
7eb36a5249 tests: Add @group and @covers to wfArrayFilterTest
Change-Id: I6565ad21b6d6e78d876f730596e213555143c3fc
2018-01-31 12:14:02 -08:00
Kunal Mehta
0c77841534 Add @covers tags to miscellaneous tests
Change-Id: I7e65c1734aef01cd6395ee65204a0158d1635b0c
2017-12-24 23:29:00 -08:00
WMDE-Fisch
b94a2829d4 Get conflict results from diff3
This patch extends the global wfMerge function to also return the
result of the first merge attempt that detects merge conflicts.

The additional output explicitly names the conflicting lines and
could help when solving edit conflicts.

Bug: T151320
Change-Id: I97acebdc87b31779200c7fde4dd4449cd1ee8ead
2017-12-06 13:25:35 +01:00
Stanislav Malyshev
194acaa0e0 Expose string->bool conversion as function
There is code in several places in extensions which converts
setting or parameter string (such as "true", "yes", "false", "no")
to boolean. Since we already have the code that does in global
functions in wfStringToBool(), it makes sense to expose this code
and reuse it.

Change-Id: I88d98b012ff4bf14fd64a05a9135a6e75cf2d4e7
2017-11-15 06:57:40 +00:00
Fomafix
ea0bd74a94 Refactor global function wfBCP47 to static function LanguageCode::bcp47
Deprecate global function wfBCP47.

Change-Id: Ie6bb061b5d6ca67289bb18bc468a87421f38fc94
2017-10-05 09:54:45 +02:00
Umherirrender
86463f3df6 build: Updating mediawiki/mediawiki-codesniffer to 0.12.0
Change-Id: Iefaae5043fa77d5d556c31079549dab8f61bd3ef
2017-09-10 21:11:37 +02:00