Commit graph

145 commits

Author SHA1 Message Date
Dan Duvall
9778adf1c5 Refactor SettingsBuilder to use BagOStuff.
Removed use of Psr\SimpleCache\CacheInterface in favor of BagOStuff, as
the latter is a tried-and-true abstraction and the former offers no real
upfront benefits since the caching patterns of SettingsBuilder are quite
basic at this time.

The simplicity of cache interface use is largely in part to the minimal
probabilistic stampede protection implementation within CachedSource
which is left untouched by this change.

Bug: T294748
Change-Id: Ie59b37a8d5c7bf96225757fa9eb9d2c762476713
2021-12-10 10:20:05 -08:00
jenkins-bot
4c5102cc28 Merge "tests: Add structure test for bundlesize.config.json" 2021-12-09 09:42:41 +00:00
Alexander Vorwerk
bf56204a44 Remove the MediaWikiTestCase class alias
Bug: T293043
Depends-On: I53852a255ceeab8083d0f5354949929df6c55b96
Change-Id: I477c0dfcb7bbb53a9972ce6b48acb470118c1ace
2021-12-05 13:50:40 +00:00
Kosta Harlan
61e16d8ef8 tests: Add structure test for bundlesize.config.json
This is the same functionality provided by `npm test:size` in Minerva
and Vector skins, but as a structure test. Any extension/skin that
provides bundlesize.config.json containing an array of expected gzipped
sizes and module names will be processed by this test.

See also WikimediaMaintenance's blameStartupRegistry.php for similar
code.

Bug: T255149
Change-Id: Ieb7591f3c0ac843677a2a61b4ad47f920fc2ca2d
2021-12-01 14:12:33 +01:00
Dan Duvall
d83a7bcd09 Cache loading of SettingsBuilder sources
The `SettingsBuilder` now accepts a PSR-16 cache interface with which to
store and query settings before attempting to load from each source. By
default, no cache is used, but any object that implements the
`Psr\SimpleCache\CacheInterface` may be provided to the constructor.

An explicit dependency on "psr/simple-cache" has been added to
`composer.json`. Note that this dependency already existed in vendor
albeit it as a transitive one.

An APCu based `SharedMemoryCache` adapter is provided as a canonical
PSR-16 compliant interface for production use.

Sources are now queued by the `SettingsBuilder` when calling `load()`.
If a cache interface has been provided, and the source is considered
cacheable (implements `CacheableSource`), then it is wrapped as a
`CachedSource` which will query the cache first before loading from the
wrapped source.

Cache stampedes are mitigated using probabilistic early expiry. The
implementation for this was partially based on symfony/cache-contract
source code but also from the Wikipedia article and paper referenced
therein.

See https://en.wikipedia.org/wiki/Cache_stampede#Probabilistic_early_expiration

Bug: T294748
Change-Id: I52ab3899731546876ee58265bd4a1927886746dc
2021-11-29 12:54:59 -08:00
Petr Pchelko
92f3f1a944 Introduce MergeStrategies for ConfigSink
Change-Id: Ibb4fdf83d87ad204da5fbc4892c9b7610e979f72
2021-11-16 13:07:03 -08:00
Petr Pchelko
928f707731 Remove old HTTP request implementations
Since 1.34 setting non-default HTTP engine
has been deprecated. It's time to remove
the old implementations. Only Guzzle is
now available.

Change-Id: I978b75827e69db02cbc027fe0b89a028adfc6820
2021-11-08 07:04:06 -08:00
Tim Starling
f7f84dddb3 Introduce CommentFormatter
CommentParser:

* Move comment formatting backend from Linker to a CommentParser service.
  Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
  was used for.
* Rename the "autocomment" concept to "section link" in public
  interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
  static analysis and code review.

CommentFormatter:

* Add CommentFormatter and RowCommentFormatter services as a usable
  frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.

Linker:

* Remove Linker::makeCommentLink() without deprecation -- nothing calls
  it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
  commentBlock() and revComment().

Caller migration:

* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
  ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
  ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
  ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager

Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-09-28 11:13:03 -07: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
Daimona Eaytoy
6e4a17b1be Remove PHPUnit hooks
Now unused: https://codesearch.wmcloud.org/search/?q=onMediaWikiPHPUnitTest__(end%7Cstart)Test%7CMediaWikiPHPUnitTest%3A%3A(end%7Cstart)Test&i=nope&files=&excludeFiles=&repos=

