Commit graph

92 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
Reedy
39f0f919c5 Update suppressWarning()/restoreWarning() calls
Bug: T182273
Change-Id: I9e1b628fe5949ca54258424c2e45b2fb6d491d0f
2018-02-10 08:50:12 +00: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
Umherirrender
b5cddfb27b Remove empty lines at begin of function, if, foreach, switch
Organize phpcs.xml a bit

Change-Id: Ifb767729b481b4b686e6d6444cf48b1f580cc478
2017-07-01 11:34:16 +00:00
Tim Starling
820f46964f A service for read-only mode
Introduce a service to represent wfReadOnly() and friends.

It's necessary to have two service instances, one for wfReadOnly() and
one for wfConfiguredReadOnlyReason(), to avoid a circular dependency,
since LoadBalancer needs the configured reason during construction, but
wfReadOnly() needs to query the currently active load balancer.

Not having a cache of the configuration makes it possible to dynamically
change the configuration. Ideally things would not change the
configuration, and I removed such instances in core, but to support
extensions, I added a test ensuring that the configuration can be changed.

Change-Id: I9bbee946c10742526d3423208efd68cb3cc5a7ee
2017-04-19 12:27:06 -07:00
aude
8443339411 Add missing @group Database tags in tests
Change-Id: Id92aab0b1f8cde6657d6558d0d82605109daa588
2017-03-18 19:13:18 -04:00
umherirrender
eac06f65ce Use more short array syntax in comments (/tests/)
Change-Id: I86c73cb9447ac562a73348b4030e24ebf49a90dc
2016-07-10 17:23:29 +02:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
addshore
96e1167d92 Give TestCase::checkHasDiff3 a better name
This method actually marks the test it is called
from as skipped if Diff3 is not confugured.

The new name "markTestSkippedIfNoDiff3" better
reflects that.

Change-Id: I1dffeba0aceb312b3a82216f0b55227e24bc2e34
2016-01-28 12:46:11 +01:00
Aaron Schulz
cb862afaf3 Rename getMainClusterInstance() -> getLocalClusterInstance()
Also corrected some ObjectCache docs

Change-Id: I322f4cbd72fbd5d4c6887d90ee75d0baddb6ac25
2015-10-20 00:26:21 +00:00
jenkins-bot
7436cd31a2 Merge "Add makeKey and makeGlobalKey to BagOStuff" 2015-10-17 01:06:12 +00:00
umherirrender
bbea9d5770 Remove empty comment line from GlobalTest.php
Remove empty line comments as found by the
MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.EmptyComment sniff

Change-Id: Ibd60165ae8ddef2a2fd443856e7476f32a0c6392
2015-10-14 12:14:23 +02:00
Ori Livneh
6916548490 Add makeKey and makeGlobalKey to BagOStuff
* Add a string `keyspace` member to BagOStuff instances. The default
  implementation, meant for simple key/value stores, treats the key space
  as a string prefix to prepend to keys. By default, its value is `local`,
  but any instance created via ObjectCache::newFromParams() (or or one of
  its callers) will have that default to $wgCachePrefix / wfWikiID().
* Add `makeKey` and `makeGlobalKey` methods to the base BagOStuff class.
  These methods are not static to allow for BagOStuff types which require
  a configured instance to know the underlying storage engine's key semantics.
* Make wfMemcKey() and wfGlobalCacheKey() delegate to these methods on the main
  ObjectCache instance.

Change-Id: Ib7fc2f939be3decfa97f66af8c2431c51039905f
2015-10-13 09:32:48 -04:00
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
umherirrender
271da88127 Some bugzilla.wikimedia.org -> phabricator.wikimedia.org changes
Changed some old bugzilla links to new phabricator links in comments,
test data and error message. This reduces the need for redirects from
old bugzilla to new phabricator from our source code.

Change-Id: Id98278e26ce31656295a23f3cadb536859c4caa5
2015-09-24 17:17:25 +02:00
Timo Tijhof
0f64b61271 Implement wfGlobalCacheKey() for database-agnostic keys
Some code paths abuse wfForeignMemcKey() for this purpose. This is semantically
incorrect and seems fragile. Also the empty second argument (for db-prefix) is
either misused or akwardly set to the empty string.

It also creates a namespace conflict between arbitrary application keys (from
the software) and any database names (from users). This commit reduces the
conflict surface down to a single key (namely, "global").

Also added unit tests to assert the implicit restrictions and
assumptions between these cache key functions are valid.

Change-Id: Ia0953b51005fe3de3b881dd1bd64c9d3c85e8c66
2015-06-23 07:52:18 +01:00
Kunal Mehta
f6e5079a69 Use mediawiki/at-ease library for suppressing warnings
wfSuppressWarnings() and wfRestoreWarnings() were split out into a
separate library. All usages in core were replaced with the new
functions, and the wf* global functions are marked as deprecated.

Additionally, some uses of @ were replaced due to composer's autoloader
being loaded even earlier.

Ie1234f8c12693408de9b94bf6f84480a90bd4f8e adds the library to
mediawiki/vendor.

