Commit graph

746 commits

Author SHA1 Message Date
DannyS712
41287e87d8 Add MediaWikiTitleCodec and NamespaceInfo to DummyServicesTrait
Move MockTitleTrait::makeMockTitleCodec to DummyServicesTrait, and
replace the two existing uses, which are in core. Add some new
uses instead of mocking each time.

Unfortunately, we cannot use an actual MediaWikiTitleCodec
for the tests in BadFileLookup, because those tests are unit tests
and a MalformedTitleException cannot be created in the context
of a unit test. BadFileLookupTest gets around this by using
a mock that throws a mock exception - add a comment inline
explaining why we cannot use a real MediaWikiTitleCodec.

Paired with adding of NamespaceInfo to make mocking the language
methods related to namespaces easier by matching the real
logic in the Language class to the extend possible. Update a few
tests to use the DummyServicesTrait for their NamespaceInfo services.

Change-Id: Ibd691ccf0e632e1bf0bc1f7e9ddc0c660d5cad32
2021-05-04 19:10:23 +00:00
Thalia
6cb1016594 Allow partial action blocks to be made via ApiBlock
Bug: T280522
Change-Id: I114e3c76cfb6dd2f79b5217aee4b3da34df00850
2021-05-04 17:48:21 +01:00
DannyS712
7fb6c856ad Introduce DummyServicesTrait for use in unit tests
Shared trait to create services in unit tests to reduce
the mocking needed, beginning with a mock WatchedItemStore.
While this doesn't have everything a full WatchedItemStore(Interface)
supports, it does properly handled the following methods
* getWatchedItem
* addWatch
* removeWatch
* isWatched
* isTempWatched
and properly differentiates between different users and titles,
something the existing mocks in WatchActionTest and
WatchlistManagerTest did not.

Change-Id: I487354542f5322478b9e2c0383cad86453bd5f3e
2021-05-03 19:04:06 +00:00
jenkins-bot
736a8e1f9b Merge "Reduce duplication and combine methods in UserAuthorityTest" 2021-05-03 18:51:23 +00:00
DannyS712
9c971f6842 Reduce duplication and combine methods in UserAuthorityTest
Change-Id: I05fccad6b84943e20b5f6210e519c0b000a11ea4
2021-05-03 16:25:13 +00:00
DannyS712
bea9165e61 Tests: use UserIdentityValue instead of mock User objects
- ParserMethodsTest for creating ParserOptions
- SimpleAntiSpamConstraintTest

Change-Id: I5f8ffbee5ee1ff8e08cae7e6ace30ff7b186539c
2021-05-03 15:41:48 +00:00
DannyS712
1ec3ee8ded Move WikiReferenceTest to a unit test
No integration is needed or used

Change-Id: Ia61e55be3b3069d75188ad2caf3bba6db09e230f
2021-05-02 10:00:52 +00:00
Kunal Mehta
ec0be22116 Update Legoktm's email address
Change-Id: Icd58c93bb0cff5b0a4e7b7f02873a271bab8964f
2021-05-02 05:39:37 +00:00
Aaron Schulz
889a37f8c3 rdbms: Use server time in DatabaseMysqlBase::getLagFromPtHeartbeat()
The avoids problems stemming from clock skew among app and db servers
along with problems caused by per-request clock drift.

Bug: T248481
Change-Id: Ifb3db110ddf8f209e0e19126abeb44437dee3768
2021-04-30 15:29:36 -07:00
DannyS712
7bd7d2a6c1 Remove hooks that use Revision objects
All hooks were previously hard deprecated
in 1.35. Affected hooks:
* ArticleRevisionUndeleted - use RevisionUndeleted
* ArticleRollbackComplete - use RollbackComplete
* DiffRevisionTools - use DiffTools
* DiffViewHeader - use DifferenceEngineViewHeader
* HistoryRevisionTools - use HistoryTools
* NewRevisionFromEditComplete - use RevisionFromEditComplete
* PageContentInsertComplete - use PageSaveComplete
* PageContentSaveComplete - use PageSaveComplete
* ParserFetchTemplate - use BeforeParserFetchTemplateRevisionRecord
* RevisionInsertComplete - use RevisionRecordInserted
* TitleMoveComplete - use PageMoveComplete
* TitleMoveCompleting - use PageMoveCompleting
* UndeleteShowRevision - no replacement

