Commit graph

132 commits

Author SHA1 Message Date
Umherirrender
eef1ff2556 logging: Hard-deprecate LogFormatter::newFromRow/newFromEntry
Depends-On: Icd3316b7f475a09390be8787fae6a8b63dcd6418
Depends-On: I007a318135db35fc82011540b3b2baf6f358b753
Change-Id: Id2c48651e1ca28146ab6bcb57c789fae69e5c251
2024-07-29 20:29:25 +00:00
Umherirrender
07db7102cc Replace deprecated LogFormatter::newFromRow/newFromEntry
Change-Id: I453ce3148a46fcb9cc5c685cee92274e0cb4f98a
2024-07-29 22:26:41 +02:00
jenkins-bot
1a4278e1e8 Merge "Drop duplicate test cases and @dataProviders from tests" 2024-07-21 04:06:33 +00:00
thiemowmde
32d214dd6d Drop duplicate test cases and @dataProviders from tests
A single test function can have multiple @dataProviders. No problem.

A @dataProvider can also be used by multiple test functions. No
problem. No need to duplicate such large pieces of code when it's
identical anyway.

Change-Id: I5aea36304ec2d1666ff2334ba883df07a70c15c5
2024-07-19 10:18:31 +00:00
Lucas Werkmeister
fb760c66c5 MoveLogFormatter::getPreloadTitles: Handle bad titles
If the namespace configuration changed, it’s possible that the title in
the params can no longer be parsed. In that case, we shouldn’t return a
null entry, but just an empty array instead. (I haven’t tried it out
locally, but the test suggests that the actual formatting of the row
works without issue, with the title being shown as Special:BadTitle.)

Bug: T370396
Change-Id: I6335e12efa518332f7cd2268a833f8b60b8e6abe
2024-07-18 11:49:33 +02:00
Umherirrender
6c41df61e9 tests: Use namespaced classes (1)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Iae45fa269363be8ee05c598ea6926514ce817762
2024-06-14 17:19:36 +00:00
Ebrahim Byagowi
d83cb5924f Add namespace and deprecation alias to IRCColourfulRCFeedFormatter
This patch introduces a namespace declaration for the
MediaWiki\RCFeed to IRCColourfulRCFeedFormatter and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I78061ed136208f974e864a9622264409979ba120
2024-05-17 16:00:04 +03:30
DannyS712
ee75e1c6f9 Tests: remove a bunch of DummyServicesTrait-related comments
Not sure why I added these, it should be clear from the method names

Change-Id: Ie49881e6f31fad52bb65b0d2ac3e9379dbb7bfc5
2024-05-10 04:07:59 +00:00
Máté Szabó
4920e1a71e PageStore: Migrate to StatsLib
Use StatsFactory for emitting metrics from PageStore and add assertions
for the new metrics.

Bug: T359374
Change-Id: Id099f54eb79a2dce078259cf9c13e548c1ec56f2
2024-05-05 15:36:33 +02:00
jenkins-bot
c8dde14616 Merge "tests: Don't depend on Message implementation details" 2024-04-04 20:25:43 +00:00
Bartosz Dziewoński
20524dde2c tests: Don't depend on Message implementation details
You're not really supposed to know how Message represents the
parameters internally.

Change-Id: Idb554f91aded1402b34932fddcb77beaa1dca0d5
2024-04-02 23:21:16 +00:00
Bartosz Dziewoński
0b0ebabea2 LogFormatterFactory: Inject LinkRenderer too
Change-Id: I1edfc9cc4e2ad794b226b4f8be03c3846bbeb84d
2024-04-02 21:24:49 +02:00
Umherirrender
3e6a1bdd00 logging: Inject services into PageLangLogFormatter
Bug: T356468
Change-Id: I593fbd8c340aa9ea75a303115d1355f3ce96be11
2024-03-28 01:32:02 +00:00
James D. Forrester
35b2542895 Namespace includes/cache
Bug: T353458
Change-Id: Ic3f3168ef17113f5fb3ec11e0a47f52d65eefba9
2024-02-20 10:28:03 -05:00
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
jenkins-bot
ba409888a1 Merge "Clean up tests" 2024-02-16 07:58:38 +00:00
Derick Alangi
3bcd9afa01
logging: Fix LogFormatterTestCase from throwing with CheckUser
`CheckUserPrivateEventLogFormatterTest::testLogDatabaseRows()` calls
`LogFormatterTestCase::doTestLogFormatter()` which overrides UserFactory
with a mock which will eventually call `BlockManager::getBlock()` which
tries to create a legacy user object with `newFromUserIdentity()`, but
the overriden UserFactory mock doesn't mock the method `newFromUserIdentity()`,
so will return a NULL user object.

With the NULL user object returned above and CentralAuth enabled, the
`onGetUserBlock()` hook in CA will fire and try to act on a NULL user object
causing the `CentralAuthUser::getInstanceByName()` method in I2c7b4ceb56463e88
to throw as if we're dealing with a user object having an invalid username.

