Commit graph

152 commits

Author SHA1 Message Date
jenkins-bot
25572c28f8 Merge "tests: Handle dynamic created properties on test classes" 2023-01-13 21:50:49 +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
jenkins-bot
a359d1dc06 Merge "Prepare migration from revision_comment_temp to rev_comment_id" 2023-01-09 21:02:49 +00:00
Umherirrender
b81db269a6 tests: Allow dynamic properties on PHP 8.2 for GhostFieldTestClass
Deprecated: Creation of dynamic property
Wikimedia\Reflection\GhostFieldTestClass::$privateField is deprecated in
/workspace/src/tests/phpunit/includes/libs/serialization/SerializationTestUtils.php
on line 150

Bug: T314099
Change-Id: Ic1cd7a3560e6fe39e6c7b077f42c90fbc844c202
2023-01-06 03:06:06 +01:00
Alexander Vorwerk
cf12721101 Prepare migration from revision_comment_temp to rev_comment_id
This patch introduces a configuration variable that allows one
to control the migration stage in production.

Bug: T299954
Change-Id: I36f1e3cd9fb0f25fd43f4dbb97f791da5eb1147b
2023-01-02 22:33:16 +01:00
DannyS712
1f8e5bcefe DummyServicesTrait: add content handler factory
Simplify mocking common cases of the content handler factory
only support specific content models.

Change-Id: Ib7f4099a2b1655b1bfb4d90f03105c27d17042ed
2023-01-02 01:09:42 +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
thiemowmde
0b80e9ebcc Fix incomplete ITextFormatter mocks
Otherwise the mocked getLangCode() method returns null, which is not
allowed any more in PHP 8.1.

Bug: T289926
Required-For: I7e026cca216aba24ee5d5662b6fca322b3cec9ae
Change-Id: I178def7f03a44f6b49cdb461d9ab340e1c89517f
2022-11-21 10:00:57 +01: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
Thiemo Kreuz
68ec2661d2 Use native array_column() in tests instead of loops
It's just a nice, lesser known convenience function. Exists since
PHP 5.5.

The changes to SerializationTestTrait ended being a little different.
Original I tried to use array_column() as well. But it drops the
array keys, which is relevant here.

We found that calling the two methods getTestInstances(AndAssertions)
multiple times is quite expensive and should be avoided. I changed
the code slightly so it's much less likely this is done unintentionally.

Change-Id: Ifaba3c370871a7c97b4d81ec21ff6ec134433fc0
2022-08-16 15:41:14 +02:00
Máté Szabó
85017a30b2 phpunit: Fix trivial dynamic property usages in tests
Dynamic property creation is deprecated in PHP 8.2 (E_DEPRECATED).
Migrate some trivial cases in tests to use explicitly declared fields
instead, and remove the unused lastLog field from
MediaWikiLoggerPHPUnitExtension.

Notably this does not yet address MediaWikiIntegrationTestCase using
dynamic properties to associate ephemeral data with DB connections used
for tests.

Bug: T314099
Change-Id: I55453c0d254012b69c6843c54cfa8345fa5744fa
2022-07-29 01:59:23 +02:00
daniel
f2df03704e Add support for nested property schemas in MainConfigSchema.
This adds support for JSONSchema style property declarations with nested
schemas. This is a step towards using more nested structured for
configuration, rather than adding to the over 700 keys already defined
in the main config schema.

Defaults from property schemas are aggregated into a default value in
the top level schema. Descriptions are however not yet aggregated.

Change-Id: Iaf46a9ecc83bee3566098c56137a1be66bff2ab9
2022-06-29 16:34:43 +10:00
daniel
7f8e3c5360 Docs: remove references to DefaultSettings.php
Bug: T300129
Change-Id: I1e83a0dde6235bed91d28d7d43691c6a5d979f2f
2022-05-30 21:27:09 +02:00
Matěj Suchánek
e47c441078 Fix many typos in comments
Found using IntelliJ's "Typo" code inspection.

