Commit graph

108 commits

Author SHA1 Message Date
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
DannyS712
26dec11987 Use DummyServicesTrait::getDummyNamespaceInfo in more places
Make it possible for callers to override config as needed

Change-Id: I54e7ba8d56d7d168248aca85c2e4e973b012806a
2021-05-05 01:53:30 +00:00
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
jenkins-bot
ae45776905 Merge "MockTitleTrait: clean up makeMockTitle" 2021-05-03 22:46:29 +00:00
DannyS712
89fa7401e3 Expand functionality of MediaWikiTitleCodec in MockTitleTrait
Add support for full interwiki handling, and then use this
service in UserNameUtilsTest as a step towards making
that test a full unit test

Change-Id: I3b54909e33e69fea8bb5ec55c99848c196859185
2021-05-03 20:33:36 +00: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
450174b7a5 MockTitleTrait: clean up makeMockTitle
Don't mock Title::getContentModel() twice:
The first time, its either $props['contentModel'] or falling
back to CONTENT_MODEL_WIKITEXT, and the second was
just always CONTENT_MODEL_WIKITEXT - keep the first.

Update the documentation with latest supported options.

Add a todo about ::getPageLanguage() returning 'qqx' by default,
it should be returning a Language object

Change-Id: I715e46ecc56288be5f8cbd8672ffe051b2c3f8d9
2021-05-03 16:40:54 +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
daniel
c1eb74603a Remove Title from public interface of OutputPage
Bug: T278459
Change-Id: If455682540faf8d42fd8a14e0ef09bac24f72db4
2021-04-16 10:01:56 -07:00
jenkins-bot
37ab31298c Merge "Remove $actor field from UsererIdentityValue" 2021-04-14 14:40:12 +00:00
DannyS712
612107b4cd Tests: move some non-tests to /mocks
Change-Id: I3d000922c945ea3a14391c9b539b099151f294eb
2021-04-14 07: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
Cindy Cicalese
7572a698ea Fix comparison operator for isAllowedAll
Change-Id: Ief3d55e2e2bc5912c0885f892d640cb7e1919958
2021-04-07 12:20:09 -04:00
Cindy Cicalese
a78184782f Convert WatchedItem et al to PageIdentity
Change-Id: Iddcd109b7f78efdbcb0e4016e81fd2c8d4666b46
2021-03-26 15:51:19 -04:00
jenkins-bot
fc746109e4 Merge "phpunit: Don't redefine methods in traits" 2021-03-24 19:48:57 +00:00
daniel
8ba4aad647 Introduce PageStore
PageStore is unused so far, usage will be demonstrated in follow-up
patches.

For now, this only implements the lookup (read) functionality of
PageStore.

Bug: T195069
Change-Id: I25cb9945795ecaf2d0b816a5abc7362424d11ba4
2021-03-23 15:20:03 -06:00
Daimona Eaytoy
4877132223 phpunit: Don't redefine methods in traits
The signatures of these methods will change in PHPUnit 9, and in
general, having these methods means additional code to maintain. Since
this is test code, any attempt to use these traits from a class which
doesn't have the required methods will fail hard, and as such, there's
no reason to have these methods at all.

Also, MockServiceDependenciesTrait was redeclaring fail() as a
non-static method, but it is actually static in the parent class, which
makes tests fail on PHP 8.

Bug: T243600
Change-Id: I78bf1bdd2eb2e09aed27d1b6bff2302e28600703
2021-03-23 12:59:34 +00:00
Petr Pchelko
7955db4d8d Convert MovePage to Authority
Change-Id: I7d4503711ab1b739ca88b5fd0aa9e336cbac06aa
2021-03-17 19:43:46 -06:00
DannyS712
8266c981e8 Remove unused MockWebRequest from tests
Change-Id: Ia0c3df5cf868d2702b05708c6d84bee2ec5fb638
2021-03-14 09:50:22 -07:00
Petr Pchelko
eb5eca11b6 Deprecate constructing revision with non-proper page
Bug: T275531
Change-Id: If641a5a901210ba1a1ea6a41fa6a18c08f4183db
2021-03-10 22:05:06 +01:00
Petr Pchelko
ea185c872e Rename Authority::getPerformer() to ::getUser()
We started to call Authority argument $performer everywhere,
and $performer->getPerformer() doesn't look that good.

