Commit graph

224 commits

Author SHA1 Message Date
jenkins-bot
af9b10ae24 Merge "Make HTTPFileStreamer testable" 2024-04-27 02:01:23 +00:00
daniel
9672a6e5e4 Make HTTPFileStreamer testable
This also improves ThumbnailEntryPointTest by allowing it
to assert which headers got sent.

Change-Id: I33911775bce1b3cc7a53a03c2be50d53a28fabd1
2024-04-26 13:22:55 +02:00
daniel
c5d29b849a Tests: enable non-integration tests to use TitleFactory service.
This change implements two things that can be combined to allow
the usage of services like the TitleFactory in subclasses of
MediaWikiUnitTestCase:

1) This adds getServiceContainer() to the MediaWikiUnitTestCase base
   class, to mirror the method of the same name on
   MediaWikiIntegrationtest case, along with a a setService() method
   for defining service objects for use in tests.

2) This adds makeMockTitleFactory() to the MockTitleTrait, to allow
   tests to esaily define the TitleFactory service.

Making services available through a service container primarily
benefits code that relies on ObjectFactory, like REST handlers.

Needed-By: Iac113a9e766e38b2d19ae99b7e448548a515469e
Change-Id: Ida6c37c7133b9e3887268025daf6e5b7c1340e52
2024-04-25 13:00:14 +00:00
jenkins-bot
638236e3fe Merge "Introduce entry point classes for media files." 2024-04-03 15:50:32 +00:00
daniel
9638fa314a Introduce entry point classes for media files.
This moves a code out of file scope into classes to make it
testable. The code is left in the same structure as it was before,
global functions have been converted into methods on the new
ThumbnailEntryPoint and Thumbnail404EntryPoint classes.

This test introduces comprehensive phpunit tests covering all functional
code paths in ThumbnailEntryPoint. This is intended to support
refactoring of this code.

Change-Id: I459abc7b11d0ab4ee682a863c9525a945048296f
2024-03-30 21:14:05 +01:00
Timo Tijhof
4e40bcdd8f PoolCounter: Adopt PSR logger in PoolCounter objects
* Inject from ServiceWiring via PoolCounterFactory.

* In production we use PoolCounterClient (which is backed by
  our poolcounterd service), we also offer PoolCounterRedis for
  third parties. Replace the local logger in the Redis variant in
  favour of the built-in one.

* Update PoolCounterWork to adopt this as well. Expose it via getter
  to here, so that DI works all the way, including for the existing
  test.

Bug: T358901
Change-Id: I5413825a0172b186d58e85bbc3cc93697b174c27
2024-03-02 00:41:11 +00:00
James D. Forrester
35b2542895 Namespace includes/cache
Bug: T353458
Change-Id: Ic3f3168ef17113f5fb3ec11e0a47f52d65eefba9
2024-02-20 10:28:03 -05:00
Reedy
c14dd609a7 tests: Move Wikimedia tests into Wikimedia\Tests
Change-Id: I9c64a631b0b4e8e4fef8a72ee0f749d35f918052
2024-02-17 02:09:08 +00:00
Reedy
e94e265a93 tests: Add Tests to PHP namespacing
Change-Id: I849268172751d50292e93aa75abe8094873f56bc
2024-02-16 19:10:11 +00:00
James D. Forrester
eeb5a740b3 Namespace Message, move to appropriate directory
Bug: T353458
Change-Id: I088cbc53fbcdb974e5b05b45a62e91709dacc024
2024-02-14 15:10:36 -05:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
daniel
24d0aee05e entrypoint: Isolate entry points from PHP runtime for testing
1) Introduce EntryPointEnvironment which wraps functions that interact
with the PHP runtime, so they can be mocked for testing.

2) Allow server info fields to be overwritten in FauxRequest.

3) Make MediaWikiEntryPoint use WebResponse to set headers

