Commit graph

73 commits

Author SHA1 Message Date
daniel
8c1c1ae35a Enable pig-latin variant for testing
Having pig-latin enabled per default in dev environments is convenient
for manual testing. More importantly, it will allow us to write
end-to-end tests for variant conversion.

Depends-On: I9dc2f743ac487b0f7cfb667150c0f6950d5e7fce
Depends-On: I85b66c85be3959d48a048733af17197bc4cf70af
Change-Id: Ia80ad33cbf5e311fa8b84bd765a8df8d156f4c38
2022-11-08 17:45:51 +05:30
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
Matthias Mullie
ea6c1ceebb Add preference to control Special:Search thumbnails
Bug: T320337
Change-Id: I828dcd3679a4869b3b58b05d7cdca6c9f8a45d3e
2022-10-17 13:48:12 +02:00
Roman Stolar
5f53f2a8a2 Replace usage of User::getOption
Update tests

Bug: T296083
Change-Id: Id209abd408a1fdecb0a39c0910b12d34458ed458
2022-08-19 21:21:36 +02:00
TheSandDoctor
da38639658 Remove deprecated $wgParser
$wgParser, deprecated in 1.32, has been removed.

Bug: T160811
Change-Id: Iaf09d3e158e1fee8c0f541695b6d9b4233033c81
2022-08-03 14:40:16 +02:00
Derick Alangi
5e8cd2c838
Migrate from setMwGlobals() to overrideConfigValue(s)
Change-Id: I3f167d0e7d59a5aa091c3095a7d96c889d6e7e78
2022-08-02 10:14:10 +01:00
Brian Wolff
ac5f8a793c Mock UserOptionsManager::getOption for php8.1
php8.1 is more strict where we can return nulls

Bug: T313663
Change-Id: I079ec2cc732d44710d2ba001f803d96134f0d6c0
2022-07-27 21:26:48 -07:00
Brian Wolff
04238e44e5 [php8.1] mock User::getTitleKey() in DeaultPreferencesFactoryTest
php8.1 doesn't appreciate the default behaviour of returning null.

Bug: T313663
Change-Id: I2cdfe385d094427c545695af57657c3a5db2ce81
2022-07-26 15:37:29 +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
Thiemo Kreuz
29aca66975 Fix visibility of setUp methods in tests
Change-Id: Iefc05b4f4a9c258a385a22fc8d87b29648900e44
2022-05-17 14:11:22 +02:00
Tim Starling
13c1839735 Fix SignatureValidatorFactory circular dependency
Parser is using the service container to get a SignatureValidator
because, as noted in Gerrit comments on the relevant commit, there is a
circular dependency Parser -> SignatureValidatorFactory -> Parser.

So, have SignatureValidatorFactory::__construct() take a closure which
returns a Parser, instead of an actual Parser or ParserFactory.

Change-Id: I7bf4660f84ec8c8fb1d5b3b8581fe5d82bc3156e
2022-04-13 12:38:00 +10:00
Func
983b16d092 phpunit: Fallback to global default user options
The real option manager would do such fallback, this behavior should
be kept in tests.
(Depends-On I814050cfa86ec1e86291d380843eb319fddc924a)

Bug: T297082
Change-Id: I55f7d1e17bde904f2245b31df2df853cf0ca803f
2022-03-30 13:17:10 +00:00
Alan Thomas
f003b125ba Allow the user to set a default number of search results
Bug: T215716
Change-Id: I2b355f7830b24f7353a7e7f9e102d5be77b534d6
2022-02-20 22:09:47 +11:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
bwang
0dcbe84184 Update skin ordering to prioritize skins set through a new config
Bug: T298933
Change-Id: Ic957421617b519bd8160be475ac538b0944a8da9
2022-01-26 23:59:41 +00:00
Derick Alangi
11f2064333 preferences: Introduce SignatureValidatorFactory service
Change-Id: Ib8df0e76b81c8f3ad592f1caa3be86ac3597a0cf
2021-12-14 12:10:32 +00:00
Kosta Harlan
67e88c00cc phpunit: Mock session object for user in DefaultPreferencesFactoryTest
Depends-On: I6c7216611ce5ca65eda589a1a07014c9ce007957
Bug: T297082
Change-Id: Ie1ad9cf71129bcadbe1de6cd82f2662998941ba1
2021-12-06 08:44:50 -05: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
DannyS712
2915e0bbbf DefaultPreferencesFactory: inject and use UserOptionsManager
Inject a UserOptionsManager instead of UserOptionsLookup, and
update deprecated calls to user options methods

