Commit graph

146 commits

Author SHA1 Message Date
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
Bartosz Dziewoński
4aebcfe097 Change more uses of getDBLoadBalancerFactory() to getConnectionProvider()
Some less trivial cases. Also update variable names.

This doesn't really change anything, but I hope it helps promote
getConnectionProvider() as the common way to do this.

Follow-up to 8604c384f6.

Change-Id: I6657d783375fac5c7fa856b884ff1fb09285e94c
2024-01-23 16:34:45 +01:00
Amir Sarabadani
f5abfb8d58 Bump codesniffer to 42.0.0
Most noisily, this enables MediaWiki.Arrays.OneSpaceInlineArray.

Change-Id: I8ab11399c67ce7e3ab1b6249b591452774393428
2023-09-27 15:06:32 -04:00
James D. Forrester
b16be7a36c Namespace TitleFormatter under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: Ic2d59eb6764b1a273ed7162ecabf641f638b8f66
2023-09-19 05:17:18 +00:00
James D. Forrester
94ece673b2 Namespace TitleValue under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: I4c901d5c32696d8334ec30cede7d9b6f3d8d645e
2023-09-18 18:24:39 +01:00
Derick Alangi
03b4f7e1ee
BacklinkCacheTest: Fix test case to avoid slowness
Calling `count()` in a for loop is terrible as the no. of elements in
the array gets recomputed every time. Instead, just call it once and
use the variable to avoid slowness of tests. We shouldn't put more load
on CI to make it slower :D

Change-Id: I9b94bda646e8d922e1f91c9d83d16370caaf8fbd
2023-08-10 14:22:22 +01:00
Derick Alangi
693b8c5987
cache: Remove deprecated methods from BacklinkCache
BacklinkCache::get(), ::getLinks(), ::getCascadeProtectedLinks()
have been removed from core. No longer used.

Change-Id: I84d743719e08c755dc98777ecf6d6d1e92eb2d2b
2023-08-10 14:21:23 +01:00
Lucas Werkmeister
7b8859c70c language: Move tests from /cache to /language
The classes were already moved in change I62c701d574 (commit
051e127bdb).

Ideally, the tests should have a namespace, but the other tests in
/language are also unnamespaced, so let’s not do that yet.

Change-Id: Ieef8728a1f474ce6b16fa534c9697e1e89a4a36d
2023-07-28 15:23:06 +02:00
daniel
c4033734db HookContainer: deprecate old hook handler formats
This reduces the acceptable forms for hook handlers to three things:
* a callable (in the form of a string, an array, or a closure)
* an object, which is expected to have a public "on" method that
  matches the hook name.
* an array containing an object spec in the "handler" key, for use
  with ExtensionRegistry.

All other forms will trigger a deprecation warning.

Bug: T339167
Depends-On: I980f2d45e6bb8c6a04058e68c758f71bbcf709de
Depends-On: Ieae405f70caa01d84602583cc214b0ee3fadc796
Depends-On: If15df4b598c02ed9bda5eea0ae89a16ebbf4f2e2
Depends-On: Id70276fa1e1821bd400dc0ae5cea722a21d524d5
Change-Id: I83bc81d1b3033c38b9313884a9c70a187fdde227
2023-06-21 11:40:10 +00:00
Func
bfd4001c6c LocalisationCache: Preserve fallback source language info
Prefix messages with their source language code when saving to the cache.

Bug: T229992
Change-Id: I06ae6432c80ffeb924b2a3ac29ad2e876b715b33
2023-06-14 22:06:36 +08:00
Amir Sarabadani
d44c45c76a watcheditem: Switch out of LB for picking db connection
A bit of a clean up. Switching out of lbFactory to ICP is not possible
at the moment because there is $this->lbFactory->getLocalDomainID()
for cache prefix. Fixable later.