Includes a fix for setting the associated rev id
of page protections, which previously was only done
using $nullRevision which was a Revision object created
if any hooks needed it; those hooks were hard deprecated
and so for WMF prod the rev id was not being set.

Bug: T247143
Depends-On: Idfa345193ae99fb2f1c9a8f8d28d8d540a6e3d62
Change-Id: I519167f76a5a3c1f5410415b2721462a3dcc3ec8
2021-04-30 17:28:20 +00:00
James D. Forrester
64898405cb build: Upgrade mediawiki-codesniffer from v35.0.0 to v36.0.0
Change-Id: I8905d0d69738a1cd6997c104080fdf128d315e8b
2021-04-29 13:00:15 -07:00
jenkins-bot
23d5d441c9 Merge "Replace uses of DB_MASTER with DB_PRIMARY" 2021-04-29 19:04:17 +00:00
jenkins-bot
943926c0a8 Merge "rdbms: remove whitespace padding from IDatabase::conditional()" 2021-04-29 18:58:00 +00:00
jenkins-bot
acb29985a2 Merge "Parser: remove Title from method signatures" 2021-04-29 18:28:28 +00:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
daniel
4880a82555 Parser: remove Title from method signatures
Bug: T281068
Change-Id: I3280e38dd82d71845c343eeb911e71dd33bb380b
2021-04-29 18:11:46 +02:00
jenkins-bot
bfb21cb176 Merge "Give WikiAwareEntityTrait it's own unit tests." 2021-04-29 12:18:37 +00:00
DannyS712
ed4a87614b Simplify and clean up WatchedItemStoreUnitTest
- Use ->createMock() instead of a mock builder where possible
- Use ->willReturnCallback()
- Add some whitespace for readability
- Fix documentation regarding returning mocks

Change-Id: I0807ec9134e5e6f4a87dd0f4afa85816f43b64d3
2021-04-28 18:52:38 +00:00
jenkins-bot
e8b51af724 Merge "Add GetAllBlockActions hook" 2021-04-28 17:13:37 +00:00
jenkins-bot
9ceff3ed5b Merge "Remove ApiUnblock unit test." 2021-04-28 16:15:15 +00:00
STran
df89e2fb49 Add GetAllBlockActions hook
Call onGetAllBlockActions to add to the blocked actions array.
This allows extensions to define blockable actions.

Bug: T279562
Change-Id: Ia72fdabba1dcca0e2f71e4c09400453295f0e05c
2021-04-28 08:59:18 -07:00
jenkins-bot
9c269ae3b8 Merge "Add change tags for media additions/removals" 2021-04-28 15:13:34 +00:00
Tim Starling
fd01c53778 Stop using legacy ActorMigration field "rc_user"
Bug: T278917
Change-Id: I4d6c175c637a2cb26c63e0b2b27d5ea8ce6b1e0d
2021-04-28 16:29:04 +10:00
Petr Pchelko
ccd4b6d98b Give WikiAwareEntityTrait it's own unit tests.
Change-Id: I7f3b9e58a3d0ff4aeb1315c16d3cf91b79530095
2021-04-27 20:31:14 -07:00
jenkins-bot
a8196f5904 Merge "Introduce infrastructure for partial blocks for actions" 2021-04-27 23:57:33 +00:00
jenkins-bot
123a0e25e7 Merge "LinkBatch: replace Title with PageReference in method signatures" 2021-04-27 23:12:29 +00:00
Thalia
c67f181dd4 Introduce infrastructure for partial blocks for actions
This adds a new type of block restriction for actions, which extends
AbstractRestriction. Like page and namespace restrictions, action
restrictions are stored in the ipblocks_restrictions table.

