aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api/ApiBlockTest.php
Commit message (Collapse)AuthorAgeFilesLines
* block: Don't modify an autoblock when the user specifies an IPTim Starling2025-03-201-3/+20
| | | | | Bug: T389452 Change-Id: Id7a3f565821231647fe75a24e9ef7efeeb157c5d
* Namespace all remaining files in includes/loggingJames D. Forrester2025-03-191-1/+1
| | | | | Bug: T353458 Change-Id: Ibe1810f1c71316a9124e1dc6ae405097dafd5267
* Merge "block: Increase page restriction limit in multiblocks mode"jenkins-bot2025-03-121-1/+1
|\
| * block: Increase page restriction limit in multiblocks modeTim Starling2025-03-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | User consultations uncovered a need for restricting blocks to a list of more than 10 pages. With multiblocks, an admin in this situation could split up the block into several blocks, each with 10 pages, which is a tedious workaround. Discourage this by increasing the limit to 50. This was already implemented on the client side. Bug: T388505 Change-Id: I034b9e2fbf38e715255ca84065ec5a63534f86ad
* | block: Fix failure to sanitize a range blocked with ApiBlockTim Starling2025-03-121-0/+16
|/ | | | | Bug: T388097 Change-Id: I89baf1b190cf9adefba9a232f57c957a2345f8e5
* block: DatabaseBlock constructor caller migrationTim Starling2025-03-041-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | There's about 100 callers of the DatabaseBlock constructor in core tests, most of them passing an address parameter which needs access to the global service container to parse. Many are passing the constructed object straight to DatabaseBlockStore::insertBlock(). So add insertWithParams() for their convenience, which has some handy shortcut parameters, has service access, and throws on failure. The calling code tends to be shorter than before. For unit tests trying to construct DatabaseBlock objects without a service container, direct construction of BlockTarget subclasses is warranted. Add a default to the $wikiId parameters for their convenience. MockBlockManager had its own 'target' parameter, mixed in with block options, carrying its own special idea of a target, which conflicted with DatabaseBlock's new 'target' parameter. Harmonise the parameters and fix the callers. Bug: T382106 Bug: T385966 Change-Id: I78b45a6003b62962211379c36da5587081f90f00
* block: Add test for block log expiry formattingTim Starling2025-02-111-0/+16
| | | | | | | | Add a regression test for accidental conversion of block log expiry times from relative to absolute timestamps. Bug: T248196 Change-Id: Ie7db802c43b222260074c01bf70a3e9759cef845
* Revert "API: Use ExpiryDef for action=block expiry parameter"Tim Starling2025-02-101-14/+3
| | | | | | | | | | | A block action done with the API no longer shows the relative timestamp in the log. So revert the parts of 257d6f3ba0517265471165cfdf4ba8576cc4 which switched ApiBlock to use ExpiryDef. The change to errorformat is not reverted. Bug: T248196 Change-Id: I3c277a5612e2c00d1120012354c4657c6fb02b47
* API: Use ExpiryDef for action=block expiry parameterSam Wilson2025-01-291-3/+14
| | | | | | | | | | | * Use the ExpiryDef validation for the action=block expiry parameter. * Change the errorformat used by Special:Block to get validation messages in HTML and the right language, and map these to form error messages. Bug: T384241 Bug: T248196 Change-Id: Ic7a080d02e317bbdddb609bf724e3c7c2c393983
* block: Multiblocks block APITim Starling2024-12-161-4/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In ApiBlock: * Add an "id" parameter. If this is given, update the specified block. * Add a "newblock" parameter. If this is given, always add a new block, don't check if the target is already blocked. * If "reblock" is given and the target has more than one block, fail with an "ambiguous-block" error. Supporting changes: * Add BlockUserFactory::newUpdateBlock(), which takes a DatabaseBlock instead of a target union to act on. The block is passed through to the BlockUser constructor. * Rename the first parameter to BlockUser::placeBlock() from $reblock to $conflictMode, and style it like an enum. Add the CONFLICT_NEW value, to support the "newblock" API option. * In DatabaseBlockStore::newFromId(), add $fromPrimary, so that ApiBlock can pass data to BlockUserFactory with equivalent freshness to the LHS. Also: * In BlockUser, memoize prior blocks loaded from the DB * Move T287798 autoblock check to the memoized accessor. Just don't return autoblocks. * Move "TODO handle failure" comment in BlockUser to the called method. It really can't fail. * In DatabaseBlockStore::newFromId(), add an $includeExpired parameter and default to false although it was previously implicitly true. Based on a brief review of callers, I think this is beneficial. Bug: T378147 Change-Id: Iea5b77cb27006b33f3dde61660be5ad2c374a425
* Use explicit nullable type on parameter argumentsUmherirrender2024-10-161-1/+1
| | | | | | | | | | | 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-1/+1
| | | | | Bug: T353458 Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
* tests/api: Add missing documentation to class propertiesUmherirrender2024-09-101-0/+3
| | | | | | | | | | 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
* Replace db with getDb for TestsWandji692024-06-231-1/+1
| | | | | Bug: T316841 Change-Id: I29e535e8ee9b5641a4546d53b98cd5060d39681d
* block: Deprecate and stop using $wgBlockTargetMigrationStageTim Starling2024-05-101-48/+15
| | | | | | | | | | | | | * Deprecate and stop using $wgBlockTargetMigrationStage. Remove block_target migration code. * Make the $schema parameters to DatabaseBlockStore methods default to SCHEMA_BLOCK. Avoid passing these parameters where possible. * Remove cleanupBlocks.php * Deprecate DatabaseBlock static methods which try to present the old schema for b/c. Bug: T362133 Change-Id: I845bad8cc09a4528fef46a6f9d490ebdec881d99
* tests: Namespace api testsReedy2024-02-181-0/+2
| | | | | Bug: T357823 Change-Id: I0d7cc2c9b166d5e5b913c1305f7cee017fe377af
* tests: Fix @covers and @coversDefaultClass to have leading \Reedy2024-02-161-1/+1
| | | | Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
* Merge "Replace a few manually crafted assertTrue assertions"jenkins-bot2023-11-301-1/+1
|\
| * Replace a few manually crafted assertTrue assertionsthiemowmde2023-11-231-1/+1
| | | | | | | | | | | | | | … replace them with the named convenience methods provided by PHPUnit. Change-Id: Ib46dbc3ab7926cf176477254f466b9bdd3be7c46
* | Support new block schemaTim Starling2023-11-291-15/+45
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Support migration stages when reading and writing blocks. I tried to set it up for an easy next stage, in which support for the old schema is removed. I tried to avoid factoring out of shared code between the two schemas, so that the old schema cases can simply be deleted without the need to revert unnecessary abstractions. However, I added HideUserUtils to factor out ipb_deleted queries. Code review showed that this was already quite complex, with multiple approaches to the problem, so it benefits from refactoring even without the schema abstraction. HideUserUtils is a service rather than a standalone class to support unit tests, since unit tests do not allow global config access. When the migration stage config is removed, it will be a service with no constructor parameters -- an unnecessary abstraction which should ideally be resolved at that time. When interpreting result rows, it is possible to share code by using field aliases. But when constructing WHERE conditions, the actual field names need to be used, so the migration is more intrusive in ApiQueryBlocks and SpecialBlockList, where complex conditions are used. Bug: T346293 Bug: T51504 Bug: T349883 Change-Id: I408acf7a57b0100fe18c455fc13141277a598925
* Follow-up 71ff05267: Stop writing to tablesUsed in tests, now unnecessaryJames D. Forrester2023-11-211-4/+0
| | | | | Bug: T342301 Change-Id: I5ea01f7ee103570165261bde0965c5b65e04c369
* Migrate callers of DatabaseBlock methods moved to DatabaseBlockStoreTim Starling2023-11-061-5/+7
| | | | | | | | | | * Migrate callers of DatabaseBlock methods newListFromTarget, newFromID, newFromTarget, doAutoblock. * Deprecate DatabaseBlock methods newFromID and getAutoblockExpiry. These are the methods with no extension callers in code search. Bug: T255433 Change-Id: If0358459f53d32e7fe984c2fb8b61e0088f28922
* tests: Use $this->getDb() instead of wfGetDB() in integration testsAmir Sarabadani2023-09-251-6/+3
| | | | | | | Deprecated long time ago. Bug: T330641 Change-Id: Ia57f12d350c3346029aafae25534c9ed262a7e98
* tests: Migrate more cases to SQBAmir Sarabadani2023-09-211-23/+17
| | | | | Bug: T344971 Change-Id: Ia69d82d6a6e623b9032240dc910fb47ff5887661
* Reorg: Move MWTimestamp to MediaWiki\UtilsAmir Sarabadani2023-08-191-0/+1
| | | | | Bug: T321882 Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
* tests: api: Replace some static function with servicesUmherirrender2023-07-291-5/+6
| | | | | | | Replace User::, Title:: ContentHandler:: calls to the corresponding services Change-Id: I57e47221a00eafac9f171215019cf25e19e1808e
* Replace usages of ApiTestCase::$usersDaimona Eaytoy2023-07-251-5/+5
| | | | | | | Ideally we'd use Authority, but that doesn't always work, so just call the getTest* methods directly. Change-Id: I7f8393bb754beeb319b5555b5dac05265e376a22
* Avoid calling overrideConfigValue() multiple timesthiemowmde2023-07-201-6/+1
| | | | | | | | | | Same as I7a82951. overrideConfigValue() and overrideConfigValues() both call setMwGlobals(), which calls resetServices(). This is surprisingly expensive. It's much better to call it once with an array. Change-Id: I4ff2f6b902b1a1e0b554ce6fc76f3b612f703fae
* Merge "tests: Migrate Database::select usages to SelectQueryBuilder"jenkins-bot2023-07-171-6/+5
|\
| * tests: Migrate Database::select usages to SelectQueryBuilderAmir Sarabadani2023-07-171-6/+5
| | | | | | | | | | Bug: T311866 Change-Id: I0324919f4e40f4e2db3dab1e9aacf74177170b20
* | ApiBlockTest: improve permission checksDaimona Eaytoy2023-07-161-10/+10
|/ | | | | | | | | | Do not assume that sysops don't have the hideuser right. That can be changed in configuration. For instance, I have that in my local. Use an appropriate authority without the 'hideuser' permission instead. Also avoid overriding $wgGroupPermissions, and use an Authority instead. Change-Id: I1c8b25965e41a1a0308dfbe0212c1c19deccb364
* API tests: Assert error codes, not error messagesBartosz Dziewoński2023-04-261-33/+11
| | | | | | | | | | | | | | | 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
* Just another 80 or so PHPStorm inspection fixes (#4)Tim Starling2023-03-251-1/+1
| | | | | | | | | | | | | * Unnecessary regex modifier. I agree with this inspection which flags /s modifiers on regexes that don't use a dot. * Property declared dynamically. * Unused local variable. But it's acceptable for an unused local variable to take the return value of a method under test, when it is being tested for its side-effects. And it's acceptable for an unused local variable to document unused list expansion elements, or the nature of array keys in a foreach. Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
* tests: Use `overrideConfig(Value|Values)` where neededDerick Alangi2022-07-121-17/+26
| | | | | | | This patch covers: tests/phpunit/includes/actions/ and tests/phpunit/includes/api/. Change-Id: I60d8fb7b8a63b423606db935fa0d24cf859b2512
* phpunit: use ->getServiceContainer() in integration testsAlexander Vorwerk2022-01-271-3/+2
| | | | Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
* Remove or replace usages of "sanity"Reedy2021-11-211-2/+2
| | | | | Bug: T254646 Change-Id: Ib192dc5704a14d02c7c374d0ab29bac55c5df24a
* Drop action api token methods deprecated in 1.24Petr Pchelko2021-09-131-25/+12
| | | | | | | | | | | 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-1/+1
| | | | | | | | | | | | | | 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
* Hard-deprecate AbstractBlock::getTargetAndType() and getTarget()vladshapik2021-06-221-1/+1
| | | | | | | | | | | | Replace all uses of AbstractBlock::getTarget with Block ::getTargetName and ::getTargetUserIdentity. Create AbstractBlockTest and two test cases for AbstractBlock::getTarget and ::getTargetAndType. It tests triggering of the deprecation warning. Bug: T282247 Depends-On: I0543f363af66c57f5763b91320d87a69f23f9466 Change-Id: Iaeca824cac30172178de72f3cf7b7ae4cdd6f880
* Allow passing mock Authority in API integration testsPetr Pchelko2021-06-071-15/+11
| | | | | | | | | | | 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
* Update DatabaseBlock construct option 'by' and 'byText' usage to use User ↵Roman Stolar2021-06-021-1/+1
| | | | | | | Identity only Bug: T283641 Change-Id: Ic6d4a6e10bda0115c87a85d8a9ddfd4098cd1373
* Allow partial action blocks to be made via ApiBlockThalia2021-05-041-0/+21
| | | | | Bug: T280522 Change-Id: I114e3c76cfb6dd2f79b5217aee4b3da34df00850
* ApiBlockTest: Separate out page and namespace restrictions testsThalia2021-05-041-7/+17
| | | | | | | Make the assertions per test more focussed and stop relying on restrictions being in a certain order. Change-Id: I75e8d8d44eb43b894f72503ead55bd95dc4b72bf
* Replace uses of DB_MASTER with DB_PRIMARYJames D. Forrester2021-04-291-4/+4
| | | | | | Just an auto-replace from codesniffer for now. Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
* ApiBlockTest: fake the current time to avoid flaky testsDaimona Eaytoy2021-03-221-3/+3
| | | | | | | | | ConvertibleTimestamp::setFakeTime is the standard for this kind of tests. This specific test just caused f069704e517f749f3fd7de0f6e801c145e6cfab1 to fail the merge-and-submit, which delayed other merges too. Change-Id: I3fc92923fee7148f3b3dce610cdb21b1712c9982
* Fix incomplete/bogus PHPDoc tags in various testsThiemo Kreuz2021-01-141-2/+1
| | | | | | | | | | | 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
* Introduce backend class for blocking usersMartin Urbanec2020-09-221-1/+1
| | | | | | | | | | | | | | Rather than having to do DatabaseBlock calls directly, and then ManualLogEntry calls to facilitate logging, let's create a BlockUser service, capable of blocking users and logging, optionally with permission checking. This should make blocking users easier for developers, for instance, AbuseFilter or CheckUser can easily benefit from this commit. Bug: T189073 Change-Id: Ifdced735b694b85116cb0e43dadbfa8e4cdb8cab
* Add tests for ApiBlock return values when blocking by useridDannyS7122020-09-191-0/+18
| | | | | | | | | To ensure the functionality doesn't break as part of Ifdced735b694b85116cb0e43dadbfa8e4cdb8cab, which refactors the block handling Bug: T189073 Change-Id: I7cb1be6532c5b32a4a77924c42483d43a290c464
* Deprecate DatabaseBlock methods moved to DatabaseBlockStoreThalia2020-09-131-1/+2
| | | | | | | | | | | | | Following 23c3c70d7ff2, soft deprecate the static methods on DatabaseBlock that have been moved to DatabaseBlockStore: * ::insert * ::delete * ::update * ::purgeExpired Update calls to the deprecated methods from core. Change-Id: I1272eb978594fd4f386bda12cbc24131ad7d882f
* Remove $wgEnablePartialBlocks config and always enable partial blocksThalia2020-03-041-12/+0
| | | | | Bug: T242912 Change-Id: Icf737140dd112dc4d222274ae40e225cb7a9d3fc