| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Block; |
| 4 |
|
| 5 |
use MediaWiki\Block\DatabaseBlock; |
| 6 |
use MediaWiki\Block\UnblockUserFactory; |
| 7 |
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait; |
| 8 |
use MediaWiki\User\User; |
| 9 |
use MediaWikiIntegrationTestCase; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class UnblockUserTest extends MediaWikiIntegrationTestCase { |
| 16 |
use MockAuthorityTrait; |
| 17 |
|
| 18 |
private User $user; |
| 19 |
private UnblockUserFactory $unblockUserFactory; |
| 20 |
|
| 21 |
protected function setUp(): void { |
| 22 |
parent::setUp(); |
| 23 |
|
| 24 |
|
| 25 |
$this->user = $this->getTestUser()->getUser(); |
| 26 |
|
| 27 |
|
| 28 |
$this->unblockUserFactory = $this->getServiceContainer()->getUnblockUserFactory(); |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public function testValidUnblock() { |
| 35 |
$performer = $this->mockRegisteredUltimateAuthority(); |
| 36 |
$block = new DatabaseBlock( [ |
| 37 |
'address' => $this->user->getName(), |
| 38 |
'by' => $performer->getUser() |
| 39 |
] ); |
| 40 |
$this->getServiceContainer()->getDatabaseBlockStore()->insertBlock( $block ); |
| 41 |
|
| 42 |
$this->assertInstanceOf( DatabaseBlock::class, $this->user->getBlock() ); |
| 43 |
$status = $this->unblockUserFactory->newUnblockUser( |
| 44 |
$this->user, |
| 45 |
$performer, |
| 46 |
'test' |
| 47 |
)->unblock(); |
| 48 |
$this->assertStatusOK( $status ); |
| 49 |
$this->assertNotInstanceOf( |
| 50 |
DatabaseBlock::class, |
| 51 |
User::newFromName( |
| 52 |
$this->user->getName() |
| 53 |
) |
| 54 |
->getBlock() |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public function testNotBlocked() { |
| 62 |
$this->user = User::newFromName( $this->user->getName() ); |
| 63 |
$status = $this->unblockUserFactory->newUnblockUser( |
| 64 |
$this->user, |
| 65 |
$this->mockRegisteredUltimateAuthority(), |
| 66 |
'test' |
| 67 |
)->unblock(); |
| 68 |
$this->assertStatusError( 'ipb_cant_unblock', $status ); |
| 69 |
} |
| 70 |
} |