Commit graph

711 commits

Author SHA1 Message Date
Daimona Eaytoy
6365eaab8d Autofix 94 PHPUnit 8 compat issues
Done automatically using the master version of MW codesniffer and
running composer fix.

Bug: T192167
Change-Id: If6b40f515fde32ab5eff074a90e821c30c791827
2019-12-13 15:29:10 +01:00
Max Semenik
eb3461d146 ApiQueryBlocksTest: fix assertions
arrayHasKey() only returns a constraint, an assertion is
needed to actually perform a check.

Change-Id: I33a6cc4ed8e002764438a23300c5d204649200ca
2019-12-10 16:39:50 +03:00
jenkins-bot
af4b49e67c Merge "Improve param docs" 2019-11-28 19:36:24 +00:00
Umherirrender
c7ad21c25f Improve param docs
Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
2019-11-28 19:08:59 +01:00
Umherirrender
a1f0be1c21 Use nullable type in function signature
Enable the sniff

Change-Id: I9fff860706b0ffb99bb9e78ff26d15bc7c87bdb4
2019-11-20 19:20:38 +01:00
Umherirrender
97ed35e2e8 Add missing @param and @return to documentation
Change-Id: I48ee838a7ebf4f25a4883d4c7886b39c2d3916af
2019-11-16 13:45:55 +01:00
Thiemo Kreuz
50dca8ed1e Replace some oldskool @see with @inheritDoc
This patch also adds some missing newlines at the beginning of files.

Change-Id: Ifcdf75396c96f17b7bfb103f54bfdf4ba4dfbccc
2019-11-08 18:00:27 +00:00
Brad Jorsch
f3058c81b9 Add $wgDiffEngine
The immediate use case is for testing, where some tests need to use the
PHP implementation even when wikidiff2 is installed.

Bug: T237049
Change-Id: I41dc4c0933429065d7638f518ec31f0a056afc41
2019-11-05 10:38:52 -05:00
Max Semenik
dd7026585c Backwards-compatible PHPUnit 8 preparations
This commit splits changes from Ic14f5debc53e55d6714 to reduce it to
only strictly needed things. It can be merged immediately.

Bug: T192167
Change-Id: I8c541a66ea13421dbe7fa51d197d5455cc4786eb
2019-11-02 12:40:07 -07: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
jenkins-bot
8904293650 Merge "LanguageFactory to replace Language::factory()" 2019-10-28 15:03:22 +00:00
Aryeh Gregor
0de9c47b50 Remove Language::factory and getParentLanguage use
Change-Id: I11f8801ef47ec1a1f63d840116e69667e6f3ae3c
2019-10-27 12:34:28 +02:00
Timo Tijhof
63ddc8c436 tests: Replace RandomImageGenerator dictionary logic with rand+time
The main purpose of this class is to generate filenames during
tests. The reason it doesn't use fixed filenames is not because
it wants to be a fuzzy test, but because it wants to allow
running against a development wiki (outside CI) multiple
times where one test may've failed and unable to clean up after
itself, or where you may've done something manually and thus
a conflicting file exists in the local wiki from before
the DB was cloned for testing.

Using dictionary based random names is needlessly complex,
and has the additional downside of actually not avoiding
conflicts very well.

Replace all this by using a timestamp instead, which is much
more stable over time and basically will never conflict with
itself unless two tests were run on the same machine and started
in the same second (or if the clock went backwards/broken).
That seems unlikely enough to not need to support magically.
But to counter-act it a bit still, also add a 3-char random hex
in front of it. This also helps with file listings so that
when you run it three times, it's easier to see the files generated
by the same run close to each other (by not having subsequent
tests start with a mostly identical prefix).

Bug: T222416
Change-Id: Iec1d89324ff2fa53d1712796157adaf4ed34bdfe
2019-10-25 02:07:21 +01: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
Brad Jorsch
f36e22dd8f Fix line selection in RandomImageGenerator
RandomImageGenerator::getRandomLines() is trying to select a random
subset of lines from a dictionary file, but the algorithm has a few bugs
that cause it to potentially leave entries in the returned array as null
and to be biased against the first few lines in the file.

This patch corrects the bugs to implement a Fisher–Yates (or Knuth)
shuffle,[1] run in reverse so that N does not need to be known ahead of
time and only maintaining the desired subset of the array in memory.

In local testing over many trials, it has produced output without nulls
100% of the time and the aggregate results do not have any obvious bias.

[1]: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle

Bug: T222416
Change-Id: If136928bda2165198d3957a3536de85d465321fc
2019-10-23 10:52:50 -04:00
Tchanders
a6533885b8 Revert "Revert "Store block reasons as CommentStoreComments in block classes""
This reverts commit 5f06efb318, which
reverted 9335363789, which makes
the deprecated property AbstractBlock::mReason private.

After 9335363789, AbstractBlock::mReason is obsolete, since the block
reason is now stored as a CommentStoreComment, AbstractBlock::reason.

Change-Id: Ica0a74be90383689ca8e4cfe6d0fb25c9a5942c5
2019-10-20 10:41:17 +01:00
Daimona Eaytoy
5f06efb318 Revert "Store block reasons as CommentStoreComments in block classes"
This reverts commit 9335363789.

