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
72 lines
1.9 KiB
PHP
72 lines
1.9 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
/**
|
|
* @group Blocking
|
|
* @group Database
|
|
* @coversDefaultClass BlockUser
|
|
*/
|
|
class BlockUserTest extends MediaWikiIntegrationTestCase {
|
|
/** @var User */
|
|
private $user;
|
|
|
|
/** @var User */
|
|
private $performer;
|
|
|
|
/** @var BlockUserFactory */
|
|
private $blockUserFactory;
|
|
|
|
protected function setUp() : void {
|
|
parent::setUp();
|
|
|
|
// Prepare users
|
|
$this->user = $this->getTestUser()->getUser();
|
|
$this->performer = $this->getTestSysop()->getUser();
|
|
|
|
// Prepare factory
|
|
$this->blockUserFactory = MediaWikiServices::getInstance()->getBlockUserFactory();
|
|
}
|
|
|
|
/**
|
|
* @covers MediaWiki\Block\BlockUser::placeBlock
|
|
*/
|
|
public function testValidTarget() {
|
|
$status = $this->blockUserFactory->newBlockUser(
|
|
$this->user,
|
|
$this->performer,
|
|
'infinity',
|
|
'test block'
|
|
)->placeBlock();
|
|
$this->assertTrue( $status->isOK() );
|
|
$block = $this->user->getBlock();
|
|
$this->assertSame( 'test block', $block->getReasonComment()->text );
|
|
$this->assertInstanceOf( DatabaseBlock::class, $block );
|
|
$this->assertFalse( $block->getHideName() );
|
|
$this->assertFalse( $block->isCreateAccountBlocked() );
|
|
$this->assertTrue( $block->isUsertalkEditAllowed() );
|
|
$this->assertFalse( $block->isEmailBlocked() );
|
|
$this->assertTrue( $block->isAutoblocking() );
|
|
}
|
|
|
|
/**
|
|
* @covers MediaWiki\BLock\BlockUser::placeBlock
|
|
*/
|
|
public function testHideUser() {
|
|
$status = $this->blockUserFactory->newBlockUser(
|
|
$this->user,
|
|
$this->getTestUser( [ 'sysop', 'suppress' ] )->getUser(),
|
|
'infinity',
|
|
'test hideuser',
|
|
[
|
|
'isHideUser' => true
|
|
]
|
|
)->placeBlock();
|
|
$this->assertTrue( $status->isOK() );
|
|
$block = $this->user->getBlock();
|
|
$this->assertInstanceOf( DatabaseBlock::class, $block );
|
|
$this->assertSame( 'test hideuser', $block->getReasonComment()->text );
|
|
$this->assertTrue( $block->getHideName() );
|
|
}
|
|
}
|