Bug: T277600
Bug: T277818
Change-Id: Ifdf491c3fd6b5b16246f33012f1db21f2cbc1f3e
2021-06-17 17:27:40 -07:00
DannyS712
fcad1b9e44 DefaultPreferencesFactory: inject all services needed
Inject LanguageConverterFactory, Parser, and SkinFactory,
plus remove use of UserOptionsLookup from MediaWikiServices
in favor of the existing injected one

Change-Id: Id8635a7a982f84828f3c0ba71f8446dd3d666a25
2021-06-04 23:51:59 +00:00
DannyS712
7c59cb3a8a DefaultPreferencesFactory: inject a UserGroupManager
Has a fallback in case one is not provided, so as to not
break the GlobalPreferences extension

Includes fixing the expectations in the tests
for the underlying code in testUserGroupMemberships

Change-Id: Ia539e48c305787f7e2a9a3a0b42891b7a8e2912b
2021-06-02 19:06:27 +00:00
jenkins-bot
c60ccf4e6d Merge "preferences: Move complex creation of infos for usergroups into closure" 2021-05-27 19:52:04 +00:00
DannyS712
779bd0aae8 Migrate DefaultPreferencesFactory to authority
Use authority methods instead of the injected PermissionManager;
not removing the PermissionManager yet since it would break
the GlobalPreferencesFactory which extends the class

Change-Id: Ia804fa7e536d0746f49f51792a48af9f4834183c
2021-05-26 06:39:45 +00:00
Umherirrender
215431bfd4 preferences: Move complex creation of infos for usergroups into closure
The HTMLInfoField allows the default part to be a closure.
This delays the message parse until the messages are needed on a gui.
This avoids the message parse on save or api calls and hopefully makes
that faster.

The message prefs-memberingroups is now parsed as all the other label
messages. This is another fix as done for T142882 / 116063f

Bug: T58633
Change-Id: I860501fe3df1ee330460f04ffe8493dd16421c8d
2021-05-25 18:17:37 +02: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
6c4c09c715 DefaultPreferencesFactoryTest: add helper for PermissionManager
Change-Id: If852c3de90513a0b6e103e89661c1d1c38611ab6
2021-05-03 16:24:21 +00:00
vladshapik
9cc797695b Hard deprecate User ::isIP, ::getOptions
Bug: T275602
Change-Id: Id4be13751ca0a900e51214c1855a4624077a5a62
2021-04-26 16:10:24 +00:00
Bartosz Dziewoński
444e28f907 Check for line breaks in user signatures
Bug: T272322
Change-Id: Ieac8be8839915a1ec4d547c2fc15d5fa9b27aca9
2021-04-23 19:55:38 +00: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
jenkins-bot
b57ace7aee Merge "Replace PHPUnit ->returnValue() with ->willReturn() shortcut" 2021-04-22 15:47:14 +00:00
Thiemo Kreuz
f10f4e05de Remove some meaningless $this->equalTo() from tests
This is the default behavior anyway when using ->with().

Change-Id: I64b6474280eb7da122eb22fc0afa28cca81e96c5
2021-04-22 10:47:54 +02:00
Thiemo Kreuz
40764d277c Replace PHPUnit ->returnValue() with ->willReturn() shortcut
It's the same and makes the test code much more readable, I
would like to argue.

Because of the was I split all the changes I made into smaller
patches this patch contains some other changes in the same
lines where I could not split them off. E.g. removal of
->any(), which is the default anyway and doesn't do anything.

Change-Id: Ib297b989d4aec33b31a4e33fe9d5032865b39be0
2021-04-22 10:37:45 +02:00
Peter Ovchyn
45140daa29 Avoid using User ::getDefaultOption, ::getDefaultOptions
This patch hard-deprecates the methods above

Bug: T276035
Change-Id: Ic36b0702f7547acce0d162d6e0b54bbd4ecf4d81
2021-03-16 17:24:17 +02:00
Umherirrender
7691dbeca9 Add missing @param and @return to documentation in tests
Change-Id: Ic663e81cca0bf007804a70772250914a85f1fef4
2021-01-22 19:57:25 +01:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00
jenkins-bot
3ea0a9068a Merge "preferences: Signature validation (lint errors, user links, nested subst)" 2020-06-24 22:14:57 +00:00
Bartosz Dziewoński
df7231ad89 preferences: Signature validation (lint errors, user links, nested subst)
Three new checks are now applied to user signatures in preferences:

* Disallow invalid HTML and lint errors (T140606)

  Since 15e0e9bb4b we can rely on Parsoid to check the signature for
  lint errors. (The old PHP Parser doesn't have this capability.)

  Most importantly, this will disallow unclosed HTML tags. Unclosed
  formatting tags like `<i>` (and also wikitext markup like `''`)
  could affect the entire page with the bad markup.

  New configuration variable $wgSignatureAllowedLintErrors is added
  to allow ignoring some errors. The default value ignores the
  'obsolete-tag' error (caused by HTML tags like `<font>` and `<tt>`.)

* Require a link to user page, talk page or contributions (T237700)

  Various tools don't work correctly when such a link is missing. For
  example, Echo notifications are not sent, DiscussionTools will not
  allow replying to these comments, English Wikipedia's SineBot treats
  these comments as unsigned.

  Such requirement has been present for a long time in many Wikimedia
  wikis' policies, but it was not enforced by software.

* Disallow "nested" substitution in signature (T230652)

  Clever abuse of "subst" markup and tildes allows users to save edits
  containing wikitext in which substitution occurs again when the page
  is next saved. Disallow this in signatures, at least.

New configuration variable $wgSignatureValidation is added to control
what we do about the result of the validation described above. The
options are:

* 'warning':
  Only displays a warning near the field on Special:Preferences if
  the current signature is invalid. Signatures can still be changed
  regardless of validity and will be used when signing comments.

* 'new':
  In addition to the above, if a user tries to change their signature,
  the new one must be valid. Existing invalid signatures are still
  used when signing comments.

* 'disallow':
  In addition to the above, existing invalid signatures are no longer
  used when signing comments.

Bug: T140606
Bug: T237700
Bug: T230652
Change-Id: I07c575c2d9d2afe7a89c4847d16ac044417297bf
2020-06-24 01:20:05 +02:00
Umherirrender
fd666afbb0 Use MediaWikiServices::getAuthManager instead of AuthManager::singleton
Change-Id: I92c31b963095eab751df9f8c1715e8e23b7e8485
2020-06-22 00:57:08 +00:00
Thiemo Kreuz
5f3a92385b Fix visibility of setUp/tearDown
Change-Id: I636be48eb9f713680abac35d46091f7b49374696
2020-06-16 21:02:05 +02:00
Sam Wilson
5e0fd6d664 Remove PreferencesFactory::setUser()
This method was recently added and was to result in the deprecation
of a few places where User objects were being passed to the factory.
This has now been reconsidered and this patch reverts to the
previous behaviour. It is largely a revert of Ie1bed9e9537cabc836992ccfa7fb127885ea3e11

Bug: T238466
Depends-On: Idc9f33fd5ab55bde88cc306ca63adead286380a8
Change-Id: I3653559704ccfd9bca0946f5a865be93bdf5ceb6
2020-06-08 00:27:04 +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
jenkins-bot
4a5c7b4e84 Merge "Deprecate no LanguageNameUtils constructing DefaultPrederencesFactory" 2020-05-11 21:13:20 +00:00
Sam Wilson
36defc20eb Add PreferencesFactory::setUser()
Add a new setUser() method to PreferencesFactory so that a User
object doesn't have to be passed around so much. This is how
GlobalPreferencesFactory has done it, and so after this change
that code can be removed from GlobalPreferences.

Bug: T238466
Change-Id: Ie1bed9e9537cabc836992ccfa7fb127885ea3e11
2020-05-06 09:04:08 +08:00
Petr Pchelko
2501625352 Deprecate no LanguageNameUtils constructing DefaultPrederencesFactory
Depends-On: I3e30bc01ec9333d03e1282a21ae8953ae1f7c770
Change-Id: Ifd9628469bf72ffaa6ab75415ee18edd416cffe2
2020-05-05 16:41:31 -07:00
Peter Ovchyn
50e3bd4fac parser: Inject a LanguageConverterFactory through DI containers:
1. into class Parser
2. into class LinkHoderArray
3. into class DefaultPreferencesFactory

Add more tests for DefaultPreferencesFactory:
1. testVariantsSupport verifies that converter with variants is used correctly.
2. Test testUserGroupMemberships verifies that membership is used correctly

Bug: T243320, T243321, T243317
Change-Id: I1e5c37e18332d0d32391c74c06e3d84862e48df8
2020-02-04 14:42:03 +02:00
James D. Forrester
5e9fca47b9 Coding style: Auto-fix MediaWiki.Usage.PHPUnit*
Change-Id: I86fc55a4fc8ceafe368692173211bbcd6d8581d7
2020-01-10 10:17:12 +00:00
Cormac Parle
c4eae0dad4 Search: Provide new preference to control redirects on search matches
To avoid preference bloat, this preference is hidden unless the new
sysadmin config $wgSearchMatchRedirectPreference is set.

Bug: T235263
Change-Id: Ic16f53a4e6ddb6da071d63cd5da28d937d4692c8
2019-11-06 15:37:56 +00:00
Max Semenik
48a323f702 tests: Add explicit return type void to setUp() and tearDown()
Bug: T192167
Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43
Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
2019-10-30 14:31:22 -07:00