Blockable actions are defined in a BlockActionInfo service, with a
method for getting all the blockable actions, getAllBlockActions.

Action blocks are checked for in PermissionManager::checkUserBlock
using DatabaseBlock::appliesToRight. To make this work, this patch
also removes the 'edit' case from AbstractBlock::appliesToRight,
which always returned true. This was incorrect, as blocks do not
always apply to edit, so cases that called appliesToRight('edit')
were fixed before this commit. appliesToRight('edit') now returns
null (i.e. unsure), which is correct because it is not possible to
determine whether a block applies to editing a particular page
without knowing what that page is, and appliesToRight doesn't know
that page.

There are some flags on sitewide blocks that predate partial blocks,
which block particular actions: 'createaccount' and 'sendemail'.
These are still handled in AbstractBlock::appliesToRight, and are
still checked for separately in the peripheral components.

The feature flag $wgEnablePartialActionBlocks must set to true to
enable partial action blocks.

Bug: T279556
Bug: T6995
Change-Id: I17962bb7c4247a12c722e7bc6bcaf8c36efd8600
2021-04-27 21:53:13 +01:00
Petr Pchelko
f86e82a5a7 Remove ApiUnblock unit test.
The class already has decent coverage with integration tests,
and I couldn't find anything the unit test provides in addition.
The unit tests is trying to mock the world, which locks the
implementation in place - any attempt to change internals of
the API module breaks the test.

Change-Id: I3eabd089faab04710828a0bba37f112721f9f888
2021-04-27 13:37:13 -07:00
Aaron Schulz
f39f0384f3 rdbms: remove whitespace padding from IDatabase::conditional()
Change-Id: Ib3d808966f8ea7a29fd503b0727373dae153d0ec
2021-04-27 11:03:09 -07:00
Petr Pchelko
f50c097b9a Keep ActorStore caches consistent on user rename
Multi-key in-memory keys for the actors is complicated
enough to have it's own small abstraction.

Change-Id: Id0e091504b71a44ce52d418c5737d64ac70495e9
2021-04-26 14:02:00 -07:00
daniel
c829bfc8dd LinkBatch: replace Title with PageReference in method signatures
Bug: T278459
Change-Id: I7ed97f868f2a8a505ca4e529036d7efce6eea3ae
2021-04-26 19:54:24 +02:00
vladshapik
3a150275de Implement injecting of dependencies to an AuthenticationProvider
init() method was added to AuthenticationProvider. It helps to inject
dependecies. Overridable postInitSetup() method was added to
AbstractAuthenticationProvider. A provider can override this to do
any necessary setup.
AbstractAuthenticationProvider ::setLogger(), ::setManager(), ::setConfig(),
::setHookContainer() were soft deprecated. Now developers must use
AbstractAuthenticationProvider::init().

Bug: T275030
Change-Id: I6ca63eddac1b177eeadbdcce992e71c44a480160
2021-04-26 15:17:34 +03:00
Matthias Mullie
dab7b16741 Add change tags for media additions/removals
This introduces 2 new tags to track changes in media usage
across articles. These tags are both hidden & disabled by
default.

Bug: T266067
Change-Id: Ia230eadf7dcf6f52facab17b92293f25de38bb1c
2021-04-26 12:22:21 +02:00
jenkins-bot
846c4413c3 Merge "Fix NoWriteWatchedItemStore::countWatchersMultiple" 2021-04-24 08:03:24 +00:00
jenkins-bot
adb08649b9 Merge "Convert MWBasicRequestAuthorizerTest to a unit test" 2021-04-24 03:33:09 +00:00
jenkins-bot
68a6512ad3 Merge "Reduce mocking LoggerInterface" 2021-04-24 03:33:03 +00:00
jenkins-bot
d7dac1bf4a Merge "RevisionStoreFactoryTest: Clean up and convert to unit test" 2021-04-24 03:32:57 +00:00
jenkins-bot
7ae12627a6 Merge "Convert SlotRoleRegistryTest to unit tests" 2021-04-24 03:07:56 +00:00
DannyS712
12ffb90aa8 Convert MWBasicRequestAuthorizerTest to a unit test
Already essentially a unit test, does not use any integration