Bug: T243600
Change-Id: Ie41fc026e6db6b9c9f5ec659e3ce8c27727cd3fe
2021-08-30 00:28:32 +02:00
Petr Pchelko
5038a66304 Merge RevisionStoreDbTestBase and McrRevisionStoreDbTest
Non-mcr storage is no longer supported, so there's no value
in keeping a superclass and a subclass.

Bug: T285460
Change-Id: I008ea30405dac990705966302a06c0957ffe497b
2021-06-28 08:55:38 -07:00
DannyS712
983984d5d4 EPIC: Remove the Revision class entirely
Following soft deprecation in 1.31, hard deprecation
in 1.35, and removal of remaining deprecated uses,
the entire Revision class, and the tests for it, can
now be removed. This will be followed by a patch to
clean up old references in comments - this is just
dealing with the code.

There were some other tests in RevisionDbTest.php
for Title::getNextRevisionID and Title::getRelativeRevisionID,
which could have been kept, but since those methods are
tested separately in TitleTest, no need to keep these, so
just remove the entire file.

Also remove the RevisionTestModifyableContent and
RevisionTestModifyableContentHandler classes that were
only loaded for use in RevisionDbTest - not sure how
the stable interface policy applies to classes that
are only loaded within tests, so mention that in the
release notes as a breaking change.

Bug: T247143
Change-Id: I05a297d28b85c7413384979f5c908be318098d9d
2021-06-10 15:57:44 +00:00
vladshapik
c0a16a41d7 Create SessionProviderTestTrait to facilitate testing of an SessionProvider
Create new SessionProviderTestTrait and
SessionProviderTestTrait::initProvider method. Replace uses of
SessionProvider::init with new method in tests.

Bug: T283709
Change-Id: I2770188faf3e4f374f9df885ff4deff7189063fc
2021-05-26 20:45:05 +03:00
vladshapik
f4627f064c Create AuthenticationProviderTestTrait to facilitate testing of an AuthenticationProvider
Create new AuthenticationProviderTestTrait and AuthenticationProviderTestTrait
::initProvider method. Replace uses of AbstractAuthenticationProvider::init with new method in
tests.

Bug: T282781
Change-Id: Ie65c7558bfbacbf6678eea77e4a9b2cf68026456
2021-05-25 16:14:39 +03: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
DannyS712
ec3d351c62 Move most ParamValidator tests to unit tests
No integration needed, except for maybe in
the tests for the UploadedFile* classes, which
are left where they are for now - those tests
deal with the file system.

Change-Id: I4f38557d524b2d36dea36a926d0f31e1afed5c7a
2021-04-14 23:57:20 +00:00
DannyS712
612107b4cd Tests: move some non-tests to /mocks
Change-Id: I3d000922c945ea3a14391c9b539b099151f294eb
2021-04-14 07:16:05 +00:00
DannyS712
bd1ca06a5e Delete ObjectFactoryMakeContentHandlerWithSpecsToTest
Its a test for the ObjectFactory code that is underlying
the ContentHandlerFactory class, but that code is already
tested elsewhere extensively - these tests add nothing
for the library, and don't cover the actual ContentHandlerFactory
code either.

Change-Id: I74a141d592a2582be8f6b2b81a392e5eebc27ec4
2021-03-28 14:03:46 -04:00
Daimona Eaytoy
8176dac4a6 phpunit: Remove MediaWikiPHPUnitTestListener
The two hooks were moved to a PHPUnit extensions which uses hooks. The
rest was simply deleted. The reason for this change is that TestListener
was removed in PHPUnit 9, with PHPUnit hooks as replacement.

No hooks exist for startSuite/endSuite, plus we should avoid adding too
much functionality: if the output of PHPUnit isn't clear, that should be
reported upstream. Additionally, PHPUnit hooks were also deprecated in
PHPUnit 10, which means that extending PHPUnit becomes more and more
difficult. As such, the two hooks will be hard-deprecated & removed
soon.

Removing all these wfDebugLog and other function calls should also
hopefully speed up the suite.

Bug: T243600
Bug: T225730
Change-Id: I2b67cd0074aca4b0ea76696ce9f24be68f5f88f8
2021-03-20 15:55:26 +01:00
Petr Pchelko
7955db4d8d Convert MovePage to Authority
Change-Id: I7d4503711ab1b739ca88b5fd0aa9e336cbac06aa
2021-03-17 19:43:46 -06:00
DannyS712
00de47a1d6 TestsAutoLoader: remove ContentHandlerTest
Not extended or used by any other tests

