Commit graph

205 commits

Author SHA1 Message Date
Umherirrender
a89a00ffb8 tests: Migrate to IDatabase::newInsertQueryBuilder
Changed some inserts to use multi-row insert for small performance
benefit where possible and not already used.
InsertQueryBuilder does not return a value, deprecated since 1.33

Bug: T353219
Change-Id: I2380ebc8ec8db178dd790247aefbdd798b6d62ff
2024-04-14 21:56:07 +02:00
Derick Alangi
d372626b97
objectcache: Introduce ObjectCacheFactory MW service
ObjectCache is already doing a lot of factory pattern logic like
creating instances of the various BagOStuff, this should really be
the responsibility of the factory servicet.

This patch introduces a proper factory (ObjectCacheFactory) to handle
the responsibility of creating various instances of BagOStuff. Since
`newFromParams()` is a static function that gets passed in configuration
of $wgObjectCaches, that can stay that way (to keep supporting how we do
this in prod today).

Technical Breaking Change: `ObjectCache::makeLocalServerCache()` now has
a parameter and requires it but there are no callers of this method outside
MW core hence it is safe to change (and this patch update all callers) to
work correctly. Cache prefix is gotten from global state because sometimes
at this stage, the services container is not available.

Bug: T358346
Change-Id: I3179a387486377c6a575d173f39f82870c49c321
2024-03-19 12:38:39 +03:00
Gergő Tisza
93407f70eb session: Improve text and documentation of SessionManager warnings
Bug: T204787
Bug: T181869
Change-Id: Id180833a9ccf383ce7e0b650aa2fa9d6651d4ad1
2024-02-26 11:34:13 +00:00
jenkins-bot
9e1588e07f Merge "tests: Fix @covers and @coversDefaultClass to have leading \" 2024-02-16 23:25:14 +00:00
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
Reedy
c4527ef115 tests: More use statements in session tests
Change-Id: I562236f45c0fef5ad2b8fba5d3584b4ddd38a17a
2024-02-16 21:57:59 +00:00
Reedy
e94e265a93 tests: Add Tests to PHP namespacing
Change-Id: I849268172751d50292e93aa75abe8094873f56bc
2024-02-16 19:10:11 +00:00
Matěj Suchánek
45390a52eb Clean up tests
Replace strpos with str_contains, str_starts_with, etc.
Fix spelling of "cannot" and other typos.

Change-Id: Ie52900b323f46d1978a9dd9ea3b17619b8942160
2024-02-12 09:25:25 +01:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Amir Sarabadani
be5593b10d Migrate bot passwords to virtual domains
Bug: T351559
Change-Id: I645f1e4a4517b9177286e834236b0c047bef928c
2024-02-01 17:35:29 +01:00
jenkins-bot
7b1545b888 Merge "Allow setting page restrictions on BotPassword grants" 2023-12-15 06:04:00 +00:00
Umherirrender
e727a54cb1 tests: Skip failing tests on php8.3 (and make pass)
Change-Id: I2055d56a185c64b2ee1da6ab2e985b5a8f771352
2023-12-13 19:29:26 +00:00
Umherirrender
f559864d06 tests: Use TestingAccessWrapper::newFromClass in session tests
Some tests using ReflectionProperty::setValue(), which is deprecated for
static values in php8.3

Bug: T352910
Change-Id: I702cbf3de9c448d0a4e41fd06adc59d4074137cc
2023-12-06 21:01:03 +01:00
Siddharth VP
ce6bd364b9 Allow setting page restrictions on BotPassword grants
Helps bot operators adhere to the principle of least privileges.

Grants can now be restricted to allow editing (and other write
operations) for upto 25 listed pages. The page IDs are persisted within
the bp_restrictions field of bot_passwords table, and in the session
metadata.

This restriction is checked only as part of expensive checks in
PermissionManager, since they are not applicable for UI actions.

Bug: T349957
Change-Id: I3d228eb97664d040a160c5b742d9176fdfae9a43
2023-12-05 14:51:06 +05:30
jenkins-bot
49482c6744 Merge "Replace a few manually crafted assertTrue assertions" 2023-11-30 12:45:42 +00:00
Umherirrender
1bd11f1b57 tests: Avoid dynamic properties in SessionManagerTest
Use local variables instead.
Dynamic properties are deprecated in php8.2

Bug: T326478
Change-Id: If0ebf68a4a4ccd6dbe65c8f6ebd518455ee829bc
2023-11-27 21:35:25 +01:00
thiemowmde
37e4c52e00 Replace a few manually crafted assertTrue assertions
… replace them with the named convenience methods provided by
PHPUnit.

