Commit graph

93 commits

Author SHA1 Message Date
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
607dde7c0c permissions: Check cascade protection only if page can exists
No need to ask the database for special pages

Set valid title in tests to pass canExists check

Change-Id: Ic6db74cf671484db475a0a646b372c814ea41918
2023-02-10 20:11:07 +00: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
Umherirrender
c0794e1b6e Hard-deprecate User/PermissionManager group permissions lookup functions
- User::getGroupPermissions
- User::getGroupsWithPermission
- User::groupHasPermission
- PermissionManager::getGroupPermissions
- PermissionManager::getGroupsWithPermission
- PermissionManager::groupHasPermission

Bug: T325680
Change-Id: If9ae610037f049050c21ad0eab7bcb4d6e596f29
2022-12-21 21:15:00 +01:00
Umherirrender
c6fecd5ab0 tests: Replace assertEmpty with assertSame
assertSame avoids use of loose comparisons and
allows to check the expected type

Change-Id: If821d1be2bc1ff9f8b70968a339f33c7a8e8880a
2022-11-25 00:42:53 +01:00
Amir Sarabadani
bbe704b5c1 Reorg: Move some of request related classes to MediaWiki/Request
Redoing I5ea70120d74 but without moving WebRequest that caused issues
with phan-taint-plugin.

Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequestUpload

Bug: T321882
Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
2022-10-28 10:15:31 +00: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
Umherirrender
dee77e59a1 tests: Remove resetServiceForTesting after overrideConfigValues
overrideConfigValues is documented to reset services as well

Change-Id: Ie13a699f6cd912b912d34adb97704bab3cbdff2d
2022-07-27 23:08:27 +02:00
Lucas Werkmeister
f2f0201981 PermissionManager: reindex errors after filtering
If $ignoredErrors isn’t empty, the process of filtering out ignored
errors may have left holes in the array. This isn’t desirable; in
particular, PermissionsError expects the first element ($errors[0]) to
exist. Let’s reindex the array sequentially to avoid problems.

Change-Id: I023d83bf7f29117da9d5a9062c9edb8c60a7e547
2022-07-22 17:56:09 +02: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
bbaa4c25d9 tests: Use MainConfigNames constants on overrideConfigValue
Change-Id: Ieeefb88daf55a976883f6e20ef6881c89a7f7630
2022-07-12 19:34:54 +02:00
Derick Alangi
f00cd03580 tests: Make use of overrideConfig(Value|Values) where needed
As we slowly move away from using globals, overrideConfigValue()
and overrideConfigValues() were introduced as a way to override
test configs between tests.

Under the hood, it just calls setMwGlobals() which resets services,
so take note.

Part 1: Directories covered are: languages/, maintenance/, tests/,
structure/ and includes/Permissions/.

Depends-On: I618b16c6d99c94eb2e7edcf05e888a65f7156754
Change-Id: If56f7d10d79f3a9824a52091a2b544d8653dd7b6
2022-07-11 21:15:26 +01:00
Umherirrender
e00a52e6f5 Clean up line indent with mixed tabs and whitespaces
Change-Id: Ifcd15ecc4212d4ebfc26b2e18d6f1da47abf2a86
2022-07-09 22:21:53 +02:00
Timo Tijhof
2721c7a1d8 permission: Simplify @covers annotations in PermissionManagerTest
Also remove an unused variable, and convert one provider to generator.

Change-Id: I63e506f30ae334ceff9658c595e64a7e9ada5bbd
2022-07-07 18:22:13 -07:00
Umherirrender
047c184bfe tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Ibfccfe696f0b8bfda0b99abae324e60bbecef7d8
2022-07-06 00:44:00 +02:00
Reedy
88b3717b68 Tests: Fix some @covers statements
Change-Id: I0e11f3ffefa6bb3f72d96b9101a1950d1c1aa556
2022-06-06 01:02:39 +01:00
Gergő Tisza
2a171c15a3 Add tests for PermissionManager
Change-Id: Ibc3190dc45a30a7c002e82ee87611aec653eb45b
2022-05-08 22:49:42 +00:00
Tim Starling
28db3e6181 Don't consult ActionFactory for pages that can't exist
Since 65f89072e3, the Article constructor will throw if a page
can't exist, which means that the Action hierarchy cannot act on pages
that can't exist. So guard the Article construction in
PermissionManager::checkUserBlock(), by assuming that the relevant
Action has nothing to say about such pages.

