Create UnblockUserFactory service, which returns an UnblockUser. UnblockUser::unblock replaces SpecialUnblock::processUnblock, which is now deprecated. Update SpecialUnblock and ApiUnblock to use UnblockUser, removing the API module's dependency on the special page. Update SpecialUnblock::processUIUnblock to use UnblockUser, and mark it for internal use only. It now returns a Status object. Also add BlockPermissionChecker::checkBasePermissions, which checks for the 'block' right and the 'hideuser' right if necessary. Bug: T250020 Change-Id: Ide31da469297f4582ad0e3f7f1a7c40d542923f8
88 lines
1.8 KiB
PHP
88 lines
1.8 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
/**
|
|
* @group Blocking
|
|
* @group Database
|
|
* @coversDefaultClass UnblockUser
|
|
*/
|
|
class UnblockUserTest extends MediaWikiTestCase {
|
|
/**
|
|
* @var User
|
|
*/
|
|
private $user;
|
|
|
|
/**
|
|
* @var User
|
|
*/
|
|
private $performer;
|
|
|
|
/**
|
|
* @var UnblockUserFactory
|
|
*/
|
|
private $unblockUserFactory;
|
|
|
|
public function setUp() : void {
|
|
parent::setUp();
|
|
|
|
// Prepare users
|
|
$this->user = $this->getTestUser()->getUser();
|
|
$this->performer = $this->getTestSysop()->getUser();
|
|
|
|
// Prepare factory
|
|
$this->unblockUserFactory = MediaWikiServices::getInstance()->getUnblockUserFactory();
|
|
}
|
|
|
|
private function convertErrorsArray( $arr ) {
|
|
return array_map( function ( $el ) {
|
|
return $el[0];
|
|
}, $arr );
|
|
}
|
|
|
|
/**
|
|
* @covers MediaWiki\Block\UnblockUser::unblock
|
|
*/
|
|
public function testValidUnblock() {
|
|
$block = new DatabaseBlock( [
|
|
'address' => $this->user->getName(),
|
|
'by' => $this->performer->getId()
|
|
] );
|
|
$block->insert();
|
|
|
|
$this->assertInstanceOf( DatabaseBlock::class, $this->user->getBlock() );
|
|
$status = $this->unblockUserFactory->newUnblockUser(
|
|
$this->user,
|
|
$this->performer,
|
|
'test'
|
|
)->unblock();
|
|
$this->assertTrue( $status->isOK() );
|
|
$this->assertNotInstanceOf(
|
|
DatabaseBlock::class,
|
|
User::newFromName(
|
|
$this->user->getName()
|
|
)
|
|
->getBlock()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers MediaWiki\Block\UnblockUser::unblockUnsafe
|
|
*/
|
|
public function testNotBlocked() {
|
|
$this->user = User::newFromName( $this->user->getName() ); // Reload the user object
|
|
$status = $this->unblockUserFactory->newUnblockUser(
|
|
$this->user,
|
|
$this->performer,
|
|
'test'
|
|
)->unblock();
|
|
$this->assertFalse( $status->isOK() );
|
|
$this->assertContains(
|
|
'ipb_cant_unblock',
|
|
$this->convertErrorsArray(
|
|
$status->getErrorsArray()
|
|
)
|
|
);
|
|
}
|
|
}
|