Change-Id: Ib46dbc3ab7926cf176477254f466b9bdd3be7c46
2023-11-23 09:38:48 +01:00
Amir Sarabadani
cd2e19c050 tests: Use $this->getDb() instead of wfGetDB() in integration tests
Deprecated long time ago.

Bug: T330641
Change-Id: Ia57f12d350c3346029aafae25534c9ed262a7e98
2023-09-25 21:08:09 +02:00
Amir Sarabadani
abbb4281cb tests: Migrate more cases to SQB
Bug: T344971
Change-Id: Ia69d82d6a6e623b9032240dc910fb47ff5887661
2023-09-21 18:30:37 +00:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
James D. Forrester
3851805f64 Namespace remaining User-related classes under \MediaWiki\User
Bug: T166010
Change-Id: Ibda1e8be0f23c6262a32b607f8260cad36f188fc
2023-09-20 09:12:08 +01:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01:00
Tim Starling
95bd40b25c In query builders, use insertInto() and deleteFrom() instead of insert() and delete()
The design principle for SelectQueryBuilder was to make the chained
builder calls look as much like SQL as possible, so that developers
could leverage their knowledge of SQL to understand what the query
builder is doing.

That's why SelectQueryBuilder::select() takes a list of fields, and by
the same principle, it makes sense for UpdateQueryBuilder::update() to
take a table. However with "insert" and "delete", the SQL designers
chose to add prepositions "into" and "from", and I think it makes sense
to follow that here.

In terms of natural language, we update a table, but we don't delete a
table, or insert a table. We delete rows from a table, or insert rows
into a table. The table is not the object of the verb.

So, add insertInto() as an alias for insert(), and add deleteFrom() as
an alias for delete(). Use the new methods in MW core callers where
PHPStorm knows the type.

Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
2023-09-08 10:16:08 +10:00
Amir Sarabadani
15a278189f Reorg: Move MWTimestamp to MediaWiki\Utils
Bug: T321882
Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
2023-08-19 05:53:40 +02:00
Daimona Eaytoy
c6bd1e842c Do not use UTSysop directly in tests
If the test expects the user to exist, it should use getTestSysop to
guarantee the account creation. Otherwise, use mocks or different
usernames to clarify that the username is not relevant to the test.

Change-Id: I87a27f01e1874af410e5d43e2e7fc3b10bb14eb8
2023-08-16 00:35:25 +00:00
Amir Sarabadani
974313663a Reorg: Move ProxyLookup to Request/
It's basically only used there.

Bug: T321882
Change-Id: Ibd9cac69772270b50152572ed618c692bbd5e4d9
2023-08-06 12:22:58 +02:00
Daimona Eaytoy
485e47ff10 tests: Avoid database usage when possible
We would like to remove DB access in non-database PHPUnit tests. As a
first step, avoid database usage in tested code when possible. In
particular:
- In NameTableStoreFactory, avoid domain ID normalization if the
  provided ID is already false.
- In SpecialDoubleRedirects, do not acquire a DB connection until it's
  needed (which is just one place).
- Use editPage() in TitleDefTest instead of a DIY implementation, and
  add `@group Database` accordingly.
- Avoid parsing titles in ContentHandler tests that don't need to parse
  titles. Among the many dependencies of parsing titles is the interwiki
  lookup, which requires DB access.
- Also remove test cases that used the "Gadget" namespace; it doesn't
  exist in core, so these pages were actually in the mainspace.
- Mock the database in CategoriesRdfTest. The only two methods that use
  the database were already being mocked.
- Add `@group Database` to test classes that are intentionally using the
  Database, mainly via getTestUser().

Bug: T155147
Change-Id: I9385fe14cfeb6b7b7378cc322d510034c4ee0711
2023-07-31 00:46:13 +00:00
Amir Sarabadani
614cd41507 tests: Migrate Database::delete calls to DeleteQueryBuilder
Bug: T340065
Change-Id: I92e85efd5d23d100a5df38aedb8edaecc5cbfc65
2023-07-14 14:48:42 +02:00
Umherirrender
1086958611 Replace array_keys in foreach to use $_ as value instead
When the value of the associated array is not used, there is no need to
use array_keys and create internal a copy of the array, just omit the
value with $_ to tell static analyzer that the var is unused.

Change-Id: I5c6d667e98c0167c0573c683f0d617bc1d4ca619
2023-07-10 02:53:52 +00: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
Umherirrender
580439e604 tests: Use MainConfigNames consts to refer config names
PasswordSalt was dropped in 2e909bcb