Bug: T306358
Change-Id: I9fd1324f1df98e8adb9daf4d3e63eb00499bad8e
2022-04-29 08:54:29 -04:00
Tim Starling
6c1f5462f7 TempUser UI tweaks
* In PermissionManager, if a user is anonymous but temporary user
  creation is possible, grant elevated permissions at RIGOR_QUICK rigor
  level. This is mostly to make skins show "edit" instead of "view
  source" to anonymous users in the recommended permissions
  configuration.
* Present temporary users as if they are not logged in in various places
  in the interface: create/move permissions errors, login, preferences,
  watchlist, BotPasswords, ChangeEmail, ResetTokens.
* Show a warning on login/logout about loss of access to the temp
  account.
* On login, don't show the temporary name as a suggestion for the login
  username.

Change-Id: Id0d5ffa46c3ca5c7b30d540cedbaa528b682aa85
2022-04-26 14:34:08 +10:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Derick Alangi
45c692eeef Stop accessing members of the Title class publicly
For now, let's just proxy the title object and set the
interwiki but to make things nicer, we should not provide
a title via setUp(), we should use providers.

Bug: T275763
Change-Id: I761de85ae5a839e8a695b85ce0fd7200b498da22
2021-11-22 14:22:51 +00:00
Reedy
8c39aab84b Remove or replace usages of "sanity"
Bug: T254646
Change-Id: Ib192dc5704a14d02c7c374d0ab29bac55c5df24a
2021-11-21 19:35:49 +00:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00:00
Umherirrender
2e4ee47c3d Cleanup mixed space/tab line indent
Change-Id: I833052a656b1ce419c0929f6f0514f2a33c2c4cc
2021-09-04 00:52:31 +02: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
vladshapik
c7e6c67dc5 Hard deprecate User group methods
1) The following methods were hard deprecated:
- User::addAutopromoteOnceGroups
- User::getEffectiveGroups
- User::getAutomaticGroups
- User::getFormerGroups

2) User ::getGroups, ::getGroupMemberships, ::addGroup,
::removeGroup were replaced in the production code,
but they were not hard deprecated because of conflict
with UserRightsProxy class.

Bug: T275148
Change-Id: Ia69598316f5dc5dd9511f6112b5b13e1aa07575a
2021-07-23 15:00:16 +03: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
Roman Stolar
27a02ba901 Move the fallback to check the 'create' right into PermissionManager when we checking 'edit' right.
Update tests by new behavior

Bug: T272079
Depends-On: I5353d158efd317921995af12534f3ae5847e3bd8
Depends-On: Ib24ef9171566016e571850ff8519a59f8a08a400
Change-Id: I403f28750bf7570fc98e7b34bed38eae84ab4e16
2021-06-23 18:09:22 +03:00
Petr Pchelko
a43dcc7c2e Followup to DatabaseBlock constructor options deprecations
One case in a test dataProvider was forgotten, so CI didn't fail,
since it's a dataProvider.

Change-Id: I13ee03aab106f2d04555286c8ebc320930773f08
2021-06-05 07:31:28 -07:00
Roman Stolar
4613e36b97 Hard deprecated DatabaseBlock options 'byText' and 'by' with user ID
Bug: T283641
Change-Id: Id1444253b26605f4c68b4cbeb61dc2299ed8ac34
2021-06-04 17:33:48 +03:00
jenkins-bot
a7da1f26a8 Merge "Add partial action block tests to PermissionManagerTest" 2021-06-03 17:59:38 +00:00
Roman Stolar
67cc77312f Update DatabaseBlock construct option 'by' and 'byText' usage to use User Identity only
Bug: T283641
Change-Id: Ic6d4a6e10bda0115c87a85d8a9ddfd4098cd1373
2021-06-02 17:01:32 +03:00
STran
0052098f7e Add partial action block tests to PermissionManagerTest
- Add test for  partial block against 'upload'

Bug: T281492
Change-Id: I9606bfd0d0645212c62a1611af23ab6befbe1d71
2021-06-02 06:22:00 -07:00
Daimona Eaytoy
535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
Ended up using
  grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'

special-casing setMethods( null ) -> onlyMethods( [] )

and then manual fix of failing test (from PS2 onwards).

Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
2021-04-16 20:15:00 +02:00
DannyS712
19b835c80b PermissionManagerTest: use data providers
Plus remove some duplicate cases

Change-Id: Ifa8d79cf99cc4e99d76f93c72a0eb986bc57d97b
2021-03-29 20:37:29 +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
Thiemo Kreuz
b655f382db Remove broken/outdated @param/@throws tags from @dataProviders
My personal best practice is to not document @params when there
is a @dataProvider. I mean, these test…() functions are not
meant to be called from anywhere. They do not really need
documentation. @param tags don't do much but duplicate what the
@dataProvider does. This is error-prone, as demonstrated by the
examples in this patch.