Bug: T100923
Change-Id: I5c35079a0a656180852be0ae6b1262d40f6534c4
2015-06-11 18:49:29 +00:00
Kunal Mehta
dda1696b7f Remove unused "swap" global function
Deprecated in 26e1e083e8, unused since r12411.

Change-Id: If328f09114ac5a5d23a300d9b0bbcd7d67e051c8
2015-04-10 18:07:38 +01:00
Chad Horohoe
9eefeaed6d Remove unused alias/layer of test abstraction wfShellMaintenanceCmd()
Change-Id: I28d303f9b89ffad052d06eb2dbb9e6f8cfaeea24
2015-03-03 22:15:52 -08:00
Timo Tijhof
48d715148b Use MediaWikiTestCase methods for tempdir in unit tests
* Use MediaWikiTestCase::getNewTempFile and getNewTempDirectory
  instead of wfTempDir().

  The upload api tests wrote a tempnam() file directly (where
  wfTempDir() is typically shared with other systems and concurrent
  runs). Use MediaWikiTestCase::getNewTempFile and
  getNewTempDirectory instead.

  This also ensures its removal by the teardown handler without
  needing manual unlink() calls. And it doesn't rely on the test
  passing. (Many unlink calls where at the bottom of tests,
  which wouldn't be reached in case of failure).

* For the upload test, the presistent storing of
  'Oberaargletscher_from_Oberaar.jpg' (downloaded from Commons)
  was removed. Note that this didn't work for Jenkins builds anyway
  as Jenkins builds set $wgTmpDirectory to a unique directory
  in tmpfs associated with an individual build.

* For filebackend tests, moved directory creation from the dataProvider
  to the main test.

  Implemented addTmpFiles() to allow subclasses to register
  additional files (created by other means) to be cleaned up also.

  Removed unused $tmpName and $toPath parameters in data
  provider for FileBackendTest::testStore. And fixed weird double
  $op2 variable name to be called $op3.

* Skipped parserTest.inc, MockFileBackend.php, and
  UploadFromUrlTestSuite.php as those don't use MediaWikiTestCase.

Change-Id: Ic7feb06ef0c1006eb99485470a1a59419f972545
2015-02-11 03:49:02 +00:00
Bryan Davis
28a7ce420b Use MWLogger logging for legacy logging methods
Send wfDebug, wfDebugLog, wfLogDBError and wfLogDBError log messages to
the new MWLogger PSR-3 logger subsystem. Compatibility with the historic
logging operations of wfLogDBError are provided by MWLoggerLegacyLogger
and the MWLoggerLegacySpi logger factory.

Requires the MWLogger system introduced in I5c82299 and the Composer
managed libraries from Ie667944.

Change-Id: I1e5596d590144fbfdfd5f18bc42cf1ef0dbcac12
2014-10-29 11:55:08 -07:00
Sergio Santoro
6dc33107dc GlobalTest: Add test for wfRandomString()
Change-Id: I8e681ed6a32a4a13603cad3cd3dc56545e16220f
2014-09-03 16:28:16 +00:00
umherirrender
abfa0d7854 Standardize @todo
Always use lowercase @todo
Changed some "@FIXME" to "@todo FIXME: "

Change-Id: I016d1f9511e6f3bbd22427f0fffeccd77ab5e0db
2014-07-23 22:27:20 +02:00
Max Semenik
d28fd40189 Mark relevant tests with @group GlobalFunctions
Change-Id: I4133ad7e5e042a8c24d4836ae2bf9f1880a56e70
2014-07-20 23:36:10 +00:00
Kevin Israel
26e1e083e8 GlobalFunctions: Deprecate swap()
This unprefixed function, added in r7198 (2b3f4c749d3d), has been
unused since r12411 (f2a59db33f).

It is short and simple enough that on the rare occasions it is needed,
it can be inlined or copied into the calling class as a private method.

Alternatively, the idiom `list( $a, $b ) = array( $b, $a )` can be used.

Change-Id: Ieb4602597a54eb21a5de177fee6dafa7ac71ce1d
2014-06-18 02:31:03 +00:00
Siebrand Mazeland
437c84adbc Pass phpcs-strict on tests/phpunit/GlobalFunctions/
Change-Id: I2acc99ac96d8c738668fae2ecc9a0cee1b695f00
2014-04-24 11:47:06 +02:00
umherirrender
725d9d125d Removed unneeded spaces and colons in @param and friends
Also swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.

Change-Id: Ic36c8c7820a6c2d603f1138130670c6bf6a1ca59
2014-04-08 16:02:49 +00:00
ptarjan
40f6571312 Use lower memory limits
HHVM is ~5x more memory efficient than php-src and it shouldn't make us
fail this test

Change-Id: I35a69766c42818c222d36e1cf2a7fabe63a4ece5
2013-11-23 02:53:55 +05:30
umherirrender
5dbfd5bf80 Fixed spacing
- Removed trailing spaces in comments
- Removed multiple empty lines
- Removed space after object operator

Change-Id: I9fd3256ab490c7cd2034de3fd94e6be6e6d6d8f2
2013-11-21 18:52:25 +00:00
aude
02071ecb18 Fix covers tag in GlobalTest
Change-Id: Ia9e6f539e9b70e82c3fc0b352585650aa3ec5d7a
2013-11-16 16:01:47 +01:00