aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/integration/includes
diff options
context:
space:
mode:
authorTim Starling <tstarling@wikimedia.org>2024-12-11 12:29:29 +1100
committerTim Starling <tstarling@wikimedia.org>2024-12-16 12:35:24 +1100
commitcf1198155c27e1cb4b02ec9ab01d91c0820f0667 (patch)
tree1b141a4f45cf3aec7b9a4de696510326980261c7 /tests/phpunit/integration/includes
parentf69f8de8d2b561b8ff1e019eb94a09c62c3d3ad9 (diff)
downloadmediawikicore-cf1198155c27e1cb4b02ec9ab01d91c0820f0667.tar.gz
mediawikicore-cf1198155c27e1cb4b02ec9ab01d91c0820f0667.zip
block: Multiblocks block API
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
Diffstat (limited to 'tests/phpunit/integration/includes')
-rw-r--r--tests/phpunit/integration/includes/block/BlockUserTest.php51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/phpunit/integration/includes/block/BlockUserTest.php b/tests/phpunit/integration/includes/block/BlockUserTest.php
index 0957a9e0f52c..5b9f78c382a1 100644
--- a/tests/phpunit/integration/includes/block/BlockUserTest.php
+++ b/tests/phpunit/integration/includes/block/BlockUserTest.php
@@ -3,6 +3,7 @@
use MediaWiki\Block\BlockUserFactory;
use MediaWiki\Block\DatabaseBlock;
use MediaWiki\Block\Restriction\PageRestriction;
+use MediaWiki\MainConfigNames;
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
use MediaWiki\User\User;
@@ -244,4 +245,54 @@ class BlockUserTest extends MediaWikiIntegrationTestCase {
$this->assertContains( $IPBlock->getId(), $blockIds );
}
+ /**
+ * @covers \MediaWiki\Block\BlockUser::placeBlockUnsafe
+ */
+ public function testTooManyContribs() {
+ // Set the contrib limit to zero so that it fails with one edit
+ $this->overrideConfigValue( MainConfigNames::HideUserContribLimit, 0 );
+ // Reset the stored instance
+ $this->blockUserFactory = $this->getServiceContainer()->getBlockUserFactory();
+ // Make the edit
+ $this->editPage( 'BlockUserTest', 'test', '', NS_MAIN, $this->user );
+ // Try to block the user with the hideuser option
+ $blockStatus = $this->blockUserFactory->newBlockUser(
+ $this->user,
+ $this->getTestUser( [ 'sysop', 'suppress' ] )->getUser(),
+ 'infinity',
+ 'test block',
+ [ 'isHideUser' => true ]
+ )->placeBlockUnsafe();
+ $this->assertStatusError( 'ipb_hide_invalid', $blockStatus );
+ }
+
+ /**
+ * @covers \MediaWiki\Block\BlockUser::placeBlockUnsafe
+ */
+ public function testUpdateWithTooManyContribs() {
+ $this->overrideConfigValue( MainConfigNames::HideUserContribLimit, 0 );
+ $this->blockUserFactory = $this->getServiceContainer()->getBlockUserFactory();
+ $this->editPage( 'BlockUserTest', 'test', '', NS_MAIN, $this->user );
+ $performer = $this->getTestUser( [ 'sysop', 'suppress' ] )->getUser();
+ // Make a regular block, without the hideuser option
+ $blockStatus = $this->blockUserFactory->newBlockUser(
+ $this->user,
+ $performer,
+ 'infinity',
+ 'test block'
+ )->placeBlockUnsafe();
+ $this->assertStatusGood( $blockStatus );
+
+ // Try to change the block to include the hideuser option, which should
+ // fail due to the edit
+ $blockStatus = $this->blockUserFactory->newUpdateBlock(
+ $blockStatus->value,
+ $performer,
+ 'infinity',
+ 'test block',
+ [ 'isHideUser' => true ]
+ )->placeBlockUnsafe();
+ $this->assertStatusError( 'ipb_hide_invalid', $blockStatus );
+ }
+
}