Change-Id: I58d2b8d4e2a235afdc8054eafdea4e85b61f03c1
2023-06-19 20:21:08 +00:00
thiemowmde
d47215586c Make use of MainConfigNames references in a few more places
Change-Id: I29499c29e7f8c6ca7627b130b1fe648e79100582
2023-04-21 11:11:44 +02:00
Tim Starling
be3018b268 Just another 80 or so PHPStorm inspection fixes (#4)
* Unnecessary regex modifier. I agree with this inspection which flags
  /s modifiers on regexes that don't use a dot.
* Property declared dynamically.
* Unused local variable. But it's acceptable for an unused local
  variable to take the return value of a method under test, when it is
  being tested for its side-effects. And it's acceptable for an unused
  local variable to document unused list expansion elements, or the
  nature of array keys in a foreach.

Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
2023-03-25 00:39:06 +00:00
Tim Starling
317b460500 Fix even more PHPStorm inspections (#3)
* Inappropriate @inheritDoc usage. Arguably all @inheritDoc is
  inappropriate but these are the ones PHPStorm flags as misleading
  due to the method not being inherited.
* Doc comment type does not match actual argument/return type.
* I replaced "@return void|never" with "@return void" since never means
  never, it doesn't make sense for it to be conditional. If a method
  can return (even if that is unlikely) then @return contains the type
  that it returns. "@return never" means that there is no such type
  because the method never returns.
* Incomplete/partial/broken doc tags

Change-Id: Ide86bd6d2b44387f37d234c2b059d6fbc42ec962
2023-03-25 00:30:15 +00: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
daniel
d19f30cede Tests: treat wgHooks like a regular config variable.
Prepare phpunit tests for a world where $wgHooks behaves like other
config variables: on-the-fly manipulation doesn't have an effect,
service objects need to be reset after changing it.

Change-Id: I34385f4c52febfe1c91bd7ea4100c06d1331adc8
2023-03-09 12:25:46 +11:00
Amir Sarabadani
bc1af1a53a Reorg: Move WebResponse and FauxResponse to Request/
Bug: T321882
Change-Id: Iae8b9e0170c67c1adf861a6d0da45178a7d3cca7
2023-03-01 18:18:11 +01:00
Umherirrender
a160240191 tests: Replace deprecated User::idFromName
Bug: T325687
Change-Id: I8319fc256f95c100aecbc31e24524f0208e3b0d5
2022-12-23 14:18:20 +00:00
jenkins-bot
f3b5f09e4c Merge "Make use of the ?? and ??= operators where it makes sense" 2022-12-16 01:06:50 +00:00
Reedy
0cb2c3c106 Fix casing of class and function name usages
Bug: T253628
Change-Id: I5c64f436d3cf757390b751ce3e34bfc7872bc176
2022-12-04 19:09:30 +00:00
Amir Sarabadani
02e5a33057 Drop more unused hard deprecated hooks
None are used in WMF-deployed extensions and have been hard deprecated
for multiple releases as well.

Change-Id: I62cfa22291f81295b4908192de8657a750c6716d
2022-12-01 03:36:48 +01:00
thiemowmde
0af1a51345 Make use of the ?? and ??= operators where it makes sense
?? is an older PHP 7.0 feature.
??= was added in PHP 7.4, which we can finally use.

Change-Id: I85921f1db9670987e173e905e8206bdf46659457
2022-11-10 18:31:18 +01:00
jenkins-bot
857a998f65 Merge "Reorg: Move some of request related classes to MediaWiki/Request" 2022-10-31 23:10:30 +00:00
Amir Sarabadani
bbe704b5c1 Reorg: Move some of request related classes to MediaWiki/Request
Redoing I5ea70120d74 but without moving WebRequest that caused issues
with phan-taint-plugin.

Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequestUpload

Bug: T321882
Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
2022-10-28 10:15:31 +00:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
Kevin Israel
1bcfc9f978 tests: Don't check if session_reset() exists in PHPSessionHandlerTest
This function was added in PHP 5.6.0, and MediaWiki no longer supports
older PHP versions.

Change-Id: I01a0246e7c26525f9f3ebd04a1911afda54efa8e
2022-10-24 01:23:12 -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
Gergő Tisza
35d3ffc648
BotPasswordSessionProviderTest: Do not set MW_API
Constants bleed over to other tests so setting them in tests is
fragile.

Change-Id: I0a09e90ea95821260c420cf8a763b71a385727d4
2022-09-23 14:28:14 +02:00