Change-Id: I746220ebe6e1e39f6cb503390ec9053e6518cf16
2022-05-10 12:46:11 +00:00
DannyS712
7a4f38ae83 DummyServicesTrait: use MainConfigSchema for default settings
Instead of needing to manually list the default, which may then
get out of sync, use what the rest of MediaWiki uses for defaults.

Change-Id: Idf97a519f21a9d1a47ae0773e18513b5e380fe15
2022-05-02 18:29:11 +00:00
Aryeh Gregor
79fc95d39c Use MainConfigNames instead of string literals, #5
This should be the last of the usages in core, although I'm sure a few
are hiding somehow.

Change-Id: I7bf0b24bf23d3efb4c56a891830bbfe67945e899
2022-04-27 18:46:29 +03:00
Tim Starling
e8dbf5f80c TempUser infrastructure and services
Add services and utilities for automatic creation of temporary user
accounts on page save, in order to avoid exposing the user's IP
address.

* Add $wgAutoCreateTempUser, for configuring the system
* Add TempUserConfig service, which interprets the config.
* Add TempUserCreator service, which creates users during page save as
  requested by EditPage. With proxy methods to TempUserConfig for
  convenience.
* Add table user_autocreate_serial. Table creation is necessary before
  the feature is enabled but is not necessary before deployment of this
  commit.

Bug: T300263
Change-Id: Ib14a352490fc42039106523118e8d021844e3dfb
2022-04-14 09:23:55 +10:00
Nikki Nikkhoui
f6780de058 Set page id to 0 for pages in virtual namespaces
If we are creating a Mock title, the ID should be set to 0
for any Titles that are in "virtual" namespaces (e.g.
any with a namespace ID < 0, which is Special: or
Media:)

Change-Id: I6aae00ae8f68ad3a93d9edd1194e828735e2a878
2022-03-10 20:12:27 +00:00
jenkins-bot
e31b1fbe20 Merge "interwiki: Adjust documentation for InterwikiLookup::getAllPrefixes" 2022-03-09 22:28:04 +00:00
DannyS712
5ef90d5b87 DummyServicesTrait: remove extra parameter to createMock()
Left over from my changes in
I25b8f0256d222d994173eee66f379fb5422994b5 when it used to
be a createNoOpMock() call instead.

Change-Id: I20fc8aaa62c296160236443ab03a4cf272fe8395
2022-03-08 01:41:12 +00:00
daniel
674e79e296 Add inNamespace support to MockTitleTrait
Needed-By: Ibcfe05f2c15f6148cb81463dbcdbdacb142dc58e
Change-Id: I571619b8b538f496f4d1db82ee443a21ab7af42e
2022-03-02 21:39:14 +00:00
Umherirrender
e0c3e75414 interwiki: Adjust documentation for InterwikiLookup::getAllPrefixes
Use bool instead of string, most caller provided int instead.

The InterwikiLookupAdapter class is strict comparing Interwiki::isLocal
(a bool) with the given $local value, which evaluates always to false
and the expected filter option is not working.
The unit tests is using bool, not the documented string.

The ClassicInterwikiLookup is not affected.

Found by phan strict checks

Change-Id: I63ed9772429c6f5bfe38a9fad190491812866f3f
2022-02-24 17:08:29 +00:00
Ammarpad
c06dd6f667 UserNameUtils: Always strip subject namespace in canonical username.
Username with namespace prefix is not valid username. It's neither
creatable nor usable.

If the rigor validation passed to getCanonical() is not RIGOR_NONE,
this namespace prefix will always be removed by TitleParser.

We will now remove it even if the validation rigor is RIGOR_NONE
since the prefix can never appear in legal username, and its presence
will cause issues later even if the strict validation is not requested.

The validation is turned off usually when it's not known whether the
username is IP address or not, as is the case for T283915.

Bug: T283915
Change-Id: I34aa1d257f8bd90c80f40a76190a756d1e93e254
2022-02-21 22:37:44 +01:00
Tim Starling
0dbcf3362b Use mock Guzzle client during tests
Instead of failing when createGuzzleClient() is called, return a mock
which fails when a request is actually dispatched, following the
suggestion of the comment.