Bug: T354216
Change-Id: Ic21950c956de5d2b5a7dd66a1e2de58f807cfd9f
2024-02-02 13:03:29 +01:00
DannyS712
f11bee20d4 DummyServicesTrait: add an ITextFormatter
To avoid duplicating the creation of mocks/implementations

Change-Id: Id1094a9009acd100092f1b7cd55016d78900ce5f
2024-01-09 13:16:59 +00:00
Amir Sarabadani
b7c5d05813 PoolCounter: Namespace classes
Two of the classes in this directory have already namespaced to
MediaWiki\PoolCounter.

Bug: T353458
Change-Id: Ie41f8d935f7623bb40040a5eb78f99c6d7b7b75e
2023-12-20 09:32:19 +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
Fomafix
b0e8a79638 Use namespaced CommentStore and CommentStoreComment in tests
Change-Id: Ied41909c2a08f5ae98ea9a27d6d9fed80e1a0292
2023-12-04 12:45:14 +00:00
Timo Tijhof
c8c47d1358 tests: Remove DummyServicesTrait::getDummyDBLoadBalancer
Follows-up Ie420f2b42ee7d. Not yet used, and in line with T326274
would ideally not need to be used.

Bug: T326274
Change-Id: Iddd5c2245bcd4215e2ed86ac64d186e8cc9fb095
2023-11-22 13:11:15 -06:00
Tim Starling
657c003ef1 Add clearUserCache to mock BlockManager
To avoid error when MediaWikiIntegrationTestCase::resetDB() calls
User::clearInstanceCache().

Change-Id: I7ba4b280d581e7821a9287b27a4b22196dd09f36
2023-11-20 12:34:34 +11:00
Tim Starling
7b0e2f946c Add MockDatabase class
Traditionally we tell people to avoid mocking the database, and we
haven't make a centralized way to do it. This has just led to it being
done poorly and verbosely in a lot of different ways.

So, add a MockDatabase class.

Change-Id: Ie420f2b42ee7d047378221c519845f7261c20c28
2023-11-16 12:24:48 +11:00
Martin Urbanec
c9908da103 IP Masking: Expire temporary accounts in 1 year
Why:
Temporary accounts (introduced as part of IP Masking)
are supposed to expire 1 year after their registration.
Automatic account expiration can be done via a maintenance
script, which would be periodically executed via cron / systemd.

Make it possible for extensions to provide their own logic
for generating a list of temporary accounts to invalidate.
This is used in CentralAuth to base registration timestamp
on the global registration timestamp.

The default behavior is "temporary accounts do not expire",
given the feature requires a maintenance script to run
periodically, which will not be the case on third party
instances.

What:
* Add `expireAfterDays` to $wgAutoCreateTempUser, controlling
  how many days temporary accounts have.
* Add UserSelectQueryBuilder::whereRegisteredTimestamp(),
  filtering accounts based on user_registration.
* Add ExpireTemporaryAccounts maintenance script, which is
  @stable to extend.

Bug: T344695
Change-Id: If17bf84ee6620c8eb784b7d835682ad5e7afdfcc
2023-11-09 15:11:48 +01:00
Tim Starling
990acd88be Stop using nonexistent DatabaseBlock constructor options
Remove the 'user' option from the documentation and defaults. It has
been ignored since a3b4881f6f (2021, 1.37).

Fix tests which pass unknown constructor options. I found these by
temporarily patching the constructor to throw when an unknown option is
given.

Change-Id: I95cb2a38a5688d83c90ad501786f6d6bb02765ba
2023-11-06 12:03:51 +11:00
jenkins-bot
e49ae11a78 Merge "Display all error messages for a CompositeBlock" 2023-10-27 14:22:29 +00:00
daniel
2024bb4d11 Introduce BlockMockTrait
This trait provides a robust way for tests to simulate user blocks.

Developed as an alternative approach to I7fc457eff88.

Change-Id: Ia5d813fcbdd77b94dbbc730ca4639d6efd2148a8
2023-10-27 12:22:36 +00:00
Thalia
e521abbcd8 Display all error messages for a CompositeBlock
* Add getMessages method to BlockErrorFormatter that will get
  error messages for all the applicable blocks.