Bug: T330641
Change-Id: I2d4537f75f5877552c6d9fd2b76c5be1959ea400
2023-05-05 15:42:10 +02:00
Umherirrender
19488997a2 Remove fallback to MediaWikiServices in LinkBatch::__construct
Bug: T325591
Change-Id: I52fe37b4c6d7b7d4ba7ccbc362413a996161156b
2023-04-19 23:52:49 +02:00
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00
jenkins-bot
92bafcb73e Merge "Hard-deprecate manual construction of LinkBatch objects" 2023-03-10 17:00:06 +00:00
Umherirrender
9e0c40424c Hard-deprecate manual construction of LinkBatch objects
Bug: T325591
Change-Id: I4f267b052e98cbb36cb76dae59a5279b01eae97c
2023-03-08 20:43:01 +01:00
Timo Tijhof
39ead04e98 objectcache: Remove $wgMainWANCache and $wgWANObjectCaches
We always wrap the local cluster cache, and there are no subclasses
of WANObjectCache. It was never documented or recommended how these
would be used. It is a left-over from the original 2015 Multi-DC plan
in which WANObjectCache would work differently. See task for details.

Note that this requires no configuration changes, even in the
theoretical case of these variables being used, as the only
option is to use the main cache, and that's also the default.

* Update WAN overrides to override the underlying main cache
  instead.
* Fix EditPageTest which was previously implicitly using a 'hash'
  as main cache but also relying on wan cache to be 'none'.
  The part that it actually needs is the 'none'. When WAN cache is
  enabled, testUpdateNoMinor fails due to an edit conflict because
  one of the edits it makes is made with a current timestamp whereas
  it expects to simulate wpEdittime in the year 2012 which, when
  caching is enabled, is ignored and becomes the current time instead.
  I don't understand exactly why, but I'm going to conserve that
  behaviour for now.
* Fix TemplateCategoriesTest, which was failing due to an unexpected
  cache hit:
  > [objectcache] fetchOrRegenerate(…:page:10:…): volatile hit
  This could be solved in a more realistic way by splitting the test,
  or by explicitly resetting services half-way the test to clear
  WikiPageFactory, PageStore and WANCache process state.
  For now, keep the prior behaviour of no cache in this test.

Bug: T305093
Bug: T329680
Depends-On: If890622eed0d0f8b4bd73d36ba1815a3d760ea05
Depends-On: Ie1def75208822bdf19bb2cfd7e6edf32c2000e6b
Depends-On: I35cce61dc3ee90dcee3dd6f0b36f84133be029ed
Change-Id: I53781a8c06ebb2583f6ca83dd91bbfe8a5c88b13
2023-03-07 22:47:04 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
DannyS712
a5293c323a Tests: add LanguageNameUtils to DummyServicesTrait
Returns a real LanguageNameUtils object configured as needed.

Change-Id: I50a8c6bc15665c454642a513f6669191456a3939
2023-02-02 20:50:48 +00:00
Umherirrender
2515199b2f Hard-deprecate BacklinkCache::get/getLinks/getCascadeProtectedLinks
Depends-On: I39a532bcce35191db6abe4fdcdd6f95df74e5e87
Depends-On: I4c8bcec6bb2396b31a7cc73cb7f6f83742dc001a
Change-Id: I09d0aae2400d3b70d8ad59df4e47ee23d3f5072b
2022-12-15 10:51:44 +00:00
Matěj Suchánek
501a16eb18 Hard-deprecate BacklinkCache::get
It has been deprecated since 1.37 and it is unused.

Change-Id: I8b588073f1d22846a8564e340e019de45e7566a3
2022-11-20 20:32:11 +01:00
Matěj Suchánek
884efbe0e3 Remove WikiRevision::downloadSource
It has been deprecated since 1.31 and it is unused.

Change-Id: I695e7f5d253076829ba9b58bccd7bfc77624c393
2022-11-04 09:24:15 -04:00
Timo Tijhof
1cf6f04768 objectcache: Remove WANObjectCacheReaper feature
Introduced in 2017 with I7f14b9ca2533032 (2e5eb693) but remains
unused at WMF, and disabled by default.

Follows-up I62107789fa (9e49260fc9) which added reap to LinkCache
test cases in 2021.