Otherwise PHPUnit fails to start up when RemoteIcuCollation and Shellbox
are configured.

Change-Id: Iac8d1e73512e7073264e79bbef8e4fa02fedefe2
2022-01-18 13:14:51 +11:00
Daimona Eaytoy
f976775201 DeletePage: add option to delete the associated talk page
Currently this is implemented internally as a second method call. In the
future, it might be possible to optimize the implementation, e.g. to
reduce the amount of DB queries/jobs etc. without changing anything for
callers.

Since the implementation of e.g. the result getters is generic, a future
commit may add an option to delete subpages with relatively low effort.

The revision limit for big deletions is now using the total number of
revisions (base page + talk page). This is because both deletions would
happen in the same main transaction, and we presumably want to optimize
the deletion as a whole, not as two separated steps. This would become
even more important if the aforementioned improvements are ever
implemented. Note, the whole concept of "big deletion" might have been
superseded by batched deletions in the author's opinion, but as long as
such a limit exists, it should serve its purpose.

The current interpretation of the associated talk option is that the
request is validated, and an exception is raised if we cannot delete the
associated talk, as opposed to silently ignoring the parameter if the
talk cannot be deleted. The only exception to this is that it will not
fail hard if the talk page turns out not to exist by the time the
deletion is attempted, as that's hard to foresee due to race conditions.

Note that the summary for the talk deletion is prefixed with the
delete-talk-summary-prefix message. The main reason behind this is that
the delete UI can sometimes offer an auto-generated summary like "the
only contributor was XXX" or "the content was YYY", and since this may
not apply to the talk page as well, the log entry might look confusing.

Bug: T263209
Bug: T27471
Change-Id: Ife1f4e8258a69528dd1ce8fef8ae809761aa6f1d
2022-01-11 14:48:56 +01:00
Thiemo Kreuz
d51c0032af Tests: Update syntax referencing classes and internal functions
Change-Id: Icd577d522a24cb636305ea7f1067a4f75816ba34
2021-12-02 17:07:49 +01:00
Kunal Mehta
f539b6f58c Support $wgLocalHTTPProxy in MultiHttpClient
This follows the same approach as MWHttpRequest, we inject
$wgLocalVirtualHosts, and for each request check whether it matches that
domain list, rewriting the request as necessary.

Unfortunately this requires a decent amount of code duplication because
MultiHttpClient is in includes/libs/ and can't depend on the same code
in MWHttpRequest.

Bug: T288848
Change-Id: Ia16d8f86b1cb20dde9fe487729d67d92af650cfe
2021-11-16 11:13:10 -08:00
Petr Pchelko
ac935cb758 Make SlotRecordTest a unit test
Change-Id: I4f5a4bf3703fc490c6c4de45f5a7947b7726aaa1
2021-10-19 20:31:55 -07:00
Roman Stolar
a68e641f9d Move Content::getParserOutput & AbstractContent::fillParserOutput to ContentHandler
Update/Create override classes of ContentHandler.
Soft-deprecate and remove method from Content and classes that override them.

Bug: T287158
Change-Id: Idfcfbfe1a196cd69a04ca357281d08bb3d097ce2
2021-09-29 13:10:51 +03:00
DannyS712
722ae6c6e1 Make UserDefTest a unit test
Building on my last few changes to use UserIdentityLookup and
TitleParser, plus the recent addition of UserNameUtils to the
DummyServicesTrait, its now fairly simple to make this a unit
test and retrieve services from DummyServicesTrait instead of
MediaWikiServices.

Add a 'hookContainer' option to
DummyServicesTrait::getDummyUserNameUtils(), because
subclasses of TypeDefTestCase don't have a helper method
createHookContainer() (normally this is provided by
MediaWikiTestCaseTrait). Instead, create a manual mock
HookContainer, like we did previously at NamespaceDefTest.

