Commit graph

31 commits

Author SHA1 Message Date
Umherirrender
856947391f api: Add a ratelimit test for action=purge
Follow-Up: Ifb19cc195a51f5521f8365ab26b3cdb56429e0fb
Change-Id: Ie1179a046d7d4dd68aca938593e83aadc578d23b
2024-07-12 22:32:22 +02:00
Reedy
75640200fb tests: Namespace api tests
Bug: T357823
Change-Id: I0d7cc2c9b166d5e5b913c1305f7cee017fe377af
2024-02-18 15:47:04 +00:00
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Umherirrender
352fce6eda Use Authority::authorizeAction for implicit purge/linkpurge right
Use of Authority::authorizeWrite includes permission checks for the
title against the edit rights, which was not the case using
User::pingLimiter before 26456e5b / 07a9c87b

Bug: T354460
Follow-Up: I9fee34f5b44e947a00f1aaf2d28202d009e2caec
Follow-Up: If85e2af107dd901d98e9553d7d38144f1bac62af
Change-Id: Ic03714e849bf3bd550f64e194797b45823b42c08
2024-01-26 23:31:58 +01:00
daniel
a5fc516f5b ApiPurge: report permission errors properly
Previously, all kinds of permission errors were reported as "rate limit
exceeded".

Follow-Up-To: I9fee34f5b44e947a00f1aaf2d28202d009e2caec
Change-Id: Idec70e754bff265c4293aee37c600e54ed1aed40
2023-10-09 17:44:20 +00:00
Daimona Eaytoy
660c1539e3 Do not use UTPage directly in tests
UTPage is a badly named page that should not be used directly. In fact,
soon it will no longer be guaranteed to exist (T342428). Tests should
create the fixtures they need, using titles/summaries that are actually
meaningful and that make it easy to identify what test is responsible
for creating a given page.

In ApiSetNotificationTimestampIntegrationTest, make separate assertions
because the order of the two pages in the result set is not stable
(ApiPageSet::initFromTitles has no ORDER BY).

Change-Id: Iecfb75e16deaa2f682afd916f58d8c548ee1cbac
2023-08-12 23:51:53 +02:00
Umherirrender
d3fb83de20 tests: api: Use NS_ constants instead of hard coded values
Avoid some "magic" numbers

Change-Id: I52ec97434751cfe4136d504a3f8107c6bc63e7ab
2023-07-29 11:02:26 +02:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Timo Tijhof
e88f4ca293 API: Clean up ApiPurgeTest
Follows-up 5e6cccc3a4.

- Let PHPUnit do the diffing instead of exporting expected value
  into the description.

- Use a stricter and complete assertion of the result, not just
  one key existence only. Specifically, this means the value (true)
  is asserted, and any additional or unexpected properties result in
  failure. For example, if all of them were marked as missing+invalid
  the old test would pass as it wasn't checking absence. In general,
  assertArrayHasKey() is almost always indicates a lax test that can
  be improved, or a redundant assertion (such as here, where it was
  used to check 'purge' exists before use, but PHP and PHPUnit naturally
  validate that already).

Change-Id: Ie7067633e4df0b9a1b451ce4c53a98e8ee3c3ae7
2021-03-13 02:29:09 +00:00
Ammarpad
5e6cccc3a4 Re-enable the lone test in ApiPurgeTest
This was disabled 10 years ago because Jenkins was not happy.
We should reenable it and see whether it's happy now, otherwise
the test should be deleted.

Use MediaWikiTestCase::getExistingTestPage() to make sure the page
exists which is another reason given for skipping the test even if
not broken in whole.

Change the test name to more correct 'testPurgePage'

See https://phabricator.wikimedia.org/rMW7a0353b01080

Bug: T273603
Change-Id: Ief2017751256c683c8e4e4df375d5a82bcb4849c
2021-02-02 22:24:59 +00: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
Aryeh Gregor
ed40e8ec53 Get rid of ApiTestCase::doLogin
The function is entirely unnecessary.

Change-Id: I805520e5355119e872e602d0bfc93be26f227128
2018-04-11 20:17:52 +03:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Siebrand Mazeland
80a8a8e85c Pass phpcs-strict on some test files (5/x)
Change-Id: I690645cd8a9b1165dcc8271b201c695ea9391226
2014-04-24 18:51:45 +02:00
addshore
dc18b813e8 Cleanup Api phpunit Tests
- Splits multiple classes into individual files
- Adds @covers tags
- Fixes scope