* Call getMessages from PermissionManager, UserAuthority and
  EditPage.
* ApiBase and UserBlockedError still call getMessage since
  they work with a single message.

Bug: T344463
Change-Id: If240562dd25435d9c6c824dd595d58bb8672de2b
2023-10-27 13:05:08 +01:00
thiemowmde
669120b089 Add missing hasContentModel to MockTitleTrait
I worked around this with a custom mock for the moment, but would
like to use the upstream trait in the future.

Change-Id: Idf28d905f9fd01c24f29ad6a60419bfb4896704c
2023-10-20 18:30:29 +02:00
Kosta Harlan
0558902fb7
MockAuthorityTrait: Move helper methods from UserAuthorityTest into trait
Why:

- MockAuthorityTrait doesn't allow setting up a mock with rate limiter,
  but user authority test has a bunch of code that could be used for
  that purpose

What:

- Copy the private helper methods from UserAuthorityTest into MockAuthorityTrait

Change-Id: I2114056e1c0447080828485e229d82290baf3b24
2023-10-16 20:36:56 +02:00
Amir Sarabadani
136fa38a4a Migrate to IConnectionProvider methods in more places
Getting rid of uber-deprecated wfGetDb() and recently deprecated
LB::getConnection.

Bug: T330641
Change-Id: Ifd4b4e01f2a120ad6db517cc8fd2eb6b11b72bc9
2023-10-05 19:51:20 +02:00
C. Scott Ananian
097983e9d7 Unit test for LinkRenderer::makeRedirectHeader() used by WikitextContentHandler
Change-Id: I3577633670d0c2a771c690e3d6601300e1867222
2023-09-22 17:08:20 -04: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
5bc2a04b08 Namespace remaining Title-related classes under \MediaWiki\Title
Bug: T166010
Change-Id: Ia2e5a7367cc8cdbd8a7b845ae2fd5d776ff22891
2023-09-19 05:21:23 +00:00
James D. Forrester
41fb118c5c Namespace TitleParser under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: I4848e903b0c0a2f7c58ac19e0baeef0085a36bdc
2023-09-19 05:19:00 +00: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
a8a6cfd966 Namespace NamespaceInfo under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: Ibe103cd362535d3cb94cb8931e95fc74099d1497
2023-09-19 05:17:04 +00: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
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
Amir Sarabadani
4fccf6bf30 rdbms: Add support for per-domain calls in ReadOnlyMode
That would remove the need for passing around LB.

ReadOnlyMode code needs a lot of clean up. In follow up patches, I want
to inject WAN and possibly APCu to this and remove that from LB itself
to decouple LB/LBF from BagOStuff.

In even later patches, I want LB/LBF to set the ReadOnly in the service
instead and reverse the coupling.

Bug: T343917
Change-Id: Ibe7f80292d911fc8953e59f74264c499ab1700d0
2023-09-10 03:23:13 +00:00
jenkins-bot
fc40cf1067 Merge "Make "temp reserved" usernames not be "usable"" 2023-09-06 21:11:52 +00:00
jenkins-bot
98f4724716 Merge "Make MockTitleTrait @stable to use." 2023-09-02 23:14:58 +00:00
Petr Pchelko
66509b3d32 Make MockTitleTrait @stable to use.
This is much better then mocking Titles manually
in extensions.

Change-Id: I40c0d118de94e85568bcb33ab1a6d1e1f9eb3eb4
2023-09-02 22:58:33 +00:00
Lucas Werkmeister
b4af67e6ce Remove migration code from CommentStoreBase
As far as I can tell, there are no other CommentStoreBase subclasses
anywhere, and everything outside the tests calls CommentStore with
hardcoded MIGRATION_NEW, so all the support for other migration stages
has been dead code for a while now. Let’s remove it to make the code
simpler and less confusing.

