Commit graph

183 commits

Author SHA1 Message Date
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
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
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
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
daniel
c1eb74603a Remove Title from public interface of OutputPage
Bug: T278459
Change-Id: If455682540faf8d42fd8a14e0ef09bac24f72db4
2021-04-16 10:01:56 -07:00
Umherirrender
78cc6d77ff build: Swap deprecated @codingStandardsIgnore to phpcs:ignore
Bug: T278594
Change-Id: I09a6175917090593e6e0055203a890c32bea03a5
2021-04-04 21:18:22 +02:00
Petr Pchelko
244bbc8edc OutputPage: move to authority where relevant
Change-Id: Iae42cc747f80cb0215f862d633e9af32fc7c8571
2021-03-04 08:55:20 -07: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
Umherirrender
9cb5f24bb8 Replace deprecated function in OutputPage
Now mocking LanguageConverter

Change-Id: I25f2f90d8dcf2cb09429e01873f1982dca199976
2021-02-05 02:17:36 +00:00
Umherirrender
62002cdcf1 build: Update mediawiki/mediawiki-codesniffer to 35.0.0
Change-Id: Idb413be4b8cba8611afdc022af59810ce1a4531e
2021-01-31 13:34:38 +00:00
Umherirrender
7691dbeca9 Add missing @param and @return to documentation in tests
Change-Id: Ic663e81cca0bf007804a70772250914a85f1fef4
2021-01-22 19:57:25 +01: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
Thiemo Kreuz
ac205fa84c Fix incomplete/bogus PHPDoc tags in various tests
Most of these are found by the not yet released I10559d8.

I remove the type MockObject in some cases when the calling
code really does not need to know if he get's a mock or the
real thing. However, I do this only in places that are very
closely related to the fixes.

Change-Id: I26a4c3c5a8ae141bf56161b52b54bce7e68f2e30
2021-01-14 19:02:00 +00:00
DannyS712
6a93b0ca93 More misc test cleanup
* parent::setUp() should be first, and ::tearDown()
  should be last
* Move tests that directly extend PHPUnit\Framework\TestCase
  to /unit

Change-Id: I1172855c58f4f52a8f624e6d596ec43beb8c93ff
2020-12-24 00:52:06 +00:00
Tim Starling
6b2a52181f Don't access $wgRequest from User
Some User methods fail if they are called before $wgRequest is
set. But according to the Setup.php comment, it is only set for b/c.
The global request object can be lazy-initialised at any time.

This is sufficient to avoid T263911 (loss/obfuscation of the $wgServer
error message).

In tests, try to keep $wgRequest and RequestContext::$request in sync.
Introduce MediaWikiIntegrationTestCase::setRequest() which sets both at
once, and use that instead of setMwGlobals() or direct assignment.

BlockManagerTest was accidentally exploiting the fact that the global
context request and $wgRequest were separate objects. Making them the
same causes session cookies to appear in the response, breaking the
cookie counts. Use a new response for the test.

Bug: T263911
Bug: T245940
Change-Id: I2be99f7251a837bc6b62be0b152038157dec10f2
2020-12-16 12:21:00 +11:00
C. Scott Ananian
c64e71615e Replace $wgDisable{Lang,Title}Conversion with LanguageConverterFactory methods
Replace direct access to $wgDisableLangConversion with
LanguageConverterFactory::isConversionDisabled(), and replace direct
access to $wgDisableTitleConversion with
LanguageConverterFactory::isTitleConversionDisabled().  However, most
places that check ::isTitleConversionDisabled() actually want
::isLinkConversionDisabled(), so add that too (and deprecate
isTitleConversionDisabled()).

Code search:
https://codesearch.wmcloud.org/search/?q=Disable%28Lang|Title%29Conversion&i=nope&files=&repos=

This change removes a number of spurious dependencies on the global
configuration and reduces code duplication (for example, if the logic
for disabling language conversion were ever to change).