Change-Id: Ic23e666216f9974ed0a3665c8b75debe667cee32
2021-03-14 21:24:08 +00:00
jenkins-bot
ff88aec2fb Merge "Remove unused MockWebRequest from tests" 2021-03-14 17:31:07 +00:00
DannyS712
8266c981e8 Remove unused MockWebRequest from tests
Change-Id: Ia0c3df5cf868d2702b05708c6d84bee2ec5fb638
2021-03-14 09:50:22 -07:00
DannyS712
2c1a051da9 TestsAutoLoader: remove BadFileLookupTest
Not needed for any other tests

Change-Id: I504a06ee18801f2070758c50cfc2730e92852bb3
2021-03-14 05:59:06 +00:00
jenkins-bot
3d17655469 Merge "Convert (Mutable)RevisionSlotsTest classes to unit tests" 2021-03-12 16:36:01 +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
DannyS712
6e82d0f256 Decouple CssContentTest and JavaScriptContentTest
Hopefully without reducing code coverage

Change-Id: Ib292450eff8296cd788b4bcce2ef8c4670c75a9c
2021-03-09 18:10:45 +00:00
Petr Pchelko
87a5cb4673 UserQueryBuilder: abstraction for actor table queries.
This introduces a specialized SelectQueryBuilder for
queries related to actor table. So far it's fairly basic,
but in future it is intended to grow.

This patch only introduces the new abstraction, using
it will be separated into separate patches.

Bug: T274223
Change-Id: Ibb1c58016e3956a46bfaf1a9f51f265114bb9ace
2021-02-22 11:47:07 -07:00
Reedy
eb41565a9a Tests: Start marking some closures as static
Bug: T274036
Change-Id: Ib738ecd3bc23d34900bc268c8246702ac3655746
2021-02-06 19:57:42 +00:00
Petr Pchelko
1fb76fefbb Change RevisionStoreCacheRecord callback signature
In order to convert the tests into tru unit tests.

Bug: T272669
Change-Id: I6055b43381fdcc6dcdf69e9311979db0dccdb16b
2021-01-26 15:14:35 +00:00
Petr Pchelko
30735541f4 Make vast majority of RevisionRecord tests unit.
Change-Id: Icc94fbd7090ee5f73fc1fba353ff7c936436f76f
2021-01-22 19:04:58 +00:00
Petr Pchelko
10de1d3472 Introduce MockAuthorityTrait for Authority test helpers
Change-Id: I152f2cbe8a7000eedc237fb46b4e4c6d2f9730d4
2021-01-21 20:19:12 -06:00
Petr Pchelko
3a2e8883b4 Rest: use Authority in all core handlers
Bug: T239753
Change-Id: Idf2229255f49514dd8b68bf63573c5b619b4f2f1
2021-01-21 18:22:33 -06:00
DannyS712
e19774125a Remove UserWrapper class from tests, not used
https://codesearch.wmcloud.org/search/?q=UserWrapper&i=nope&files=&excludeFiles=&repos=

Change-Id: I38380cdf647295ad9197939b6ff0b9302d2869b4
2021-01-21 05:26:16 +00:00
jenkins-bot
e47b3bc655 Merge "Split title mocking methods out of HandlerTestTrait." 2021-01-18 17:08:11 +00:00
jenkins-bot
e63675f1cf Merge "exception: Add test for MWExceptionHandler trace formatting" 2021-01-14 23:36:37 +00:00
Timo Tijhof
f7e8bc6a69 exception: Add test for MWExceptionHandler trace formatting
Change-Id: I00b9607ba7e17c1f75ef065e83b83d2e1a82870c
2021-01-13 23:26:48 +00:00
Petr Pchelko
7854dd5fc9 Split title mocking methods out of HandlerTestTrait.
The functionality of creating title mocks is generally useful
and this will also allow to make HandlerTestTrait more narrow.

Bug: T264058
Change-Id: I76eca48dfcff65a6203fccde5366912a2d66c495
2021-01-13 12:46:10 -06:00
Daimona Eaytoy
6426479063 Add HookRunnerTestBase for use by extensions
Bug: T271620
Change-Id: I3642a7b1953cef03bd3ddc4a6b47c4d3c4c0ef4a
2021-01-10 11:17:31 +00:00
C. Scott Ananian
71aa8e0e0d Add support for running parsertests with Parsoid in integrated mode
This allows us to move Parsoid-specific extension code from the
Parsoid repo into the extension's own repository and still have
Parsoid parser tests run on it via core's mechanism for running
extension tests.