Also add more options to DummyServicesTrait to allow
callers to provide service instances, needed to avoid
creating two MediaWikiTitleCodec objects and to use
a hook container in NamespaceInfo.

This also required replacing uses of createNoOpMock()
in DummyServicesTrait, because that is also not available
in UserDefTest (its another feature of MediaWikiTestCaseTrait).
It may be worth exploring splitting MediaWikiTestCaseTrait into
the parts that are specific to MediaWiki (like HookContainer
or the Message system) and parts that are useful generally
(like createNoOpMock).

Change-Id: I25b8f0256d222d994173eee66f379fb5422994b5
2021-09-13 23:55:51 -04: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
jenkins-bot
d66e428747 Merge "New RestrictionStore service" 2021-09-01 08:20:29 +00:00
Aryeh Gregor
cf818256fb New RestrictionStore service
This allows checking restrictions without a dependency on Title, based
only on a PageIdentity.

Additional fixes along the way:

* Correctly return false instead of 'infinity' for
  getRestrictionExpiry( 'create' ) on an existing page
* Correctly handle non-special pages that can't exist (like media pages)
  in listApplicableRestrictionTypes() (return empty array instead of
  'create')
* Improve readability of isProtected()

The expectation change in TitleTest::testIsProtected() is because the
test was formerly broken, since it set mRestrictions without setting
mRestrictionsLoaded. (Which illustrates how this approach to testing is
essentially broken.)

Co-authored-by: Vedmaka <god.vedmaka@gmail.com>
Bug: T218395
Change-Id: Ia73ea587586cb69eb53265b2f8f7a296a2573dd0
2021-08-28 16:01:06 +00:00
Amir Sarabadani
66a4b414e5 Introduce concept of generateHTMLOnEdit() for ContentHandler
This way you can avoid rendering HTML and storing ParserCache entries

Bug: T285987
Change-Id: I3c7023b776f2a1e35dafdbb6ac0eb3eb73ae5fd4
2021-08-24 22:40:46 +02:00
Petr Pchelko
295557d1ae MockHttpTrait: support multiple MultiHttpClients
With mocking HTTP, we can supply an array of requests
to expect, but if MultiHttpClient or Guzzle client are
used, we can only supply one. Now we can mock a sequence
of requests done via either of these clients.

Change-Id: I350ed59af603a0504704af3265787a4be8f2dc2a
2021-08-12 11:30:14 -07:00
jenkins-bot
3c34f7f684 Merge "Use DummyServicesTrait for BadFileLookupTest TitleParser" 2021-08-10 03:44:11 +00:00
Petr Pchelko
0a4958150a MockHttpTrait: convenience to mock HTTP timeout
Two enhancements:
1. If the status code of the mocked response is >= 400,
the Status object returned by the mock request should actually
be fatal, not good.
2. Convenience method to create a mock request that will
result in a timeout response, compatible with real timeout.

Change-Id: I4c3aab6ab88695729b4f398dacf3575fbdb4dad4
2021-08-03 09:09:09 -07:00
Petr Pchelko
b782a7e66d Move Content::preSaveTransform to ContentHandler
Create ContentTransformer to access ContentHandler::preSaveTransform through the service.
Prepare object to hold a data that required for ContentHandler::preSaveTranform params.

This will require making a semi-backwards-incompatible
change no matter what, we don't really have a great way
of hard-deprecating overriding methods.

However, with the ContentHandler calling Content and
Content calling ContentHandler, and with the ProxyContent
trick to stop infinite recursion, it doesn't matter whether
callers use Content or ContentHandler. This will allow us
to naturally convert all callers. But won't really allow
hard-deprecation.

Bug: T287156
Change-Id: If6a2025868ceca3a3b6f11baec39695e47292e40
2021-07-29 18:06:02 +03:00
DannyS712
d62a398a78 Use DummyServicesTrait for BadFileLookupTest TitleParser
Possible now that we can tell the service to throw mock
exceptions. Requires telling DummyServicesTrait to
include "Image" and "Image talk" alias support (these
are included in MessagesEn.php and so always available).