In order to fix this, this patch also mocks the `newFromUserIdentity()` method
in the mocked UserFactory service that gets overridden in test. As a result,
with this patch, the failing tests in CheckUser extension should begin
passing again.

Bug: T343963
Change-Id: I11937d0d53b3914d7f6bd1483404a04b74ac26c9
2024-02-15 16:59:55 +03: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
Pppery
876e9883aa Allow MergeHistory to split up joined revisions with same timestamp
Bug: T183501
Change-Id: Iedd818a83838683fb07334aade11754557828062
2024-01-05 23:09:15 +00:00
Umherirrender
388b0374fa tests: Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: Ib326ae1e5c8409a98398c721e8b8ce42c73bd012
2023-12-11 15:59:55 +01:00
Tim Starling
d6727856fd Support new block schema
Support migration stages when reading and writing blocks.

I tried to set it up for an easy next stage, in which support for the
old schema is removed. I tried to avoid factoring out of shared code
between the two schemas, so that the old schema cases can simply be
deleted without the need to revert unnecessary abstractions.

However, I added HideUserUtils to factor out ipb_deleted queries. Code
review showed that this was already quite complex, with multiple
approaches to the problem, so it benefits from refactoring even without
the schema abstraction.

HideUserUtils is a service rather than a standalone class to support
unit tests, since unit tests do not allow global config access. When
the migration stage config is removed, it will be a service with no
constructor parameters -- an unnecessary abstraction which should
ideally be resolved at that time.

When interpreting result rows, it is possible to share code by using
field aliases. But when constructing WHERE conditions, the actual field
names need to be used, so the migration is more intrusive in
ApiQueryBlocks and SpecialBlockList, where complex conditions are used.

Bug: T346293
Bug: T51504
Bug: T349883
Change-Id: I408acf7a57b0100fe18c455fc13141277a598925
2023-11-29 13:31:42 +11:00
Dreamy Jazz
3d98381fff Use IReadableDatabase over IDatabase in DatabaseLogEntry::newFromId
Why:
* The DatabaseLogEntry::newFromId method only uses the provided DB
  for SELECT queries (via the DatabaseLogEntry
  ::newSelectQueryBuilder method).
* The DatabaseLogEntry::newSelectQueryBuilder method takes a
  IReadableDatabase object and this is the only usage of the DB
  provided to ::newFromId
* As such, the ::newFromId type should be IReadableDatabase
  instead of IDatabase so that callers who only have a readable
  database connection can still use this method.

What:
* Change the type of the $db parameter of DatabaseLogEntry
  ::newFromId to be a IReadableDatabase instead of an IDatabase.
* Update RCDatabaseLogEntry::newFromId to reflect the change
  in parameter type.
* Update the associated tests to use a IReadableDatabase.

Change-Id: Idc6c13b147a5ff99d0969c1120eb1deb2d111496
2023-10-11 00:25:45 +01:00
Amir Sarabadani
c00148768c Introduce LoggingSelectQueryBuilder
To replace DatabaseLogEntry::getSelectQueryData()

Many migrations can't happen right now because of use of
ChangeTagsStore::modifyDisplayQuery() but I will fix that soon.

Bug: T344971
Change-Id: Iafb2bb5ea3a0da49da1dafb69b65dea3c15029ed
2023-09-25 15:51:24 +02:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +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
James D. Forrester
459cbb0494 Namespace remaining 'specialpage' files under \MediaWiki\SpecialPage
SpecialPageFactory is already here, but none of the others were yet.

Bug: T166010
Change-Id: I9689bf0a1ab329625e23669b99f019b96295fffd
2023-09-18 18:23:13 +01:00
Umherirrender
d7f959e528 tests: Use namespaced Wikimedia\Rdbms\IDatabase
Bug: T344536
Change-Id: I29c80fe2ac3effd5e9df4402c598dc33c1b23d5e
2023-08-20 15:18:57 +02:00
Daimona Eaytoy
1cb036c392 Avoid DB access in more non-Database tests
Bug: T155147
Change-Id: Iae2512c66c32b209ea8579beecb3de94a744da14
2023-08-06 16:07:27 +00:00
Daimona Eaytoy
6b1a62e169 Fix more non-database tests accessing the database
Mock the needed services, or set fixed values to avoid DB lookups, when
possible. Add the test to the Database group otherwise, e.g. for things
like Skin and Parser that use global state all over the place.

Change-Id: I8d87013d89accaf04d0ac19cb4b7216290383eb5
2023-08-06 15:30:41 +00:00
Daimona Eaytoy
0310a6b3e9 Mock UserFactory::newAnonymous in LogFormatterTestCase
Bug: T343491
Change-Id: I07d6fab04db2fbb770e50f19795d1e3f49ab09db
2023-08-04 01:50:20 +02:00
Daimona Eaytoy
db8897dbe7 LogFormatterTestCase: avoid database access
LogFormatter is another place that uses the global state a lot, with
Title, Linker, etc. Some of its dependencies were accessing the
database, but most LogFormatter methods are not in the database group.