Depends-On: I6fa8230ae97b0e34c381003548e61f9b7387d363
Change-Id: Icc4687638ff1815003dd903854efdbd904854f1e
2020-11-25 12:47:26 -05:00
ArtBaltai
e7dbd69de0 Hard deprecation of Language::convertTitle(),
::findVariantLink(), ::updateConversionTable()

Co-authored-by: C. Scott Ananian <cananian@wikimedia.org>
Bug: T226832
Change-Id: I41a3b67490fc6b9d4c484f566d346a0d10c670e9
2020-10-20 16:49:17 -04: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
Tim Starling
d459add63d Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.

However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."

So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().

Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-22 14:34:39 +10:00
Reedy
229b2c15e8 Fix a plethora of class and function call case mismatches
Bug: T231412
Change-Id: I597a25de3294a6673424f30475760280ef209a8a
2020-05-26 14:14:46 +01:00
Reedy
a8b006426e Fix tests/ PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I0beed1a35e046705fb84c9d1f63cf92afd009bb4
2020-05-16 04:30:21 +01:00
Dave Pifke
0a3aa08b72 OutputPage: Add experimental preconnect resource hint for thumbnails
Adds <link rel="preconnect"> for the first valid foreign or local file
repo, on pages containing images.

This is a hint to the browser that it should open a connection to the
other host (e.g. upload.wikimedia.org), if it doesn't have one
already.  Doing so allows the connection setup to happen before page
parsing is complete, and should result in faster image loading,
especially on slow connections.

Bug: T123582
Change-Id: I2dcc14f05012570a3e41ed8c7064969a4cbfb6db
2020-04-07 21:04:47 +00:00
Brian Wolff
89be2c5820 Allow storing additional CSP sources in ParserOutput
This adds methods to ParserOutput ::addExtraCSPStyleSrc,
::addExtraCSPDefaultSrc, and ::addExtraCSPScriptSrc, to easily
allow parser tags/functions to add additional CSP sources if their
tag needs it. Previously such an extension would need to use
and OutputPage hook. This is modeled on how addModules() works.

The immediate use case is for Kartographer (T240960), although
its expected that lots of extensions might do something like this,
especially extensions used outside of Wikimedia.

Change-Id: I24e5f0b4edff58025a0c2a3e1a9aa3f62eb7db7b
2020-03-12 17:39:51 -07:00
Thiemo Kreuz
e1dd371e11 Make use of PHPUnit's assertCount feature where possible
… and avoid assertEmpty() on arrays, in favor of a much more strict
assertSame( [] ).

Change-Id: I20266b0b1fc38a3a87666ba1b0793cb2b37d94a9
2020-03-02 15:58:41 +00:00
Aaron Schulz
5282a02961 resourceloader: support tracking indirect module dependency paths via BagOStuff
This can be enabled via a configuration flag. Otherwise, SqlModuleDependencyStore
will be used in order to keep using the module_deps table.

Create a dependency store class, wrapping BagOStuff, that stores known module
dependencies. Inject it into ResourceLoader and inject the path lists into
ResourceLoaderModule directly and via callback.

Bug: T113916
Change-Id: I6da55e78d5554e30e5df6b4bc45d84817f5bea15
2020-02-13 17:26:36 +00:00
jdlrobson
8cd2e13363 Deprecate access of logos directly from config, introduce wgLogos
Add getAvailableLogos static method and wgLogos config variable

Longterm we'll phase out wgLogo and wgLogoHD for this more extendable
config.

wgLogoHD is marked as deprecated. wgLogo continues to function as before
when wgLogos doesn't exist to cause minimum disruption.

From now on all logos should be accessed via getAvailableLogos. Patches
in Minerva and Vector follow. See I00899c16c0325f36b671baf17e88c2b5187b3526,
I569e0d800e147eabc7852567acd140108613f074 and
I013bd0904fe8c55efa49d14e84cf06ec1412896f.