Change-Id: I7d2816d3574fa53a2aaa8e2a84b7a7ecdd245252
2013-10-24 19:17:01 +01:00
addshore
de7af7ac2c Fix scope on all /phpunit test methods
Change-Id: I3ce92463d485a0fb23e464e9a8059330f32d79af
2013-10-24 10:31:32 +02:00
Siebrand Mazeland
791d0b2a98 Update code formatting
Change-Id: I16a9b42651f1cfb1a70dffbb67b7b83dfeb90d03
2013-04-26 14:21:20 +00:00
Siebrand Mazeland
419b02b6df Update formatting
3 of n.

Change-Id: I62ad009018c54da6cf081c334e44eb98a3c72695
2013-02-14 12:56:23 +01:00
Brad Jorsch
252ae6268b (bug 43762) Mark slow unit test as @group medium
All tests based on APITestCase can be slow. I've also seen more than one
Jenkins failure due to GlobalTest::testMerge timing out.

Also, added a meta-test on APITestCase to make sure that all its
subclasses are marked with @group medium or @group large, to prevent new
tests from re-causing the bug.

Change-Id: I48630736a3d06574876fd1fa3d90899cfbc48012
2013-01-18 14:07:49 -05:00
Timo Tijhof
181c7cdc8e Clean and repair many phpunit tests (+ fix implied configuration)
This commit depends on the introduction of
MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4.

Various tests already set their globals, but forgot to restore
them afterwards, or forgot to call the parent setUp, tearDown...

Either way they won't have to anymore with setMwGlobals.

Consistent use of function characteristics:
* protected function setUp
* protected function tearDown
* public static function (provide..)

(Matching the function signature with PHPUnit/Framework/TestCase.php)

Replaces:
 * public function (setUp|tearDown)\(
 * protected function $1(

 * \tfunction (setUp|tearDown)\(
 * \tprotected function $1(

 * \tfunction (data|provide)\(
 * \tpublic static function $1\(

Also renamed a few "data#", "provider#" and "provides#" functions
to "provide#" for consistency. This also removes confusion where
the /media tests had a few private methods called dataFile(),
which were sometimes expected to be data providers.

Fixes:

TimestampTest often failed due to a previous test setting a
different language (it tests "1 hour ago" so need to make sure
it is set to English).

MWNamespaceTest became a lot cleaner now that it executes with
a known context. Though the now-redundant code that was removed
didn't work anyway because wgContentNamespaces isn't keyed by
namespace id, it had them was values...

FileBackendTest:
* Fixed: "PHP Fatal: Using $this when not in object context"

HttpTest
* Added comment about:
  "PHP Fatal: Call to protected MWHttpRequest::__construct()"
  (too much unrelated code to fix in this commit)

ExternalStoreTest
* Add an assertTrue as well, without it the test is useless
  because regardless of whether wgExternalStores is true or false
  it only uses it if it is an array.

Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-09 03:01:51 +02:00
Antoine Musso
da8ba7c544 Regroup all API tests in the 'API' PHPUnit group
That will let us tests all the API tests by using PHPUnit group
filtering such as:

 php phpunit.php --group API

Also cleaned some whitespaces

Patchset-4: skipped files that had only whitespace changes

Change-Id: I51e03d910521b061f505e3a9b11a08c7b95f1538
2012-04-02 16:55:31 +02:00
Chad Horohoe
d455b3b267 Another @group Broken 2012-01-08 16:40:05 +00:00
Antoine Musso
7b66f6d486 Better output message for ApiPurgeTests
Follow up r10833
2011-12-12 10:25:29 +00:00
Sam Reed
7a0353b010 Mark the test as broken again seeing as Jenkins isn't happy 2011-12-12 00:07:22 +00:00
Sam Reed
24d9a9f179 Revert r105834, WMF locally after fixing PHPUnit 2011-12-11 23:29:06 +00:00
Sam Reed
49d471c67a Mark testPurgeMainPage broken after r105828 and r105833
PhpUnit is more than broken locally (and phpunit.de is down)
2011-12-11 22:39:48 +00:00
Sam Reed
82ee95eb92 Attempt to fix tests broken by r105828
Test wanted in a specific order, now just look up wanted array key from title row

Untested as my phpunit tests seem to be b0rked locally :(
2011-12-11 21:49:05 +00:00
Chad Horohoe
85a5f0eb85 Merge ApiTestSetup into ApiTestCase and update all subclasses. The amount of duplication here was nasty, and also lets us get rid of a bunch of useless require_once()s.
./phpunit.php --filter Api currently gives me: Tests: 24, Assertions: 107, Incomplete: 1, Skipped: 2.
2011-07-01 16:34:02 +00:00
X!
4cce1efbe7 Followup to r79477: Add invalid purge title 2011-01-02 06:15:32 +00:00
X!
cbca0769b7 Add API purge test (mainly as proof of concept for how API tests should be written) 2011-01-02 06:09:58 +00:00