Commit graph

114 commits

Author SHA1 Message Date
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
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Petr Pchelko
1782bc7fd4 Remove hard-deprecated LogEntry::getPerformer
Change-Id: Ia2c4819848f5d23d5ceb74aae9c6c5920b8851ba
2021-06-28 18:06:36 -07:00
jenkins-bot
6feb8d7834 Merge "Change "protection level" to "protection settings"" 2021-05-23 12:54:48 +00:00
jenkins-bot
d7a0394e8e Merge "Allow action blocks to be logged via block log parameters" 2021-05-05 21:26:46 +00:00
DannyS712
31676abea5 Add DummyServicesTrait::getDummyInterwikiLookup
Replacing the mock InterwikiLookup used in
MediaWikiTitleCodecTest revealed that that test was,
because of the mock not behaving correctly, testing the
wrong thing - interwiki prefixes are *not* case sensitive,
and are always converted to lowercase in the actual
ClassicInterwikiLookup. Fixed those expectations.

Change-Id: I242431e88860b7700a9f93f77a0fe195fd748800
2021-05-05 10:57:59 -07:00
tsepothoabala
b4a60fecdf Allow action blocks to be logged via block log parameters
Bug: T279560
Change-Id: Icd6ba193a2ce7af83a074cd135470a5097638791
2021-05-05 19:45:52 +02:00
Amir Aharoni
986a4c9459 Change "protection level" to "protection settings"
This was suggested in translatewiki.

Protection is not only about protection level, but also
about its being cascading or not and expiry time. The message
should reflect this. Some messages that are specifically about
level are not changed.

Change-Id: Id9dae220269cda526564c555427e24d880e1a57c
2021-05-04 13:17:36 +03:00
Tim Starling
83e184670c Stop using legacy ActorMigration field "log_user"
Bug: T278917
Change-Id: I1b78bad7e1fa43f5f82908567a7daad9c6cc79b9
2021-04-28 16:29:04 +10:00
daniel
fed7f0b179 Remove $actor field from UsererIdentityValue
Code that needs to store an actor ID in the database to
represent a UserIdentity, or needs to construct a UserIdentity based on
an actor ID loaded from the database, should use the ActorNormalization
service.

Note: The getActorId() method is removed from the UserIdentity interface,
but all concrete classes continue to support it for now.
UsererIdentityValue::getActorId() is hard deprecated and should
be removed in 1.37. It always returns 0.
User::getActorId() is not deprecated at this point.

Bug: T274179
Depends-On: Id2b3ddf6a2a7cdf90f8936a69148d2cce6fde237
Change-Id: I9925906d11e47efaec3c1f48d5cb3f9896a982c1
2021-04-13 18:18:06 +00:00
Reedy
eb41565a9a Tests: Start marking some closures as static
Bug: T274036
Change-Id: Ib738ecd3bc23d34900bc268c8246702ac3655746
2021-02-06 19:57:42 +00:00
Umherirrender
0347fd0631 Improve some function documentation in tests
Also fix some whitespaces

Change-Id: Ibed50a4f07442d3f299cf545c16f5dbb5f27a411
2021-01-14 22:13:55 +01:00
Thiemo Kreuz
ac205fa84c Fix incomplete/bogus PHPDoc tags in various tests
Most of these are found by the not yet released I10559d8.

I remove the type MockObject in some cases when the calling
code really does not need to know if he get's a mock or the
real thing. However, I do this only in places that are very
closely related to the fixes.

Change-Id: I26a4c3c5a8ae141bf56161b52b54bce7e68f2e30
2021-01-14 19:02:00 +00:00
DannyS712
6a93b0ca93 More misc test cleanup
* parent::setUp() should be first, and ::tearDown()
  should be last
* Move tests that directly extend PHPUnit\Framework\TestCase
  to /unit

Change-Id: I1172855c58f4f52a8f624e6d596ec43beb8c93ff
2020-12-24 00:52:06 +00:00
C. Scott Ananian
3d40c43b1f Deprecate InterwikiLoadPrefix hook
The InterwikiLoadPrefix hook isn't compatible with Parsoid, as it is
unidirectional and doesn't support enumerating all valid prefixes
(T270444).  Set/reset $wgInterwikiCache to mock the interwiki table
for parserTests and other unit tests instead.

This is a soft deprecation, as the used-in-production
Extension:Interwiki still uses InterwikiLoadPrefix, although not in a
way that would break Parsoid (since $wgInterwikiCache is set in
production).

Bug: T270444
Change-Id: If2507017c99c4ee42c104a0890bc45a84d7239d5
2020-12-21 19:28:48 +00:00
DannyS712
370856f0cf Remove use of $wgUser from LogFormatterTest, unneeded
Bug: T243708
Change-Id: I4d76ffbec4f094178059d3cccb65bf4837321f08
2020-09-14 20:26:13 +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
Thiemo Kreuz
5f3a92385b Fix visibility of setUp/tearDown
Change-Id: I636be48eb9f713680abac35d46091f7b49374696
2020-06-16 21:02:05 +02:00
Daimona Eaytoy
f5529400cc Stop using assertContains with string haystack
This was done automatically by replacing every assertContains with
string *needle*. Then verifying the results.

Bug: T192167
Change-Id: Id8cbbf3b01e948f80046714183cc299f86be21fd
2019-12-15 00:22:44 +00:00