Change-Id: I705c9e5fb04103f305e26b7cd677cf68fc7b73b5
2021-04-23 23:35:09 +00:00
DannyS712
1d5bac66c4 Reduce mocking LoggerInterface
Use TestLogger when we want to ensure specific
logged messages, or NullLogger when we don't care

Change-Id: Ifebc770933d4f5313d5b8b43a52437dbe1e24432
2021-04-23 22:35:43 +00:00
DannyS712
260f4ea92c Move MimeAnalyzerTest under unit tests
Extends the base PHPUnit\Framework\TestCase
and does not need any integration

Change-Id: I221ffb9d2ed96e240ad1be7f11c311f95883d882
2021-04-23 21:53:55 +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
633ec93a8c Clean up WatchlistManager tests
Most of the code in WatchlistManager does not depend
on integration logic, with the exception of
- ::clearTitleUserNotifications adding a DeferredUpdate

- ::addWatch and ::removeWatch using
User::newFatalPermissionDeniedStatus, which uses
MediaWikiServices

Move the majority of the rest to the unit tests, except
for an integration test of the overall basic functionality
that we leave to make sure that the integration with the
actual services works properly.

Also take this opportunity to document why the integration
tests left behind need to be integration test, and fix
the name of some tests to addWach/removeWatch instead of
the old doWatch/doUnwatch.

Explicitely add 'watchlist' to the tables used by the
integration test.

Change-Id: I899ef1618c59c179ed2591149b93969fd935276d
2021-04-23 17:19:34 +00:00
DannyS712
1acd9531d3 Fix NoWriteWatchedItemStore::countWatchersMultiple
Should call the same ::countWatchersMutiple on the
actual store, not ::countVisitingWatchersMultiple

Has been broken since NoWriteWatchedItemStore was
first introduced, see 1ff58fc746

Change-Id: I20ab9a130f5bfe8b888ad08ea5852f13a03184f8
2021-04-23 15:27:56 +00:00
jenkins-bot
89b00fcfbe Merge "Remove unnecessary ->equalTo() from tests" 2021-04-23 14:43:04 +00:00
Thiemo Kreuz
c1ee8250e9 Remove unnecessary ->equalTo() from tests
This is the default anyway when using ->with(). The test code
becomes so much more readable without this, I would like to
argue. Let it just say "with these values".

Because of the way I split my changes into multiple patches
there are a few other changes in this patch I could not split,
e.g. removing unnecessary ->any(). This is the default anyway
and doesn't make the test more specific.

Change-Id: I34990799fa9258ba8dc64c7e78ec43f7903b7681
2021-04-23 12:02:42 +02:00
Thiemo Kreuz
b95a07380a Remove meaningless ->expects( $this->any() ) from all tests
It is not entirely meaningless. It might be an indicator that
the number of calls to a method is intentionally unlimited.
This is similar to e.g. an @inheritDoc PHPDoc comment that
marks a method as being "intentionally undocumented".

However, what's the meaning of being "intentionally
unconstrained"? Let's just not have any constraint then.

I feel all these ->expects( $this->any() ) bloat the test
code so much that it's never worth it.

Change-Id: I9925e7706bd03e1666f6eb0b284cb42b0dd3be23
2021-04-23 11:58:58 +02: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
jenkins-bot
b57ace7aee Merge "Replace PHPUnit ->returnValue() with ->willReturn() shortcut" 2021-04-22 15:47:14 +00:00
jenkins-bot
29604272e8 Merge "Remove some meaningless $this->equalTo() from tests" 2021-04-22 15:47:04 +00:00