Reason for revert: It's full of code accessing AbstractBlock::mReason
out there, see [1]. Also, it was never hard deprecated. While that may
be acceptable under some circumstances, it's definitely not OK to remove
code when there are consumers around. I'd have fixed it right now without
reverting if it were a single repo, but there's just too many.

[1] - https://codesearch.wmflabs.org/search/?q=-%3EmReason&i=nope&files=&repos=

Change-Id: I8669f502b50cff89e28dada0f65fe2b130ae9b37
2019-10-19 18:55:45 +00:00
Thalia
9335363789
Store block reasons as CommentStoreComments in block classes
AbstractBlock::setReason now accepts a string, Message or
CommentStoreComment. The CommentStoreComment is accessed via
AbstractBlock::getReasonComment.

AbstractBlock::getReason returns the reason as a string, with
the language and format consistent with how block reasons were
built before this commit. This method is deprecated, since it
makes assumptions about the language and format needed. The
deprecated mReason property is no longer public.

Doing this (and T227005) will remove the implicit dependency of
BlockManager::getUserBlock on language, which causes a recursion
error if the block is checked before the user has loaded. It also
provides a mechanism for getting the block reason in a language
specified by the caller. (This does not apply to DatabaseBlock
reasons entered via the Special:Block form, which were not and
are still not translatable.)

This commit also updates authentication classes to return the
translated reason.

Bug: T227007
Change-Id: Iec36876e930dff96a256aebbdc39cbfb331c244e
2019-10-18 17:47:56 -04:00
Thalia
7bbda9811b Remove deprecated method ApiQueryUserInfo::getBlockInfo
Change-Id: Ib291a7893cde780c3505f7cd499e222410e0efa9
2019-10-16 20:46:02 +01:00
James D. Forrester
83d76f4cb5 phpcs: Enable MediaWiki.Commenting.PhpunitAnnotations.ForbiddenExpectedException* and make pass
Change-Id: I63f97497714a32236268be6965c5e181dade6c58
2019-10-14 12:48:48 -07:00
James D. Forrester
9be9e77b51 build: Upgrade mediawiki-codesniffer from 26.0.0 to 28.0.0
Newly-disabled general rules:
* MediaWiki.Commenting.FunctionComment.MissingSplatVariadicArg
* MediaWiki.Commenting.FunctionComment.SuperfluousVariadicArgComment
* MediaWiki.Commenting.PhpunitAnnotations.ForbiddenExpectedException
* MediaWiki.Commenting.PhpunitAnnotations.ForbiddenExpectedExceptionMessage
* MediaWiki.Commenting.PhpunitAnnotations.ForbiddenExpectedExceptionMessageRegExp
* MediaWiki.Usage.NullableType.PHP71NullableStyle
* MediaWiki.Usage.PHPUnitTypeHints.MissingTypehint
* PSR12.Files.ImportStatement.LeadingSlash
* PSR12.Properties.ConstantVisibility.NotFound

Change-Id: Ifcf8c6d5fecc47a32741114b5a5b746a41510045
2019-10-11 10:05:43 -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
jenkins-bot
85f022b7eb Merge "Export $wgMainPageIsDomainRoot in siteinfo API" 2019-10-09 16:17:19 +00:00
Aryeh Gregor
6d80b6c082 Split some Language methods to LanguageNameUtils
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.

In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).

There is 100% test coverage for the code in the new class.

This was previously committed as 2e52f48c2e and reverted because it
depended on e4468a1d6b, which had to be reverted for performance
issues. There should be no changes other than rebasing.

Bug: T201405
Change-Id: Ifa346c8a92bf1eb57dc5e79458b32b7b26f1ee8a
2019-10-07 15:20:52 -07:00
jenkins-bot
59a0942376 Merge "Kill the remaining usages of PHPUnit4And6Compat methods" 2019-10-06 10:47:37 +00:00
Daimona Eaytoy
8545ce131a Kill the remaining usages of PHPUnit4And6Compat methods
Bug: T192167
Change-Id: I1ea19e9b53683b7d32ff9836990ee73ab3e11104
2019-10-06 10:12:54 +00:00
Max Semenik
fb06e4cd85 Update tests to use PHPUnit 6 class names
Bug: T192167
Change-Id: I42b0c8908b4968b95b08f861a40af18dc79fa0a1
2019-10-06 01:01:28 -07:00
jenkins-bot
be07355873 Merge "Replace setExpectedException with two args" 2019-10-05 23:40:59 +00:00
jenkins-bot
31b87650c7 Merge "Drop strings for wgExternalDiffEngine, deprecated in 1.27 and 1.32" 2019-10-05 22:14:16 +00: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
jenkins-bot
0b31b60e08 Merge "tests: Add type hints to ApiFormatBaseTest" 2019-10-05 00:30:09 +00:00
C. Scott Ananian
315a859b53 Export $wgMainPageIsDomainRoot in siteinfo API
Follow up to a5deeac58c.