Bug: T232140
Change-Id: I66a971631c623cc94b58eb0e5e5bad804789bf1c
2020-02-04 01:56:20 +00:00
Peter Ovchyn
61e0908fa2 languages: Introduce LanguageConverterFactory
Done:
* Replace LanguageConverter::newConverter by LanguageConverterFactory::getLanguageConverter
* Remove LanguageConverter::newConverter from all subclasses
* Add LanguageConverterFactory integration tests which covers all languages by their code.
* Caching of LanguageConverters in factory
* Make all tests running (hope that's would be enough)
* Uncomment  the deprecated functions.
* Rename FakeConverter to TrivialLanguageConverter
* Create ILanguageConverter to have shared ancestor
* Make the LanguageConverter class abstract.
* Create table with mapping between lang code and converter instead of using name convention
* ILanguageConverter @internal
* Clean up code

Change-Id: I0e4d77de0f44e18c19956a1ffd69d30e63cf51bf
Bug: T226833, T243332
2020-02-03 11:38:03 +02:00
C. Scott Ananian
1aef5d72d9 Remove deprecated non-tidy OutputPage::parse/parseInline methods
The non-tidy parsing modes were deprecated in 1.32.  Remove the
deprecated parse/parseInline methods which use them, as part of a
general clean up of nontidy parsing modes.

Bug: T198214
Change-Id: I04ea82dd20eac8b0ce07a8d0e6b0bf2c4b03dbe8
2020-01-15 16:22:19 -05:00
jenkins-bot
ec34c3a340 Merge "Add get{Robot,Index,Follow}Policy methods to OutputPage" 2019-12-29 01:16:03 +00:00
Daimona Eaytoy
7b946ffb4b Fixes for PHPUnit 8 compat in DB suite
Once again, this fixes all issues aside from assertArraySubset.

Bug: T192167
Change-Id: I45c91dc1cf23f04140576dc66233558bb6021324
2019-12-15 00:27:54 +00:00
Daimona Eaytoy
f5529400cc Stop using assertContains with string haystack
This was done automatically by replacing every assertContains with
string *needle*. Then verifying the results.

Bug: T192167
Change-Id: Id8cbbf3b01e948f80046714183cc299f86be21fd
2019-12-15 00:22:44 +00:00
Jack Phoenix
730f7b5917 Add get{Robot,Index,Follow}Policy methods to OutputPage
Inspired by wikiHow's RobotPolicy extension, which depends on the existence of OutputPage#getRobotPolicy, as the extension needs to know the current robot policy state.

Change-Id: I764f5584a9f04a6b66c53193e9118dd1a5248284
2019-12-11 14:23:51 +02:00
Umherirrender
a1f0be1c21 Use nullable type in function signature
Enable the sniff

Change-Id: I9fff860706b0ffb99bb9e78ff26d15bc7c87bdb4
2019-11-20 19:20:38 +01:00
David Barratt
441ff2003e
Add tests to OutputPage::sendCacheControl()
Before making improvements to OutputPage::sendCacheControl() the test coverage
should be increased.

Bug: T236862
Change-Id: I4a76b0894e2d574688e1cbd30f32ee7504801082
2019-11-06 12:58:29 -05:00
jenkins-bot
169e21e921 Merge "tests: Add type hints to OutputPageTest" 2019-11-01 03:07:57 +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
jenkins-bot
17b931caf6 Merge "Remove Language::factory and getParentLanguage use" 2019-10-29 09:25:29 +00:00
Brian Wolff
67ea4f5747 Mild refactoring of ContentSecurityPolicy
This is to make it behave in a more object orientied way. The
goal is to make it be easier to allow extensions to mark certain
pages as requiring a different policy (For example, CodeEditor
extension uses a blob: url with a WebWorker. We don't want to
include that on the policy of every page, but allow the extension
to mark it as required whenever needed).

This commit does not change code behaviour in any way.

Change-Id: I4bf53dabb6e6c5446cea99a64db68b300cef2fd4
2019-10-28 09:02:14 -07:00
Aryeh Gregor
0de9c47b50 Remove Language::factory and getParentLanguage use
Change-Id: I11f8801ef47ec1a1f63d840116e69667e6f3ae3c
2019-10-27 12:34:28 +02:00
Aryeh Gregor
e787246ce8 LanguageFactory to replace Language::factory()
Languages with variants no longer can override the parent's constructor
(which is now used for injecting services). Instead, they need to
override Language::newConverter().

Bug: T201405
Change-Id: I923400d61763cf1db88cb0c3f684c9c10e58032d
2019-10-23 10:48:23 -07:00
Umherirrender
5bd311b1a2 Add public as visibility in tests folder
Add public, protected or private to function missing a visibility
Enable the tests folder for the phpcs sniff

Change-Id: Ibefce76ea9984c47e08c94889ea2eafca7565e2c
2019-10-10 21:55:37 +02:00
Daimona Eaytoy
8545ce131a Kill the remaining usages of PHPUnit4And6Compat methods
Bug: T192167
Change-Id: I1ea19e9b53683b7d32ff9836990ee73ab3e11104
2019-10-06 10:12:54 +00:00
jenkins-bot
889f683035 Merge "Clean up most of b/c for phpunit4" 2019-10-06 02:17:39 +00:00
Amir Sarabadani
440297fa3a Clean up most of b/c for phpunit4
We don't support phpunit4 anymore:
https://w.wiki/9UT

Change-Id: Ia7c932998f1a49af1e322ab9e1dc249b7bd2e8b2
2019-10-06 00:14:35 +02:00
Daimona Eaytoy
ef5ab69629 Replace setExpectedException with two args
Find: ^(\t*)(\$this->)setExpectedException\(\s+(\\?[a-z\\]+::class),\s+('(?:[^'\\]|\\')+'|"(?:[^"\\]|\\")+")\s+\);

