Commit graph

65 commits

Author SHA1 Message Date
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +02:00
James D. Forrester
53b67ae0a6 Add namespace to remaining parts of Wikimedia\ObjectCache
Bug: T353458
Change-Id: I3b736346550953e3b2977c14dc3eb10edc07cf97
2024-09-27 16:19:10 -04:00
Timo Tijhof
311b2d0e98 Revision,Storage: Widen @covers tags in tests
> Given all called same-class methods are de-facto and liberally claimed,
> and that we keep the coverage limited to the subject class, it maintains
> the spirit and intent by listing the class as a whole instead.
>
> PHPUnit offers a more precise tool when you need it (i.e. when testing
> legacy monster/god classes), but for well-written code, the
> class-wide tag is exactly what you want.
>
> We lose useful coverage and waste valuable time on keeping tags
> accurate through refactors, especially private functions (or worse,
> forget to update it).
> Tracking tiny per-method details wastes time in realizing (and
> fixing) when people inevitably don't keep them in sync, and time
> lost in finding uncovered code to write tests to realize it was
> already covered but "not yet claimed".

Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen

Change-Id: If90fc5285a067ec8f706d87b2ba1ae85020e2ba0
2024-08-30 04:23:11 +00:00
James D. Forrester
f7ce0a0976 Move remaining four classes in includes/content into Content namespace
Bug: T353458
Change-Id: Ia0f3e22078550be410c4b87faf6aa4eabe6e270d
2024-08-10 10:40:53 +02:00
Ebrahim Byagowi
4c270a72ac Add namespace to WikitextContent
It adds MediaWiki\Content namespace to WikitextContent
and two classes related.

Change-Id: Ib74e4c5b3edac6aa0e35d3b2093ce1d0b794cb6d
2024-08-06 17:42:51 +03:30
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
Ebrahim Byagowi
16197f7d76 Add namespace and deprecation alias to TextContentHandler
This patch introduces a namespace declaration for the
MediaWiki\Content to TextContentHandler and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I2c72dacf28ee72fb70b15acdd81d0eb717ea949a
2024-05-20 05:34:31 +03:30
Ebrahim Byagowi
97d1202784 Add namespace and deprecation alias to TextContent
This patch introduces a namespace declaration for the
MediaWiki\Content to TextContent and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: Ic251b1ddfcf6db9c85cb54cddf912aa827d2bc3a
2024-05-19 23:23:01 +03:30
Alexander Vorwerk
d9713bf6a6 RevisionStore: Remove usage of ActorMigration
Bug: T227047
Change-Id: Ie877b578b5760d3592afd7654df524fe4d20a6ff
2024-02-05 00:29:44 +00:00
Thalia
123320164b RevisionStoreFactoryTest: Use class @covers annotation
Bug: T354968
Change-Id: Iecfe395d4e5f139f65cd81b665496b5c38398bfa
2024-01-12 19:11:24 +00:00
Fomafix
b0e8a79638 Use namespaced CommentStore and CommentStoreComment in tests
Change-Id: Ied41909c2a08f5ae98ea9a27d6d9fed80e1a0292
2023-12-04 12:45:14 +00:00
Bartosz Dziewoński
460422279a RevisionArchiveRecord: Also check for permission to view deleted pages
Bug: T345777
Change-Id: I12c00c9a5d547ddaa459fdd1489dd82b91fc3fe2
2023-09-20 22:05:59 +00:00
Reedy
a1144dc7c5 mark various anonymous functions as static
Change-Id: Iefe896769359f0d32e52bf20aa03e1c3715d5074
2023-08-22 19:38:38 +00:00
Umherirrender
0099099bb0 tests: Change expectDeprecation to expectDeprecationAndContinue
TestCase::expectDeprecation() is deprecated in PHPUnit 10,
use mediawiki own MediaWikiTestCaseTrait::expectDeprecationAndContinue()
for this case. This avoids the trigger_error call and isolate the
deprecation check into MWDebug class.

The continue part is also helpful in StubGlobalUserTest, where after the
first deprecation access more code exists, that was not executed as
PhpUnit 9 converts deprecations to exceptions.
In RCFeedTest the exception needs to be catched as the code proceed
after the deprecation notice is emitted.

