aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api/ApiTestCase.php
Commit message (Collapse)AuthorAgeFilesLines
* Use explicit nullable type on parameter argumentsUmherirrender2024-10-161-5/+5
| | | | | | | | | | | Implicitly marking parameter $... as nullable is deprecated in php8.4, the explicit nullable type must be used instead Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a Break one long line in SpecialPage.php Bug: T376276 Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
* Add namespace to includes/api classesJames D. Forrester2024-09-251-7/+7
| | | | | Bug: T353458 Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
* tests: Consistently use class_alias comments like elsewhereJames D. Forrester2024-09-251-0/+1
| | | | | | Found via `[^*][^\\]\nclass_alias`. Change-Id: I9732f75226445f48fb131c432b209d0fd3eba1ba
* tests/api: Add missing documentation to class propertiesUmherirrender2024-09-101-0/+2
| | | | | | | | | | Add doc-typehints to class properties found by the PropertyDocumentation sniff to improve the documentation. Once the sniff is enabled it avoids that new code is missing type declarations. This is focused on documentation and does not change code. Change-Id: I48014b6464f3e7e2b7f083e67f517af0b1a9367e
* ApiTestCase: Set request context user to session userKosta Harlan2024-06-261-0/+1
| | | | | | | | | | | | | | Why: - In some situations (e.g. tests in ApiRevisionDeleteTest), the context user ID / name was being unset by code in Session What: - Set the session user to the request context user Bug: T365669 Change-Id: Ife2cc31133bafb6a2c0adfeebcb2e1a139f25f48
* Use StatusValue::getMessages() instead of deprecated methodsBartosz Dziewoński2024-05-181-1/+1
| | | | | | | | | This commit replaces some of the uses of getErrorsArray(), getWarningsArray(), getErrorsByType(), and getErrors(). In many cases the code becomes shorter and clearer. Follow-up to Ibc4ce11594cf36ce7b2495d2636ee080d3443b04. Change-Id: Id0ebeac26ae62231edb48458dbd2e13ddcbd0a9e
* Formally deprecate code marked with @deprecatedJames D. Forrester2024-05-031-1/+2
| | | | | | | | | | | | | | | Some of these have been marked in-code as deprecated for a long while, but haven't ever been announced in the RELEASE-NOTES (and later, HISTORY) file, so let's mark them up now so we can get the ball rolling at least. Per Gergo, the AuthManager one was 'born deprecated' and should only have been used by humans also reading the deprecation notice given in the code, and indeed no uses are known to code search, so also emit deprecation warnings there immediately; others will have to wait until uses have been migrated. Change-Id: I0c1c71d8f4293623039302da35d58d2a24367e97
* tests: Namespace api testsReedy2024-02-181-3/+20
| | | | | Bug: T357823 Change-Id: I0d7cc2c9b166d5e5b913c1305f7cee017fe377af
* Namespace includes/contextJames D. Forrester2024-02-081-0/+1
| | | | | Bug: T353458 Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
* update a few tests to use PHP 7.4 syntaxAriel T. Glenn2024-01-091-11/+7
| | | | | Bug: T261872 Change-Id: Ia573136f0ab90025a1588e9dfd5add081d9ffdae
* phpunit: Avoid TestUser in non-database testsDaimona Eaytoy2023-07-291-0/+6
| | | | | | | | | | | | | TestUser creates the user and therefore needs the database. Avoid using it in non-database tests. Add ApiQueryBlockInfoTraitTest to the Database group because it needs the database. Add DeleteUserEmailTest to the Database group because since 3bedffa8 the default user is not created any more in non-database tests Change-Id: Iff438964dde47a47a2fa4a314d55010bd8c7fee5
* Replace usages of ApiTestCase::$usersDaimona Eaytoy2023-07-251-1/+1
| | | | | | | Ideally we'd use Authority, but that doesn't always work, so just call the getTest* methods directly. Change-Id: I7f8393bb754beeb319b5555b5dac05265e376a22
* ApiTestCase: Clone User object when Authority is usedDaimona Eaytoy2023-07-251-1/+5
| | | | | | | | | | | | Something in Session(Backend? Manager?) replaces the user with an unknown user if it doesn't exist, which later causes a token mismatch. I didn't find the root cause for this issue, as I stopped digging once I found a working solution, but it shouldn't realy matter as this is only test code and we're moving away from User anyway. Bug: T341953 Change-Id: I6b675a8b1c6b3d7fff8ca1330f8857b7393ab012
* Deprecate MediaWikiIntegrationTestCase::$usersDaimona Eaytoy2023-07-251-3/+38
| | | | | | | | | | | | | | | | | This property shouldn't be needed in modern code, where most things can use Authority. So much so because TestUser adds a dependency on the database, but many tests that use TestUser don't even need the database. ApiTestCase, in particular, sets this property in setUp, thus adding a database dependency to all API tests, including those that don't need users or the database at all. Deprecate the property and replace existing usages in core. The one in ApiTestCase is much harder to migrate, but this patch replaces the array with an anonymous ArrayAccess class to allow lazy initialization and remove DB dependencies. Bug: T155147 Change-Id: I59c4ed1f6a7572d3a92387b15b8e56625bc376a2
* tests: Avoid array_combine in ApiTestCase::doApiRequestUmherirrender2023-04-281-6/+6
| | | | | | | Also in case of null nothing changed on the key, so skip that array handling Change-Id: I7df8452654d2ecab22c555cbbdc46158f26a4dd1
* API tests: Assert error codes, not error messagesBartosz Dziewoński2023-04-261-0/+98
| | | | | | | | | | | | | | | Error messages are not guaranteed to be stable, and these tests prevent us from improving them. Error codes are supposed to be stable, so we should be asserting that they do not change (especially since many of them are dynamically generated by the dodgy code in ApiMessageTrait). Introduce helpers assertApiErrorCode() and expectApiErrorCode() to be used instead of the usual PHPUnit assertions/expectations for this case. Change-Id: I752f82f29bf5f9405ea117ebf9e5cf70335464ad
* Reorg: Move some of request related classes to MediaWiki/RequestAmir Sarabadani2022-10-281-0/+1
| | | | | | | | | | | | | | | Redoing I5ea70120d74 but without moving WebRequest that caused issues with phan-taint-plugin. Moving: - DerivativeRequest - FauxRequest - FauxRequestUpload - PathRouter - WebRequestUpload Bug: T321882 Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
* Revert "Reorg: Move some of request related classes to MediaWiki/Request"Zabe2022-10-271-2/+1
| | | | | | | | | This reverts commit 2bdc0b2b7209441a42a784157633a8a01b321922. Reason for revert: T166010#8349431 Bug: T166010 Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
* Reorg: Move some of request related classes to MediaWiki/RequestAmir Sarabadani2022-10-261-1/+2
| | | | | | | | | | | | | Moving: - DerivativeRequest - FauxRequest - FauxRequestUpload - PathRouter - WebRequest - WebRequestUpload Bug: T166010 Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
* ApiTestCase: Drop testApiTestGroup forcing use of medium/largeJames D. Forrester2022-08-111-16/+0
| | | | | | | We do not encourage people to use these groups, they are not widely used, and this is just forcing cruft into code for no value. Change-Id: Ia58aa62ea6a1694694fb54acbd717181cd36e051
* ApiBase: Reset self::$filterIDsCache between testsdaniel2022-06-131-0/+2
| | | | | | | | | self::$filterIDsCache caches database state, it gets out of whack when we reset the database between test cases. The cache was originally introduced to fix T140302. Change-Id: I9a05c60d84d92f6798154bfa77c6288576dc53bc
* ApiTestCase: Support APIs with parameter prefixes in doApiRequestWithTokendylsss2022-06-071-3/+15
| | | | | | | Add an optional parameter to doApiRequest/doApiRequestWithToken to automatically prefix parameters. Change-Id: If69074b12fb4682490e05243ae808c39a17c697b Bug: T310008
* Drop action api token methods deprecated in 1.24Petr Pchelko2021-09-131-15/+0
| | | | | | | | | | | Removes deprecated API endpoints and modules for dealing with CSRF tokens. Note: i18n messages are removed in a followup for ease of revert. Bug: T280806 Depends-On: Ic83f44587db119ff2e3e6d5ff33a10894e0695e7 Change-Id: I58aedec6942ac5d3c21574cb0072f00ef365098c
* build: Updating dependencieslibraryupgrader2021-07-221-2/+2
| | | | | | | | | | | | | | 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
* ApiTestCase: stop interacting with $wgUserDannyS7122021-07-131-12/+2
| | | | | Bug: T285448 Change-Id: I6c91f47321c5ab717812a7dd0d629230b71a3ef1
* ApiTestCase: For tokenType=auto respect no token possibilityPetr Pchelko2021-06-241-5/+7
| | | | Change-Id: I92ae8455b08b90c613a54d63b992d59efef2c6dc
* Remove AuthManager::$instance and ::resetCache()Alexander Vorwerk2021-06-201-1/+0
| | | | | | | | | | | | AuthManager has been converted to a service in 1.35. AuthManager::$instance is only used in AuthManager::resetCache(), where it is set to null. This patch also removes AuthManager::resetCache() because with removing AuthManager::$instance AuthManager::resetCache() has no longer any effect. Change-Id: I8b27f9a2d0d3f7acec6b93f64f9c256084990026
* Allow passing mock Authority in API integration testsPetr Pchelko2021-06-071-12/+14
| | | | | | | | | | | This is a demo, a lot of tests could be rewritten as a followup to pass proper Authority when executing tests instead of writing globals. Much cleaner imho. An improvement idea is to allow overriding 'default permissions' when creating a mock Authority. Change-Id: I38570024e0d5a67a8e1c52f7456c458090ec2b6e
* Create FauxRequestUpload to fake uploads in testsUmherirrender2021-04-061-1/+11
| | | | | | | | | | | | And use it in core Avoid direct use of super global $_FILES This can breaks all FauxRequest relaying on $_FILES in tests or production code via FauxRequest::getUpload. Falls back to $_FILES for the moment Bug: T48163 Change-Id: I7392acc9bb682ec6b7025dbed0734c142f45c91a
* API: Clean up ApiPurgeTestTimo Tijhof2021-03-131-8/+5
| | | | | | | | | | | | | | | | | | | Follows-up 5e6cccc3a4c858. - 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
* Use Authority and GroupPermissionLookup in Action APICindy Cicalese2021-02-231-0/+1
| | | | | | | | | | | | | | | | | | | Replaces calls directly to PermissionManager with calls to the Authority object available from Context or the GroupPermissionLookup service. This patch does not address use of PermissionManager for blocks. Deprecations: - ApiBase::checkUserRightsAny deprecated passing optional User parameter - ApiBase::checkTitleUserPermissions deprecated passing LinkTarget as first parameter, takes PageIdentity instead Bug: T271462 Bug: T271854 Change-Id: I5d7cac1c28a37e074750c46cda03283980a07fca
* Tests: Mark more closures as staticReedy2021-02-071-1/+1
| | | | | Bug: T274036 Change-Id: I911d3041cebe417d162934223b46ea295c6d20e3
* Don't access $wgRequest from UserTim Starling2020-12-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | 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
* Reduce some direct references to $wgUserDannyS7122020-09-251-3/+15
| | | | | Bug: T243708 Change-Id: Ief59ce77469de4185c031413e64d0dee3ea26e60
* Remove hard deprecated ApiTestCase::doLoginDannyS7122020-07-271-26/+0
| | | | | | | | No known uses in any repo on codesearch: https://codesearch.wmcloud.org/search/?q=doLogin%5C(&i=nope&files=&repos= Bug: T245355 Change-Id: I606d4f922a3034af786cf64e6d8b211cd12a09af
* Hard deprecate ApiTestCase::doLoginDannyS7122020-02-151-0/+1
| | | | | | | | Soft deprecated in 1.31 All deployed uses removed Bug: T244039 Change-Id: I67b1ce00585a1d305b92a0e8fcc11147930cd4f3
* Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNullJames D. Forrester2020-01-101-1/+1
| | | | Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
* Add missing @param and @return to documentationUmherirrender2019-11-161-0/+4
| | | | Change-Id: I48ee838a7ebf4f25a4883d4c7886b39c2d3916af
* tests: Add explicit return type void to setUp() and tearDown()Max Semenik2019-10-301-2/+2
| | | | | | Bug: T192167 Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43 Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
* Remove Language::factory and getParentLanguage useAryeh Gregor2019-10-271-1/+2
| | | | Change-Id: I11f8801ef47ec1a1f63d840116e69667e6f3ae3c
* Update tests to use PHPUnit 6 class namesMax Semenik2019-10-061-3/+6
| | | | | Bug: T192167 Change-Id: I42b0c8908b4968b95b08f861a40af18dc79fa0a1
* Drop AuthPlugin and related code, deprecated in 1.27James D. Forrester2019-03-051-1/+0
| | | | | | | | | Bug: T215843 Depends-On: Ie49709faa6f67b0a31bd546823d29dbfea0a70eb Depends-On: If8109dbfdeeb88a6265f4cd79d1ae81bff48d934 Depends-On: I36b195fa2d6c23a76631ebaf869c787e44427d60 Depends-On: Iaa171b085fde331eab7d85c7de74523e27fc625a Change-Id: I330b30d6582034a233fed204c0680b1ce84eec6e
* New helper ApiTestCase::setExpectedApiException()Aryeh Gregor2018-08-011-0/+13
| | | | | | | | | | This allows setting the expected exception message by the message key, not text, so it remains correct if the message is updated. This function could be defined to work with other exception types too, but it seems useful to have shortcuts for common types like ApiUsageException or MWException. Change-Id: Ic86278e9e1e91eea0c045d2b93342f018e1d8e66
* Move utility methods from ApiTestCase to MediaWikiTestCaseAryeh Gregor2018-07-291-37/+0
| | | | Change-Id: I79c4e37092958c63a693194b27a9eafae70cb2f8
* Merge "Test ApiUserrights"jenkins-bot2018-04-121-1/+5
|\
| * Test ApiUserrightsAryeh Gregor2018-04-121-1/+5
| | | | | | | | | | | | | | | | | | Fixed bug: in PHP versions less than 5.6.0, any request that didn't attempt to add any groups would warn, because it would call array_fill() with the second argument (num) equal to 0. From PHP 5.6.0, the num argument to array_fill() is allowed to be 0. Change-Id: I0c5772f15d8f550dc43fb37c3c58d15dd73ea584
* | Improve test coverage for ApiParseAryeh Gregor2018-04-121-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also removed a sketchy-looking usage of ?: with a string in ApiParse.php. In this case I think it was fine, because it would only cause a bug if a page's display title was '0' but its actual title was not '0', which is only possible if $wgRestrictDisplayTitle is false, which is broken by design anyway and I don't think is worth testing. But ?: used for something that should be interpreted as a string is generally not a good idea. One bug fixed: an error message that used an undefined variable. Depends-On: Id0e6184aff8f9d7e8f32558e1de14faa0168cc1d Change-Id: I0904bff0f9d80892d0db2ebb590c24fb862f2418
* | Get rid of ApiTestCase::doLoginAryeh Gregor2018-04-111-28/+17
|/ | | | | | The function is entirely unnecessary. Change-Id: I805520e5355119e872e602d0bfc93be26f227128
* Merge "Refactor ApiTestCase to get token from ApiQueryTokens"jenkins-bot2018-04-101-28/+25
|\
| * Refactor ApiTestCase to get token from ApiQueryTokensAryeh Gregor2018-04-101-28/+25
| | | | | | | | | | Depends-On: I9375bc5f40268fd681a2d447c66a03f40b23390a Change-Id: Ia21a974f2b463afc9324182137b95c80db86a6aa