2020-04-23 19:33:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
2020-10-04 12:26:55 +00:00
|
|
|
namespace MediaWiki\Tests\Block;
|
|
|
|
|
|
2020-04-23 19:33:03 +00:00
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
2020-10-04 12:26:55 +00:00
|
|
|
use MediaWiki\Block\UnblockUserFactory;
|
2021-03-16 01:37:57 +00:00
|
|
|
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
|
|
|
|
|
use MediaWikiIntegrationTestCase;
|
2020-10-04 12:26:55 +00:00
|
|
|
use User;
|
2020-04-23 19:33:03 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group Blocking
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2021-03-16 01:37:57 +00:00
|
|
|
class UnblockUserTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
use MockAuthorityTrait;
|
2020-04-23 19:33:03 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var User
|
|
|
|
|
*/
|
2021-03-16 01:37:57 +00:00
|
|
|
private $user;
|
2020-04-23 19:33:03 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var UnblockUserFactory
|
|
|
|
|
*/
|
|
|
|
|
private $unblockUserFactory;
|
|
|
|
|
|
2022-05-17 12:11:22 +00:00
|
|
|
protected function setUp(): void {
|
2020-04-23 19:33:03 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
// Prepare users
|
|
|
|
|
$this->user = $this->getTestUser()->getUser();
|
|
|
|
|
|
|
|
|
|
// Prepare factory
|
2021-09-05 21:12:06 +00:00
|
|
|
$this->unblockUserFactory = $this->getServiceContainer()->getUnblockUserFactory();
|
2020-04-23 19:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-16 01:37:57 +00:00
|
|
|
* @covers \MediaWiki\Block\UnblockUser::unblock
|
2020-04-23 19:33:03 +00:00
|
|
|
*/
|
|
|
|
|
public function testValidUnblock() {
|
2021-03-16 01:37:57 +00:00
|
|
|
$performer = $this->mockAnonUltimateAuthority();
|
2020-04-23 19:33:03 +00:00
|
|
|
$block = new DatabaseBlock( [
|
|
|
|
|
'address' => $this->user->getName(),
|
2021-03-16 01:37:57 +00:00
|
|
|
'by' => $performer->getUser()
|
2020-04-23 19:33:03 +00:00
|
|
|
] );
|
2021-09-05 21:12:06 +00:00
|
|
|
$this->getServiceContainer()->getDatabaseBlockStore()->insertBlock( $block );
|
2020-04-23 19:33:03 +00:00
|
|
|
|
|
|
|
|
$this->assertInstanceOf( DatabaseBlock::class, $this->user->getBlock() );
|
|
|
|
|
$status = $this->unblockUserFactory->newUnblockUser(
|
|
|
|
|
$this->user,
|
2021-03-16 01:37:57 +00:00
|
|
|
$performer,
|
2020-04-23 19:33:03 +00:00
|
|
|
'test'
|
|
|
|
|
)->unblock();
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusOK( $status );
|
2020-04-23 19:33:03 +00:00
|
|
|
$this->assertNotInstanceOf(
|
|
|
|
|
DatabaseBlock::class,
|
|
|
|
|
User::newFromName(
|
|
|
|
|
$this->user->getName()
|
|
|
|
|
)
|
|
|
|
|
->getBlock()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-16 01:37:57 +00:00
|
|
|
* @covers \MediaWiki\Block\UnblockUser::unblockUnsafe
|
2020-04-23 19:33:03 +00:00
|
|
|
*/
|
|
|
|
|
public function testNotBlocked() {
|
|
|
|
|
$this->user = User::newFromName( $this->user->getName() ); // Reload the user object
|
|
|
|
|
$status = $this->unblockUserFactory->newUnblockUser(
|
|
|
|
|
$this->user,
|
2021-03-16 01:37:57 +00:00
|
|
|
$this->mockRegisteredUltimateAuthority(),
|
2020-04-23 19:33:03 +00:00
|
|
|
'test'
|
|
|
|
|
)->unblock();
|
2022-03-04 22:00:02 +00:00
|
|
|
$this->assertStatusNotOK( $status );
|
2020-04-23 19:33:03 +00:00
|
|
|
$this->assertContains(
|
|
|
|
|
'ipb_cant_unblock',
|
2022-08-05 10:29:54 +00:00
|
|
|
array_column( $status->getErrorsArray(), 0 )
|
2020-04-23 19:33:03 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|