This patch also removes @throws tags from tests. A test…() can
never throw an exception. Otherwise the test would fail.

Most of these are found by the not yet released I10559d8.

Change-Id: I3782bca43f875687cd2be972144a7ab6b298454e
2021-01-21 03:42:42 +00:00
Umherirrender
0347fd0631 Improve some function documentation in tests
Also fix some whitespaces

Change-Id: Ibed50a4f07442d3f299cf545c16f5dbb5f27a411
2021-01-14 22:13:55 +01:00
DannyS712
bb36474959 PermissionManager: Allow sysops to view deleted config pages
For specific actions that do not change the content of
pages, skip the additional permission checks required
for individual user configuration pages. This allows
sysops to view deleted content of such pages,
even though they cannot edit the page.

Bug: T202989
Change-Id: I02e820c818e9e58e6591ec412fc3eca9384e0bb2
2020-10-20 21:57:18 +00:00
DannyS712
8a77f601d1 PermissionManagerTest cleanup, part 5
Split unit tests into a separate class

Change-Id: I630d40b8093ff221337f47187246d9891adfaad6
2020-10-18 19:07:26 +00:00
DannyS712
cc6ac5030d PermissionManagerTest cleanup, part 4
Remove broken `testQuickPermissions` tests,
as well as the helper method `runGroupPermissions`
only used in those broken tests. Will follow-up
with the addition of working tests, splitting
to ease review since the new tests will
be very different from the old ones (eg using
a dataProvider)

Change-Id: I4aa9d4b5f8ac4ee74aae3282b221d0bbbb7276a4
2020-10-18 00:33:09 +00:00
DannyS712
b1a3a8149d PermissionManagerTest cleanup, part 3
Replace existing `testPageRestrictions` method,
which is `@group Broken`, with simpler tests with
direct access to `checkPageRestrictions` via TestingAccessWrapper

Change-Id: Iadd74c1bad95ecdbb89fd5835330a9c5f32432d0
2020-10-18 00:33:02 +00:00
DannyS712
d825cd16ca PermissionManagerTest cleanup, part 2
Rewrite tests for `checkUserConfigPermissions`

Replace `runConfigEditPermissions` with direct
access to the private method using TestingAccessWrapper

Change-Id: I05757a0d0249edf7dd39b8c21988f7fa88020b2b
2020-10-18 00:31:29 +00:00
DannyS712
8e68310e82 PermissionManagerTest cleanup, part 1
Right now its just reducing the number of calls to
MediaWikiServices::getInstance()->getPermissionManager()
to make the tests a bit more readable

This change should be a no-op

Change-Id: I97c9dd8d057dbb20d07c51a67e17f4734b13723f
2020-10-16 00:24:14 +00:00
Thalia
addb098c39 Deprecate DatabaseBlock methods moved to DatabaseBlockStore
Following 23c3c70d7f, soft deprecate the static methods on
DatabaseBlock that have been moved to DatabaseBlockStore:
* ::insert
* ::delete
* ::update
* ::purgeExpired

Update calls to the deprecated methods from core.

Change-Id: I1272eb978594fd4f386bda12cbc24131ad7d882f
2020-09-13 22:17:27 +00:00
DannyS712
77781b08c7 Add delete-redirect for deleting single-rev redirects during moves
A new user right, `delete-redirect`, is added (not given to anyone
by default). At Special:MovePage, if attempting to move to a single
revision redirect that would otherwise be an invalid target (i.e.
doesn't point to the source page), the user is able to delete the
target.

Deletions are logged as `delete/delete_redir2`, and the move is
then logged normally as `move/move`, mirroring current delete and
move logging.

To allow for separate handling by Special:MovePage,
MovePage::isValidMove now returns a fatal status `redirectexists` if
the target isn't valid but passes Title::isSingleRevRedirect.
Otherwise, `articleexists` is returned (as previously). Other callers
that don't intend to treat single revision redirects differently
should treat `redirectexists` the same as `articleexists`.

Currently, this deletion (like normal delete and move) cannot be
done through the move api. Since the deletion is only valid when
moving a page, unlike for normal deletion, deleting redirects with
this right cannot be done via the delete api either.

Bug: T239277
Change-Id: I36c8df0a12d326ae07018046541bd00103936144
2020-09-04 03:50:17 +00:00
DannyS712
94169ee873 Whitespace cleanup: Use tabs for indentation, avoid double spaces
Change-Id: I346073b59d283029bd6666356c62c81e687ea5e6
2020-06-27 07:53:07 +00:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00