Since MediaWiki 1.36, this method is provisioned to replace creating new instances of the services object. If one is already created and seen by the service locator, just use it. Change-Id: I9509497a8380194aa93310343b1896521070fc31
89 lines
2 KiB
PHP
89 lines
2 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tests\Block;
|
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
|
use MediaWiki\Block\UnblockUserFactory;
|
|
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
|
|
use MediaWikiIntegrationTestCase;
|
|
use User;
|
|
|
|
/**
|
|
* @group Blocking
|
|
* @group Database
|
|
*/
|
|
class UnblockUserTest extends MediaWikiIntegrationTestCase {
|
|
use MockAuthorityTrait;
|
|
|
|
/**
|
|
* @var User
|
|
*/
|
|
private $user;
|
|
|
|
/**
|
|
* @var UnblockUserFactory
|
|
*/
|
|
private $unblockUserFactory;
|
|
|
|
public function setUp(): void {
|
|
parent::setUp();
|
|
|
|
// Prepare users
|
|
$this->user = $this->getTestUser()->getUser();
|
|
|
|
// Prepare factory
|
|
$this->unblockUserFactory = $this->getServiceContainer()->getUnblockUserFactory();
|
|
}
|
|
|
|
private function convertErrorsArray( $arr ) {
|
|
return array_map( static function ( $el ) {
|
|
return $el[0];
|
|
}, $arr );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\Block\UnblockUser::unblock
|
|
*/
|
|
public function testValidUnblock() {
|
|
$performer = $this->mockAnonUltimateAuthority();
|
|
$block = new DatabaseBlock( [
|
|
'address' => $this->user->getName(),
|
|
'by' => $performer->getUser()
|
|
] );
|
|
$this->getServiceContainer()->getDatabaseBlockStore()->insertBlock( $block );
|
|
|
|
$this->assertInstanceOf( DatabaseBlock::class, $this->user->getBlock() );
|
|
$status = $this->unblockUserFactory->newUnblockUser(
|
|
$this->user,
|
|
$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->mockRegisteredUltimateAuthority(),
|
|
'test'
|
|
)->unblock();
|
|
$this->assertFalse( $status->isOK() );
|
|
$this->assertContains(
|
|
'ipb_cant_unblock',
|
|
$this->convertErrorsArray(
|
|
$status->getErrorsArray()
|
|
)
|
|
);
|
|
}
|
|
}
|