This patch tries to work around the DB dependencies by providing
(complex) mocks that do not access the DB. There's a lot of mocking
involved, but that's just because of the current state of LogFormatter,
and hopefully it'll get better some day.

Rights- and ProtectLogFormatter also need a mock DB connection because
they use the database to format expiry.

Bug: T155147
Change-Id: I4fa9ee4fb246e08cb2b4577454029b5af3276b79
2023-08-01 16:35:20 +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
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
jenkins-bot
95edc4e452 Merge "logging: Add class for suppressed items on Special:Log" 2023-02-06 23:15:47 +00:00
Umherirrender
8585fa9f12 logging: Add class for suppressed items on Special:Log
Similiar to the handling for suppressed edits since b6f148b

Bug: T327538
Follow-Up: I08f14f712479e1b170c606e2b64857f8386acd76
Change-Id: Icfb46d9ef02984510ef1c2c5e4785345cbe6ad2f
2023-01-20 18:45:45 +00:00
jenkins-bot
64c6ce7b95 Merge "tests: Expand test for LogFormatter::getPerformerElement/Comment" 2023-01-20 15:59:59 +00:00
Umherirrender
abf2ea44e8 tests: Handle dynamic created properties on test classes
- Declare missing properties
- Remove unused or avoid set of properties
- Add AllowDynamicProperties

Bug: T314099
Change-Id: Ie631894f2ffbb616f6dd09851405d681f3eb8fcd
2023-01-13 21:03:42 +00:00
Umherirrender
0bcfd1db54 tests: Expand test for LogFormatter::getPerformerElement/Comment
Test the revision deleted part of both functions

Change-Id: I980b39d1e458808e6a6ea9b44e574f9637c67ba4
2023-01-11 00:47:08 +01:00
Umherirrender
f65e6bb488 Replace deprecated Linker::commentBlock/revComment
Bug: T324906
Change-Id: I8cf96c3b7a03127ce1243f7a7e849b6d5a5d3dfa
2022-12-11 01:33:56 +01:00
Amir Sarabadani
2d60ba0c63 Reorg: Move DummyLinker and Linker to linker/
This feels like a no-brainer unless I'm missing something obvious

Bug: T321882
Change-Id: Id49c3d0dd6ea4593211048850856b5b8e05a8fb3
2022-12-08 06:38:17 +01:00
daniel
8e0ae53482 PHPUnit: introduce clearHooks() method.
Since the introduction of the new hooks stystem, it is not possible to
clear all hooks by setting $wgHooks. This would only clear old-style
hooks. This is becoming increasingly problematic as the new hooks system
is adopted by more and more extensions.

Introduce a method that allows tests to reset many or all hooks.
This isn't needed much in core, but extension tests need it.

Change-Id: Ica3eb88fe23fe822d2aadb96ff5d15f80dce0d7b
2022-11-03 13:40:42 +01:00
Derick Alangi
b6b335b183 tests: Migrate MediaWiki settings to overrideConfig...()
Also, make use of MainConfigNames constants where necessary like in
HashConfig map.

NOTE: Since `wgConf` is not a setting, keep using `setMwGlobals()`
  in this case.

Change-Id: I8d0c718fd02043835fe122d675cce3d759b30330
2022-08-18 17:48:03 +01:00
Derick Alangi
175832a8e9 Migrate usage of setMwGlobals() to overrideConfigValue(s)
Change-Id: I49d97864d8f9d8cadf01b0c0dc653fbac4ca9e94
2022-08-01 06:16:22 +01: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
EpicPupper
6abc28230b Unify how the term "undelete" is used in the undelete UI
Amend DeleteLogFormatterTest phpunit test with new string

Bug: T307181
Change-Id: I367b78068c8177505651c6d87ce668b36e1ca651
2022-05-16 13:31:01 +00:00
Umherirrender
d7809a41d9 logging: Normalize "infinity" in BlockLogFormatter for pre-T241709 rows
This allows the API to consistently return the new value for old rows.

Bug: T241709
Follow-Up: I36f49dc83718cc78f17fc340e6445030b8fd0c66
Change-Id: Ida69980f62a6ef070ba41b7e826967f424881716
2022-04-12 20:57:18 +00:00
Umherirrender
e247447af0 logging: Remove user_editcount from DatabaseLogEntry query info
The column is now unused. It was used to prefill edit count in User
object before 83e1846 by use of User::newFromRow

Follow-Up: I1b78bad7e1fa43f5f82908567a7daad9c6cc79b9
Change-Id: Iec5eeaa8729a3add46c11cd62dee8aefe2e5e050
2022-04-06 23:40:03 +02:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Umherirrender
7359c6bda9 Allow DeleteLogFormatter to work with pre-T20361 (April 2009) log rows
The i18n part of T20361 / ec0dd5b adds new log parameter,
logs from before the changes are needed to work with the formatter.

Bug: T289806
Change-Id: I096bc14373cbe038671fc33f651af7e005998a3b
2021-12-04 19:45:51 +01:00