Change-Id: Id2cf3f27b18340314e4ed1ea9931ad9404b4df6f
2021-03-04 12:45:28 -07:00
Petr Pchelko
7e799cc7f5 Convert RecentChange::doMarkPatrolled to Authority
Change-Id: If93d6133f61bf0801bbe979885e2fb120e01a33d
2021-03-03 20:23:56 -07:00
Petr Pchelko
595d605e34 Convert EditConstraints to Authority
Bug: T271977
Change-Id: I12a2f71f52a1ba7e94bf325621e62ed0e255601b
2021-03-03 17:12:07 -07:00
Petr Pchelko
bb990c7e94 Convert skin code to Authority where ready
Change-Id: Ie530051d7abb3137e0e79114cb01dbb129ae0fe0
2021-02-23 21:04:19 -07:00
Petr Pchelko
375e9f0a68 Rename Authority::getActor to Authority::getPerformer
Bug: T274947
Change-Id: I8f652816af00bf9fa413ba4b1fa7ac4c27290dc2
2021-02-22 14:53:21 +00:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Reedy
eb41565a9a Tests: Start marking some closures as static
Bug: T274036
Change-Id: Ib738ecd3bc23d34900bc268c8246702ac3655746
2021-02-06 19:57:42 +00:00
Peter Ovchyn
d8f54cae8b Language: Turn public properties into Getters in LanguageConverter based hierarchy
The main goal is to simplify the construction of the LanguageConverter and
avoid using constructors for derived classes.

In order to hard-deprecate removed property, DeprecationHelper::deprecatePublicPropertyFallback
was introduced.

Bug: T253834
Change-Id: Ib167982e4e872cfdf0fbcb78b7ca597f5ac8d60a
2021-02-03 15:17:42 +02:00
Lucas Werkmeister
766120ce92 Call TestCase::fail() more carefully in MockHttpTrait
If we directly pass [ TestCase::class, 'fail' ] as the callback for a
mock method, then the method will be called with whatever arguments the
caller tried to pass to the original method. Those arguments may not be
compatible with TestCase::fail()’s signature, which requires the first
argument to be a string (or absent). Use a custom callback first which
throws away any arguments before calling TestCase::fail().

Bug: T272998
Change-Id: I3514d3d29355a55a5ca10ccc22981e3972347f35
2021-01-27 15:58:52 +01:00
Lucas Werkmeister
f406c5872e Allow more calls in MockHttpTrait
Don’t fail the test immediately when createMultiClient() or
createGuzzleClient() is called – instead, return service instances that
will fail the test as soon as any method is called on them. This is a
bit friendlier for dependency injection.

Bug: T272998
Change-Id: I79f90ef028867920f6a228991eda59ed4aeadb62
2021-01-27 11:51:28 +01: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
816e02ae51 Convert RevisionRecord to Authority and PageIdentity
As we convert the RevisionRecord to using Authority,
we no longer need Title instances, so we can convert
that to PageIdentity.

Ideally, we'd part away from using Title at all, but:
1. For foreign wikis PageIdentity has stronger validation,
so calling PageIdentity getId() on Title will break things.
There's still a lot of code depending on lax Title guarantees,
so we keep it.
2. A lot of code still depends on Title, so we try to pass it
through even if we don't nesessarily need to, to save cost
on recreating it later on.