Bug: T342110
Change-Id: Iecf827bec0d5215fd21bbb20b84caf928ee108a0
2023-07-18 16:35:43 +00:00
Umherirrender
e961107d28 tests: Remove MWDebug::clearDeprecationFilters from unit tests teardown
It is part of the global teardown in
MediaWikiTestCaseTrait::mwDebugTearDown which is annotated with @after

Change-Id: I25df03370e4efbbd08c2833ab72e449f3797e3d1
2023-07-10 20:20:17 +02:00
Umherirrender
d36073cdcf tests: Make some PHPUnit data providers static
Initally used a new sniff with autofix (T333745),
but some provide are defined non-static in TestBase class
and need more work to make them static in a compatible way

Bug: T332865
Change-Id: I889d33424f0c01fb26f2d86f8d4fc3de3e568843
2023-05-20 01:05:27 +02:00
Bartosz Dziewoński
6ba47296d9 Fix Phan suppressions related to Title::castFrom*() and friends
There is no way to express that Title::castFromPageIdentity(),
Title::castFromPageReference() and Title::castFromLinkTarget()
can only return null when the parameter is null. We need to add
Phan suppressions or explicit types almost everywhere that these
methods are used with parameters that are known to not be null.

Instead, introduce new methods Title::newFromPageIdentity() and
Title::newFromPageReference() (Title::newFromLinkTarget() already
exists), without the null-coalescing behavior, and use them when
the parameter is not null. This lets static analysis tools, and
humans, easily understand where nulls can't appear.

Do the same with the corresponding TitleFactory methods.

Change the obvious uses of castFrom*() to newFrom*() (if there is
a Phan suppression, a type check, or a method call on the result).

Change-Id: Ida4da75953cf3bca372a40dc88022443109ca0cb
2023-04-22 16:45:09 +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
Umherirrender
e59cf6c133 Use SlotRecord::MAIN instead of hard coded value
Makes it clear what about the value is (slot role name)

Change-Id: I0dc195aa24c0e699a32d3b07e62d58e90cfac84d
2023-01-03 16:24:42 +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
Amir Sarabadani
cb18d1007e Reorg: Move ActorMigration and ActorMigrationBase to user/
This may seem a bit weird but anything else related to actor is already
under user/ including ActorCache, ActorNormalization, ActorStore and
ActorStoreFactory.

Bug: T321882
Change-Id: I7072b374bba7a0cd9d905e399c822bf30bd5c0d8
2022-12-16 13:44:33 +01:00
Tim Starling
540bddfb1f When content is marked bad, show an error, don't pretend it is empty
It misrepresents the users contribution to show empty text for a
revision when in fact the revision contained some text which we later
lost.

Also, errors from SqlBlobStore::fetchBlobs() did not stop a cache entry
from being written, so a subsequent cache hit would show the bad
revision as empty.

So, in Storage:
* Add BadBlobException, which is thrown by the Storage layer to
  indicate that a revision is marked as bad.
* Have SqlBlobStore::getBlobStore() return an error for bad blobs
  instead of an empty string.
* Duplicate the check for flags=error into SqlBlobStore::expandBlob().
  This avoids an unnecessary cache fetch, and avoids making
  decompressData() throw on error, which would be a b/c break.
* In SqlBlobStore::getBlob(), suppress the cache when there was an
  error.

In Revision:
* Add BadRevisionException, to wrap BadBlobException in the Revision
  layer.
* Return null from RevisionRecord::getContent() on a broader set of
  errors. Make it mostly non-throwing.
* Add RevisionRecord::getContentOrThrow() which returns a non-nullable
  Content.
* Note that SlotRecord::getContent() returns a non-nullable Content so
  now throws in more cases.

In the UI:
* In Article::view(), catch the exception and show an error message.
* In DifferenceEngine, catch the exception and make a suitable error
  message available via getRevisionLoadErrors(). In the diff page, show
  the error message in a box.
* In ApiComparePages and the legacy rvdiffto, show a warning.
* In RawAction, show a 404 by analogy with other error cases.
* In EditPage, there was already handling for $content=null with an
  appropriate error message (missing-revision-content). But having
  $this->textbox1 = null caused PHP 8.1 deprecation warnings, so I fixed
  that.