Follow-up: I11ae4c6292465626ad1e432f7c6e9754c8ef36c2
Change-Id: Ic995aeebcd2b9c8d2c43cb17258363eef81429ad
2021-07-28 20:50:20 +00:00
DannyS712
91ac8a717d Add UserNameUtils to DummyServicesTrait, and use it
Allows us to reduce direct mocking in individual tests, or relying
on MediaWikiServices, by having a reusable service instead that
can be used in unit tests.

Make use of it in a few places.

This dummy service is also less coupled to individual tests;
in the rest handler tests, replacing mocks that report that
only a specific string is an ip address with the actual implementation
that accepts other ip address, and in BlockUtilsTest use
an actually invalid user name instead of making the mock
UserNameUtils complain about a perfectly valid name.

Change-Id: Iaa3195002ac4ae7e0c9c58ed57c80c02762d4070
2021-07-27 12:17:06 +00:00
DannyS712
edd9ae23be Allow using MediaWikiTitleCodec with errors in unit tests
MediaWikiTitleCodec can throw MalformedTitleException,
which cannot be created in unit tests (see T281935). Until
that changes, add a helper callback
MediaWikiTitleCodec::$createMalformedTitleException
that will by default return a MalformedTitleException, but
tests can override this to return a mock.

We add this as an option to DummyServicesTrait to throw
generic `MalformedTitleException`s without regard to the
specifics of the message or parameters provided, this
can be used if no finer control is needed, or callers
can manually change the callback.

Demonstrate using it by moving the tests for UserNameUtils
to be unit tests - the only thing blocking this was the
creation of `MalformedTitleException`s.

Change-Id: I11ae4c6292465626ad1e432f7c6e9754c8ef36c2
2021-07-27 11:27:56 +00: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
DannyS712
d290b63153 Add DummyServicesTrait::getDummyReadOnlyMode()
Returns an actual working ReadOnlyMode object
based on a ConfiguredReadOnlyMode and a mock
load balancer

Change-Id: I429c8e81343c24c536718b3fc112e797afbc05a2
2021-07-05 07:16:13 +00:00
daniel
b3b70624c9 Authority: expose user block info
Expose info about user blocks from Authority. This allows calling code
to provide more detailed information to the user about why they are
denied some action on the wiki.

Bug: T271494
Change-Id: Ia84e469888866d72752aad355292666c31e12bad
2021-06-30 13:42:21 +02:00
Petr Pchelko
edb3a9a692 Allow passing mock Authority in API integration tests
This is a demo, a lot of tests could be rewritten as a followup
to pass proper Authority when executing tests instead of writing
globals. Much cleaner imho.

An improvement idea is to allow overriding 'default permissions'
when creating a mock Authority.

Change-Id: I38570024e0d5a67a8e1c52f7456c458090ec2b6e
2021-06-07 11:50:42 -07:00
DannyS712
3dc01651b2 Make MockAuthorityTrait stable to use
Document the trait to be stable to use by extensions' tests

Change-Id: I58661943c7e1acb6ff09798ee1a30be0fde3f459
2021-06-06 04:08:17 +00:00
Thiemo Kreuz
6805f39a30 Remove unused default values from class properties
In all these cases the property is unconditionally set in
the constructor. The extra initialisation is effectively
dead code and an extra source of errors and confusion.

Change-Id: Icae13390d5ca5c14e2754f3be4eb956dd7f54ac4
2021-05-12 13:44:28 +02:00
daniel
7b832c1fa3 Remove SearchResultPageIdentity interface
SearchResultPageIdentity and SearchResultPageIdentityValue were
introduced as placeholders for PageIdentity and PageIdentityValues.
They can now become aliases.

Bug: T282091
Depends-On: I9b1ab02e0acf12ace107361ea2c443aa543c4880
Depends-On: Ie405ea9539cd18e15b0abb6db6df64ec0135825d
Change-Id: I6eb55c78a0a72be66814f8bc854ba663e7c6f62b
2021-05-10 16:05:45 +02: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