Factored out some common ParserOptions setup into a common helper
function.  There are a number of features still missing from the
Parsoid test runner, which are marked with @todo comments and
phab task numbers.

Bug: T254181
Change-Id: Ifaf53862b96e9127d8f375ad8dd0cc362cba9f5b
2020-12-23 15:50:50 -05:00
daniel
ed41864370 Extract PoolWorlArticleViewCurrent
Extracts a specialized subclass for rendering the current revision
from PoolWorlArticleView, which then no longer knowes about caching.

In the next step, we will add a subclass that implements caching for old
revisions.

Bug: T267832
Change-Id: I56fb365962951e6c723a01cf9243dbc0094b5581
2020-11-17 20:17:02 +01:00
Petr Pchelko
7c68ae9296 Safe ParserOutput extension data and JsonUnserializable helper.
One major difference with what we've had before is that now we
actually write class names into the serialization - given that
this new mechanism is extencible, we can't establish any kind
of mapping of allowed classes. I do not think it's a problem
though.

Bug: T264394
Change-Id: Ia152f3b76b967aabde2d8a182e3aec7d3002e5ea
2020-11-10 11:21:09 -07:00
Petr Pchelko
017cfcf016 Forward-compat for merging CacheTime and ParserOutput mOptions
CacheTime::mUsedOptions and ParserOutput::mAccessedOptions
do exactly the same thing and has to be merged into a single property.
This patch adds forward-compatibility and needs to be deployed
at least one train before the patch which actually merges the properties.

Change-Id: Ic9d71a443994e2545ebf2a826b9155c82961cb88
2020-11-10 07:09:41 -07:00
DannyS712
cc8bab4111 Add PageSizeConstraint and ChangeTagsConstraint
Bug: T157658
Change-Id: I2c7b4f77cd07c72b42eaeb7e37095461c92b367a
2020-10-28 16:03:02 +00:00
DannyS712
05ae763ba2 EditPage: Migrate more checks to constraint
Add
- ContentModelChangeConstraint
- EditRightConstraint
- ImageRedirectConstraint
- ReadOnlyConstraint
- UserBlockConstraint
- UserRateLimitConstraint

Additionally:
- Split EditPageTest into a separate file for
all of the constraints being tested

- Add a helper EditConstraintTestTrait

- Add debug logging for EditConstraintRunner for
the result of each constraint

- Changed the order of some of the checks, which
may result in a different failure code if multiple
checks were going to fail, but shouldn't change the
overall result of whether an edit fails or not.

Bug: T157658
Change-Id: Ib8f8b62b9928544e5559c96d82bf850dd8cf9b05
2020-10-26 22:01:05 +00:00
Daimona Eaytoy
d516961f30 Drop PHPUnit4And6Compat and PHPUnit6And8Compat
MW 1.35+ only supports PHPUnit >= 8.5; these traits can now be removed
as previously advertised.

Bug: T192167
Change-Id: I84694e32c06f1f0f9fb8398b1f2b92d3df599ddb
2020-10-16 19:08:48 +02:00
jenkins-bot
f49aec0b32 Merge "Re-apply: "PHPUnit: prevent HTTP requests"" 2020-10-12 13:14:52 +00:00
Daniel Kinzler
aea8cb17bd Re-apply: "PHPUnit: prevent HTTP requests"
This reverts commit c17ddfd786.

This time, also: Trying to get mock http to work in parser test

Bug: T262443
Change-Id: Id708cdfa3d3c27f30543c6bf212df96e6b0a69e1
2020-10-09 16:19:31 +02:00
daniel
6eea7d7ed5 Add test infra for ParserCache serialization/deserialization
Based on Daniel's work at Ia6e70179b7ee5ce4e93888585ccc30d92da165c3
however was changed enough to move into a separate changeset.

More acceptance tests and data will be added in a followup commit.

Bug: T264397
Change-Id: I135187e83cbfa02b97c5656f0752f8bf1ceb58d0
2020-10-09 08:14:57 -06:00
daniel
383a6e2a42 Introduce MockHttpTrait
MockHttpTrait can be used by tests that need to simulate HTTP requests.

Bug: T262443
Needed-By: I1832cb1858ef4cf42ec34cb7fda509ce5b951c27
Needed-By: I390856b4609635cee22253071f21ce63ff716791
Needed-By: Iff24b55dfaf7a4e02a4c80aaeaf0366de5660ef1
Needed-By: Ia8213725839e4b697c4985060bc35593fea622bc
Change-Id: I8ce17da7315b87b8dd0e502e601b9ac488089456
2020-09-28 20:28:43 +00:00