* In EditPage undo, there was already handling for null content, but I
  improved the error message: "does not exist or was deleted" seems more
  appropriate than "conflicting intermediate edits".

Change-Id: Idd1278d6d756ef37d64addb7b5f3be30747ea603
2022-12-05 22:03:45 +00:00
Amir Sarabadani
09b18a8f4c Reorg: Move Title-related classes to title/
These three classes:
 - TitleArray
 - TitleArrayFromResult
 - TitleFactory

We need to move these and the rest of files under title/ to Title/ (and
namespace them) but the patch will become way too big given that Title class is
also one of them.

Bug: T321882
Change-Id: Iac1688172ee457348a08a470c86e047571feb8e0
2022-11-26 09:30:32 +00:00
Reedy
116b71452c tests: Simplify some nested ->will( $this->return assertions
Change-Id: Ic861ce5604784b7fa600844d81387b84230bc0e1
2022-11-12 11:57:12 -07:00
Thiemo Kreuz
e5d8bd29e6 tests: Remove non-existing method arguments from revision-related tests
Change-Id: Ie7b12fddd58617c7af7c569bf6208709bb730dbd
2022-08-06 10:49:59 +00:00
DannyS712
756df24990 Tests: remove unneeded helper methods that just return a mock with no
configuration.

Use $this->createMock() directly instead, and reduce some single-use
variables.

Change-Id: I34cee8a67a05593baf18a0322472653c39f37f37
2022-07-20 23:40:19 +00:00
Thiemo Kreuz
61ae7504df Replace trivial usa of mock builder with createMock() shortcut
createMock() does the same, but is much easier to read.

A small difference is that some of the replacements made in this
patch didn't use disableOriginalConstructor() before. In case this
was relevant we should see the respective test fail. If not we can
save some CPU cycles and skip these constructors.

Change-Id: Ib98fb06e0fe753b7a53cb087a47e1159515a8ad5
2022-07-15 16:43:48 +00:00
Umherirrender
05a175b439 Simplify assertion for false around wiki id and domain id
false is accepted by Assert::class since 9090085

Change-Id: I243a63dca310a198c6f7a8bc52298c5c95939eb6
2022-06-18 09:49:13 +02:00
Umherirrender
2909d06a08 Use new namespace for revision related classes
All revision related classes are namespaced MediaWiki\Revision
instead of MediaWiki\Storage since 1.32. The old namespaced
class names are deprecated and only kept for backwards-compatibility.

Bug: T305784
Change-Id: I34e492d84d9fc4bc78481667202716d93b3c43cb
2022-04-14 23:03:43 +02:00
Timo Tijhof
128debb64b tests: Change use of AtEase to at operator
Follows-up I361fde0de7f4406bce6ed075ed397effa5be3359.

Per T253461, not mass-changing source code, but the use of the native
error silencing operator (@) is especially useful in tests because:

1. It requires any/all statements to be explicitly marked. The
   suppressWarnings/restoreWarnings sections encourage developers to
   be "lazy" and thus encapsulate more than needed if there are multiple
   ones near each other, which would ignore potentially important
   warnings in a test case, which is generally exactly the time when
   it is really useful to get warnings etc.

2. It avoids leaking state, for example in LBFactoryTest the
   assertFalse call would throw a PHPUnit assertion error (not meant
   to be caught by the local catch), and thus won't reach
   AtEase::restoreWarnings. This then causes later code to end up
   in a mismatching state and creates a confusing error_reporting
   state.

See .phpcs.xml, where the at operator is allowed for all test code.

Change-Id: I68d1725d685e0a7586468bc9de6dc29ceea31b8a
2022-02-24 21:29:51 +00:00
Reedy
12aae45101 tests: Replace some usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: I361fde0de7f4406bce6ed075ed397effa5be3359
2022-02-24 12:55:25 +00:00
Amir Sarabadani
a0138ce2c6 Revision: Inject local cache to RevisionStore
Follow up to I630603eaffcae3700b2843fb97c5bedf8d29da9e

Bug: T297147
Change-Id: Ie3a7c345671d7d4f37978e513dd69bfe546d6c33
2021-12-17 19:23:19 +01:00
Petr Pchelko
ac935cb758 Make SlotRecordTest a unit test
Change-Id: I4f5a4bf3703fc490c6c4de45f5a7947b7726aaa1
2021-10-19 20:31:55 -07:00
Petr Pchelko
12997e1f14 Narrow PageUpdater dependency from Title
Note: this contains a b/c incompatible change to
SlotRoleHandler, but it's never used in any extensions
and never was used.

Change-Id: I898ab18467f7f8c605a579cc6236859b9d86c7f5
2021-07-26 19:45:11 -07:00
jenkins-bot
d7dac1bf4a Merge "RevisionStoreFactoryTest: Clean up and convert to unit test" 2021-04-24 03:32:57 +00:00
DannyS712
7d896dc2b5 Convert SlotRoleRegistryTest to unit tests
No integration is used in the existing code

Change-Id: I2b454e97e446c68658c8b3efeb9c15a0a4ca23d7
2021-04-23 20:57:46 +00:00
DannyS712
ee23dd80df RevisionStoreFactoryTest: Clean up and convert to unit test
Combine single use private methods, simplify mocks,
use a mock ActorMigration to allow making a unit test

Change-Id: I50e18b7727ca78a0ce0504d2b6c978e14d142b6a
2021-04-22 20:16:05 +00: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
jenkins-bot
bda0196304 Merge "Add support for derived MCR slots" 2021-03-18 20:55:17 +00:00
Cindy Cicalese
29862dd51d Add support for derived MCR slots
Bug: T277203
Change-Id: I1c70abc00c912b283e3e6eb2266633ae3f57673b
2021-03-18 15:34:46 -04:00
DannyS712
39a19f209a MainSlotRoleHandlerTest: fix typo "Fet"
Should be "Get"

Change-Id: I7dd2037b78011b2a1182d0c7c46cfa2f785aaa22
2021-03-16 14:45:49 +00:00
DannyS712
09df2d3c63 Convert MainSlotRoleHandlerTest to pure unit tests
Use mocks

Change-Id: Ie03f1a423dff119b817236925c99cdfef8561ffd
2021-03-15 18:01:28 +00:00
DannyS712
f5fcdb034e Convert (Mutable)RevisionSlotsTest classes to unit tests
No integration needed

Change-Id: I09be82b0f0e0347bbc3b343f86fd820999f68f93
2021-03-12 14:43:13 +00:00
Petr Pchelko
26be00fac4 Introduce helper WikiAwareEntityTrait
Bug: T273948
Change-Id: I21180d7031646f13413e2edb1bf0a17fbfdada13
2021-02-08 13:49:50 -06:00
Peter Ovchyn
e708b1d33f Make RevisionRecord::getPageId() and :: getParentId take a wiki ID
Bug: T273284
Change-Id: Id191b54844aaefeeaca081ae00997f13cdb987cb
2021-02-08 12:09:58 +02:00
vladshapik
ddb80d4f77 RevisionRecordTests: create a test case to check triggering of the warning in the RevisionRecord::getId() method
Since there is the testGetIdDeprecated() test case which tests that the deprecated functionality still works in RevisionRecordTests trait. So the new testGetIdTriggerDeprecatedWarning test case was added in order to check triggering of the warning in RevisionRecord::getId() method.

Bug: T273314
Change-Id: I7248bfa5ed8b485ea79929a3bd5f8db0156c3201
2021-02-03 10:56:55 +02:00
Petr Pchelko
511347f32a Use DummyContentForTesting in Revision unit tests.
TextContent/WikiTextContent can actually get to initializing
the global service container, which is not good.

Change-Id: I418d0a839fc3cd154d6d02af865e53564e2805ed
2021-02-01 20:11:49 -06:00
Umherirrender
393b6fb508 Add missing @param tags in tests
And exclude the rest inline to remove global exclude

Bug: T238572
Change-Id: Ib4c207177dd73702c113e6233f59be6e571a0f6a
2021-02-01 20:38:05 +01:00
vladshapik
117982da96 RevisionRecord: make RevisionRecord::getId() take a wiki ID
Bug: T272485
Change-Id: Ic1a8a406c2163844b14aa34ab259f0836687887e
2021-01-29 15:01:31 +02:00