Change-Id: I0654c29a671467dd6b366f462d1c09b90a273413
2022-10-25 23:09:39 +01:00
Umherirrender
89b2d11a0d tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Ie240eb42479d19714e64cc4606e26073fadc2e13
2022-09-23 21:53:11 +02:00
jenkins-bot
aafa2e0b04 Merge "tests: Replace deprecated WikiPage::factory" 2022-09-09 16:25:08 +00:00
Amir Sarabadani
6c4194e23e schema: Drop tl_title and tl_namespace fields from templatelinks
The day has gone. Still keeping the code as the schema changes are not
done in production but the data migration has been finished.

Bug: T299417
Change-Id: I906e069a63d1dae14924c72318b22b16244371d6
2022-09-06 19:53:15 +02:00
Umherirrender
6555923b08 tests: Replace deprecated WikiPage::factory
Bug: T297688
Change-Id: Ic84d491c5603f3590e26cb56a305508b2b0ca109
2022-09-02 19:34:02 +00:00
Thiemo Kreuz
9e6e3f8d08 Inline a few more trivial createMock() calls in tests
createMock() is still relatively new. This code was using more
complicated mock builders before. This was changed just recently.
createMock() is now so short, the extra helper methods don't make
the code more readable, I would argue.

Change-Id: Ia7e24827157d5f49fc7da102418c79ae33c8e053
2022-08-08 09:50:50 +02:00
Derick Alangi
6e5f2d0822 tests: Migrate setMwGlobals() to overrideConfigValue(s)()
Directories covered are:
- tests/phpunit/includes/cache/
- tests/phpunit/includes/changes/
- tests/phpunit/includes/changetags/
- tests/phpunit/includes/config/
- tests/phpunit/includes/content/
- tests/phpunit/includes/debug/
- tests/phpunit/includes/deferred/
- tests/phpunit/includes/diff/

Change-Id: I3a1f586867db7d57b177e13a03a4593f7eed09f4
2022-07-23 05:53:49 +01:00
Thiemo Kreuz
3703b30618 Tests: Use createNoOpMock() shortcut in a few more places
… instead of doing the same manually with anythingBut() and such.

Change-Id: Idb66040d1560a82df9a5bfa2a6c7e20a0649e49c
2022-07-18 21:25:31 +00:00
jenkins-bot
3fc9cf4f51 Merge "Add support for write new for templatelinks migration" 2022-07-12 14:17:52 +00:00
Amir Sarabadani
692dde00df Add support for write new for templatelinks migration
- schema change to allow tl_namespace and tl_title being empty
   This is done by removing them from primary key. They don't need to be
   nullable as they have default value.
 - Make sure with WRITE_NEW, updater avoids writing to the old columns