Bug: T271458
Depends-On: I287400b967b467ea18bebbb579e881a785a19158
Change-Id: I63d9807264d7e2295afef51fc9d982447f92fcbd
2021-01-21 13:37:01 -06: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
Umherirrender
86ea6965d3 Add missing @param/@return to MockHttpTrait
Change-Id: I38cb2e0e7f7a0f6a0199670f7aa56a1522d6628c
2020-12-19 07:21:51 +00: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
daniel
78e2089140 PHPUnit tests: prevent real Guzzle requests from tests.
Per I1702c11928f8760, tests should fail when trying to make a
HTTP request, unless they have explicitely defined the desired
response.

This patch implements the same behavior for the newly introduced
createGuzzleClient() method.

Bug: T263816
Bug: T262443
Change-Id: Ie3c2efb1387ecc5bc29ff1749cae4bb33e636e9f
2020-10-26 23:03:36 +01:00
Petr Pchelko
da05003b9b Include URLs when clocking HTTP requests.
For easier debugging.

Change-Id: I01660509316d2f68a56b0cbe8b9bcdd980cc287e
2020-10-15 14:19:05 -07: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
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
Thiemo Kreuz
fd7363a1e1 Fix broken PHPDoc comments that don't start with /**
Change-Id: I8db56ff0f73873864dde260e51adcd729aa74e94
2020-07-23 16:09:41 +00:00
Tim Starling
7f710a514a Fast stale ParserCache responses
If PoolCounter acquisition would block and a stale ParserCache entry is
available, deliver it immediately rather than waiting for the lock. This
should avoid PoolCounter contention on heavily edited pages.

* Add a fastStale pool option to toggle the feature. False by default
  but I'll set the default to true in a followup commit.
* Add a $timeout parameter to PoolCounter::acquireForMe() and
  acquireForAnyone(). This requires a simultaneous update to the
  PoolCounter extension.
* In the Redis implementation, use the requested timeout for blPop()
  but use the configured timeout for data structure cleanup and item
  expiry.
* Add a boolean $fast parameter to fallback() which tells the subclass
  whether it is being called in the fast or slow mode. No extensions
  in CodeSearch extend PoolCounterWork directly so this should not
  cause a fatal.
* Pass through the $fast parameter in PoolCounterWorkViaCallback
* In PoolWorkArticleView, use the $fast flag to decide whether to check
  the ChronologyProtector touched timestamp.
* Add $wgCdnMaxageStale by analogy with $wgCdnMaxageLagged, which
  controls the CC:s-maxage when sending a stale ParserOutput.
* Fix the documented type of the timeout. It really should be a float,
  but locks.c will treat non-integers as zero.

A simultaneous update to the PoolCounter extension is required.

Bug: T250248
Change-Id: I1f410cd5d83588e584b6d27d2e106465f0fad23e
2020-06-05 16:24:22 +10:00
Tim Starling
47a1619027 Remove terminating line breaks from debug messages
A terminating line break has not been required in wfDebug() since 2014,
however no migration was done. Some of these line breaks found their way
into LoggerInterface::debug() calls, where they mess up the formatting
of the debug log.

So, remove terminating line breaks from wfDebug() and
LoggerInterface::debug() calls.

Also:
* Fix the stripping of leading line breaks from the log header emitted
  by Setup.php. This feature, accidentally broken in 2014, allows
  requests to be distinguished in the log file.
* Avoid using the global variable $self.
* Move the logging of the client IP back to Setup.php. It was moved to
  WebRequest in the hopes that it would not always be needed, however
  $wgRequest->getIP() is now called unconditionally a few lines up in
  Setup.php. This means that it is put in its proper place after the
  "start request" message.
* Wrap the log header code in a closure so that variables like $name do
  not leak into global scope.
* In Linker.php, remove a few instances of an unnecessary second
  parameter to wfDebug().

Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
2020-06-03 12:01:16 +10:00
Reedy
ead6b1e53f Fix some PSR12.Properties.ConstantVisibility.NotFound in tests/phpunit/
Change-Id: I0f678049dc274f0cd29f543bb293c33da51d8529
2020-05-09 23:55:09 +00:00