Replace: $1$2expectException( $3 );\n$1\$this->expectExceptionMessage( $4 );

+broke long lines manually.

Bug: T192167
Change-Id: I5557b4372625def55a53ac637c2f980f51f12933
2019-10-05 16:14:05 +00:00
Thiemo Kreuz
5719b28cee tests: Add type hints to OutputPageTest
… to make my PHPStorm IDE complain less about unknown types. The moment
the tests go green this should proof itself, because there is no other
code that depends on this test than the test itself. ;-)

Note the removed options array was broken. The comparison checked the
*values*, not the keys.

Change-Id: I1929cd694808d5b924933fc7033c05eaceda7e34
2019-10-01 14:50:57 +02:00
Thiemo Kreuz
32a429e8c4 tests: Prefer assertSame() when comparing the integer 0
assertSame() is guaranteed to not do any type conversion. This can be
critical when acciden tially comparing, for example, 0 to 0.0.

Change-Id: Iffcc9bda69573623ba14af655dcd697d0fcce525
2019-09-19 15:35:23 +00:00
Timo Tijhof
9f516f1d3b resourceloader: Reduce width of module hash from 7 chars to 5
In a nut shell:

* We very often (52% of modules on enwiki) pad the hash with a zero,
  which means the amount of bits we currently compute already fit in
  6 characters already for most modules. For some modules (3%) we
  even padded two zeroes.

* For the (now documented) use cases, the space of 78 Giga
  (78 billion, or 78 milliard) seems more than we need. The space of
  60 million should be enough.

  This follows-up dfd046412f from 2016, which previously shortened the hash
  down from 8 chars of base 64 (or 12 chars of hex) to 7 chars of base 32.
  Before that change, the space was 281 Tera (64^8, or 16^12).

For more details see the added inline comment for ResourceLoader::makeHash,
and also the data at <https://phabricator.wikimedia.org/T229245>.

Bug: T229245
Change-Id: I9ad11772a33b3a44cb625275b1d7353e1393ee49
2019-09-02 01:25:48 +00:00
Piotr Miazga
b7204566d2 Deprecate skin functions that are not skin responsibilities
Skin shouldn't be responsible for providing requested revisionId
nor if that revision is the current revision.
The OutputPage object has all required information (both the
currentRevisionID and the current Title object).

Change-Id: I2dbae4c6968a2b3b3cea3e09977e9579609b4cc5
2019-08-23 13:21:11 +00:00