Bug: T306674
Change-Id: I2b8a29043e952060e7a79b6a7a3d647d48cd16fb
2022-07-12 14:46:54 +02:00
Umherirrender
047c184bfe tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Ibfccfe696f0b8bfda0b99abae324e60bbecef7d8
2022-07-06 00:44:00 +02:00
Umherirrender
8b1a3d13eb tests: Use WikiPageFactory to create WikiPage object
Bug: T259948
Change-Id: I9afcf3b845306f81ee5ca156553256e6c38df3a0
2022-06-26 23:21:02 +02:00
Reedy
41c42d5435 Tests: Cleanup some unnecessary nested function calls
Replace ->will( ->return with ->willReturn(

Change-Id: Ia2dfafa03cac8169d86d6fa5a30b73bfad1fe9fa
2022-06-06 01:02:34 +01:00
jenkins-bot
0e08a27e03 Merge "Use injection for LinksMigration on LinkBatch, action, api, special page" 2022-05-11 05:48:30 +00:00
Umherirrender
d79fd02d4b Use injection for LinksMigration on LinkBatch, action, api, special page
Even the service does not long stay in that classes,
it should be injected to avoid global state

Bug: T304780
Change-Id: Ib488037f5a6966ab61042ed3cd889ddc50f1ba8e
2022-05-10 20:19:58 +00:00
Amir Sarabadani
30aa4679c0 Remove references to legacy page_restrictions field in page table
Bug: T218446
Change-Id: I4d45de0890b96e00d4b24fc96ceffbf336928bc2
2022-05-09 11:20:53 +02: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
Func
7f74a2e50c Clean up tests that misused the parameters of assertSame/Equals
Expected value is the first parameter to assertSame() or assertEquals().
And turn to use assertCount() for some assertions aginst count of array.

Based on code search `assert(?:Same|Equals)\(.+,.+expected` and I look
through files roughly, so some assertions that don't contains 'expected'
are also fixed. In the meantime, some assertions that I am not clear
about are not touched.

Change-Id: I75798b60d29fd19b33f4fdf34ed3c788db420d01
2022-02-08 07:21:10 +00:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Taavi Väänänen
de3a7ef3b9
MessageCacheTest: remove sunday from tested words
The remaining test cases (MessageCacheTest-*) should already test
everything that testing for sunday does. This change is to ensure that
changes to the translation strings made on translatewiki do not cause
unnecessary test failures.

Bug: T298392
Change-Id: Ie9632da6eee505ab77108b74aa126e479d99be4f
2021-12-30 15:07:22 +02:00
Amir Sarabadani
ec074a6a27 cache: Add four fields to LinkCache::getSelectFields
These are needed PageStoreRecord::REQUIRED_FIELDS and that's why putting
PageStore on top of LinkCache caused a lot of increase in db reads.

Bug: T297669
Change-Id: If77c2f9879d7bae71eb59944efd8b3798d16aa46
2021-12-14 15:10:49 +01:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00:00
Martin Urbanec
b406c52adb LinkCache: Try invalidating cache before throwing
The code that was previously in LinkCache::getGoodLinkRow
may return a cached row object (either from the in-process
cache, or memcached). In some cases, this caused
LinkCache::addGoodLinkObjFromRow to throw, because a field
was missing (although the field is missing only from
the cached copy, not from the database).

To avoid this, try to invalidate the cache
in LinkCache::getGoodLinkRow and retry, before
letting the exception propagate.

Bug: T205349
Change-Id: Ie9e90bf32964047c1831f575cc260d7d62e9e848
2021-11-02 13:10:45 +00:00
Derick Alangi
d62ba36bba Use PageUpdater's fluent interface
Change-Id: I541b7ae565c46d00ab5e1de08a2447461a9e73a7
2021-10-05 07:18:17 +01:00
Alexander Vorwerk
04dfdc3653 Hard deprecate User::setOption()
deprecated since 1.35

Bug: T277818
Change-Id: Ic251d624e5d6fa857aa92f9c5dd3df44714ac610
2021-09-26 17:18:54 +02:00
Derick Alangi
2432cc2bb4 Use PageUpdater's fluent interface as in some parts of our codebase
Some methods in the PageUpdater's class implements the fluent interface
design pattern. Use the fluent interface where need be.

Change-Id: If76a4b8c5070c20ed40038a4ee78e2d677de5180
2021-09-23 00:31:33 +01:00
jenkins-bot
5a53d57449 Merge "LinkCache: soft deprecate addGoodLinkObj()" 2021-09-10 17:22:02 +00:00
jenkins-bot
7ece0e7afd Merge "Title: Make use of BacklinkCacheFactory service" 2021-09-10 14:31:23 +00:00
daniel
855988fd0e LinkCache: soft deprecate addGoodLinkObj()
addGoodLinkObj() has many optional arguments, but omitting them actually
means corrupting the cache.

Nearly all existing callers are in tests.
So LinkCacheTestTrait::addGoodLinkObject() was created only
for testing. It is better to have this method in the
trait, because building the row directly in each test
would make these tests brittle against schema changes.

The only usage in WMF production code was in WikiPage and has been
fixed.

Bug: T284955
Change-Id: I03a2bd9ed64fcc0281ee29a286c8db395a9e03d9
2021-09-10 16:00:02 +02:00