Bug: T343558
Change-Id: I411967bd19979de47463aa93891cdc55baf89653
2023-08-29 12:37:44 +02:00
Amir Sarabadani
f4e68e055f Reorg: Move Status to MediaWiki\Status\
This class is used heavily basically everywhere, moving it to Utils
wouldn't make much sense. Also with this change, we can move
StatusValue to MediaWiki\Status as well.

Bug: T321882
Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3
Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
2023-08-25 15:44:17 +02:00
Tim Starling
07f1bc9f89 Make "temp reserved" usernames not be "usable"
If a username matches $wgAutoCreateTempUser['reservedPattern'], but the
username is not a valid temp user, return false from
UserNameUtils::isUsable().

This makes reserved patterns analogous to $wgReservedUsernames, and
provides a simple way to reject central sessions for temp users on wikis
where temp users are disabled.

Bug: T342475
Change-Id: I1d7f843e71e605fccf3de93fd145ff43e396619f
2023-08-25 15:06:22 +10:00
daniel
bf28ebd4ef HookContainer: allow registering broken callables.
Extensions may implement hooks defined by other extensions.
When the other extension is not present, the base class or interface of
the hook handler may also not be present. In that case, we should still
allow the handler to be registered. This is harmless, since the hook
will never fire if the extension that defines it is not loaded.

Bug: T339834
Change-Id: Id975370dececcb09ae5d00e6f68da57dc22fb267
2023-08-22 16:30:44 +00:00
Michael Große
7fb8424bc1 Override inContentLanguage for FakeQqxMessageLocalizer
Message:inContentLanguage() changes the language of the message to the
ContentLanguage of the current wiki. But for tests we want to keep it as
qqx and also not access any Services/DB.

Change-Id: Ic1d8b39b053fb0f6050bd7cbdfe7b140dd423659
Needed-By: I6dbb683d755b1a4eed6f0b158b26185cf11dbbde
2023-07-31 16:22:42 +02:00
thiemowmde
7583ed8be8 phpunit: Replace ad-hoc array in TestLocalisationCache with MapCacheLRU
This does not have a direct impact as far as I can tell. Still I feel
this is a much better fit.

Change-Id: I2a4a4a9b0e6d91bd56c03c80564db6a0c53758b6
2023-07-24 17:52:31 +00:00
Daimona Eaytoy
0e55aa602a Inject extension namespaces into NamespaceInfo
The service was previously accessing the global ExtensionRegistry
singleton, making it lose its statelessness. Dependencies should always
be injected, so add constructor parameters for that.

Simplify tests accordingly.

Change-Id: Iae375a81cab411fab607cba0addb2088131b3c81
2023-07-16 22:53:26 +02:00
thiemowmde
8334188972 Fix TestLocalisationCache being way to small
I dug into a particular profile via KCachegrind (specifically the
profile for DirectParsoidClientTest in VisualEditor) and found this
surprising bottleneck. Let's say a test uses a data provider to test
a particular piece of code with 5 different languages. And then
another piece of code with 5 languages. And so on. Because the cache
can only hold 4 languages there will never be a successfull cache
hit.

The items in the cache are something like 1 or 2 megabytes each. It
should be fine to hold 16 of them in memory. Possibly even more. The
sweet spot in my example was 10. This is when the runtime of
DirectParsoidClientTest gets suddenly cut in half.

Bug: T225730
Change-Id: Ie04f338ee8a59f08be50947d794626ed52d793bc
2023-07-07 20:15:03 +00:00
jenkins-bot
79cfad5ee0 Merge "FakeQqxMessageLocalizer: Add @since" 2023-06-29 18:35:26 +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
Alexander Vorwerk
27beeac288 Drop $wgCommentTempTableSchemaMigrationStage
This was a temporary flag to allow setting the migration stage for a
comment migration with a temp table.

Since the rev_comment_id migration is done, this is no longer needed.

Dropping the compatibility code for temp tables will be done in
follow-ups.

Bug: T299954
Change-Id: I290a74f27b05cd7e062dda78766911ffe3053d08
2023-06-09 11:32:16 +00:00