Bug: T120085
Change-Id: I58bfc55362fb8da7f22891ce0f57aa4996c51b16
2019-10-04 17:23:57 -04:00
James D. Forrester
5b3bbd5ade Drop strings for wgExternalDiffEngine, deprecated in 1.27 and 1.32
Also move the 'unit' test into integration, given it tests code
using globals.

Change-Id: Ie039cae9b5d2870c18a6deefec9a73de522dd847
2019-10-03 22:09:38 +00:00
jenkins-bot
fb04cc5a7e Merge "tests: Fix broken assertion in ApiQueryAllPagesTest" 2019-10-01 13:31:19 +00:00
Thiemo Kreuz
d2227f415a tests: Fix broken assertion in ApiQueryAllPagesTest
The description had two errors:

* It talked about the presence of a specific value, but all it did
was checking a count.

* It was talking about the value *not* being there.

I just removed it. The possible error message from PHPUnit should be
good enough.

Change-Id: I7ea85dd37db8969bdd120f9600eeb6145e42eb1e
2019-09-30 16:22:54 +02:00
Thiemo Kreuz
cff596804a tests: Replace assertions on count() == 0 with strict === []
The benefit of using count() is that the test would still succeed if
the return vfalue is not an array, but an iterable object. It seems
this is not needed.

Change-Id: I23529f6990aebe0cce86e236a21820fe74993204
2019-09-30 16:20:34 +02:00
jenkins-bot
a046c25c9d Merge "Speed up ApiQuerySiteinfoTest:testContinuation" 2019-09-27 13:42:20 +00:00
Antoine Musso
6d78b45e1b Speed up ApiQuerySiteinfoTest:testContinuation
The test fills $wgUrlProtocols with 86000 entries, forging oversized
strings which ends up eventually truncated to 100 bytes.  The aim is to
overflow $wgAPIMaxResultSize to trigger an apiwarn-truncatedresult
warning.

The test takes 230 ms on my machine and when generating code coverage
almost a minute.

A faster approach is just to lower the $wgAPIMaxResultSize limit to
trigger the warning.

Test plan:

  $ php tests/phpunit/phpunit.php \
      tests/phpunit/includes/api/ApiQuerySiteinfoTest.php \
      --filter testContinuation

Bug: T234016
Change-Id: I3dc96d394d8b98dda8f151d14544b829c92f9b10
2019-09-27 10:42:56 +02:00
Brad Jorsch
995aad376a API: Use ConvertibleTimestamp::setFakeTime for testing curtimestamp
Mainly to avoid spurious test failures when CI is being extremely slow.

Bug: T233752
Change-Id: Ie2cdd84dc076a852fbdce52f661ef893f9a2d45b
2019-09-26 12:35:00 -04:00
Thiemo Kreuz
400a3d5e22 tests: Add type hints to ApiFormatBaseTest
These help making the code much more readable and explorable. IDEs
now allow to ctrl+click most of the methods to jump to their source.

Change-Id: If1e55fa549de27be2549f245eca6938ecd5cfd82
2019-09-26 14:14:47 +02:00
jenkins-bot
095c50ade1 Merge "tests: Prefer assertSame() when comparing the integer 0" 2019-09-20 15:33:02 +00: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
Brad Jorsch
02d6dc2e4f API: Use ApiBlockInfoTrait in ApiQueryUsers and AllUsers
For efficient bulk querying, this means that
ApiQueryBase::showHiddenUsersAddBlockInfo() needs to return everything
needed by DatabaseBlock::newFromRow().

Since we're rewriting it anyway, we may as well also move
ApiQueryBase::showHiddenUsersAddBlockInfo() out into a trait of its own.

Bug: T232021
Change-Id: I9c5b17a232ecbfbffefc7e40608cf5684ce8a644
2019-09-18 19:44:01 +00:00
DannyS712
3a2c7d1b5d Deprecate $wgSysopEmailBans
Bug: T232169
Change-Id: Iba2493eb2f49d32c5aa1b4da53c9c221847fb125
2019-09-17 08:23:04 +00:00
jenkins-bot
cfd56e52d9 Merge "Add namespace restrictions to meta=siteinfo&siprop=namespaces API result" 2019-09-16 22:47:52 +00:00
DannyS712
c711cb207f Add namespace restrictions to meta=siteinfo&siprop=namespaces API result
Bug: T73952
Change-Id: I6b4484fa9170ce39953a37eae2ffb859118fd1e5
2019-09-12 16:40:12 +00:00
jenkins-bot
1e2cce13ea Merge "Allow users who are partially blocked to delete revisions." 2019-09-11 08:24:11 +00:00
David Barratt
6b43064e5c Allow users who are partially blocked to delete revisions.
Currently, users who are partially blocked are prevented from deleting
revisions. The system should check to see if the user can edit the page.

Bug: T228486
Change-Id: Id08dfab9b0ebe9721d3552564ee9f9d1e1a4805a
2019-09-11 08:14:48 +01:00
jenkins-bot
6b89d180d9 Merge "Move callers away from Title::GAID_FOR_UPDATE" 2019-09-10 03:32:37 +00:00