1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
<?php
use MediaWiki\Block\DatabaseBlock;
use MediaWiki\MainConfigNames;
use MediaWiki\Request\FauxRequest;
use MediaWiki\Specials\SpecialUnblock;
use MediaWiki\Title\Title;
use Wikimedia\TestingAccessWrapper;
/**
* @group Blocking
* @group Database
* @coversDefaultClass \MediaWiki\Specials\SpecialUnblock
*/
class SpecialUnblockTest extends SpecialPageTestBase {
/**
* @inheritDoc
*/
protected function newSpecialPage() {
$services = $this->getServiceContainer();
return new SpecialUnblock(
$services->getUnblockUserFactory(),
$services->getBlockUtils(),
$services->getDatabaseBlockStore(),
$services->getUserNameUtils(),
$services->getUserNamePrefixSearch(),
$services->getWatchlistManager()
);
}
/**
* @dataProvider provideGetFields
* @covers ::getFields
*/
public function testGetFields( $target, $expected ) {
$page = TestingAccessWrapper::newFromObject( $this->newSpecialPage() );
$page->target = $target;
$page->block = new DatabaseBlock( [
'address' => '1.2.3.4',
'by' => $this->getTestSysop()->getUser(),
] );
$fields = $page->getFields();
$this->assertIsArray( $fields );
foreach ( $expected as $fieldName ) {
$this->assertArrayHasKey( $fieldName, $fields );
}
}
public static function provideGetFields() {
return [
'No target specified' => [
'',
[ 'Target', 'Reason' ],
],
'Target is not blocked' => [
'1.1.1.1',
[ 'Target', 'Reason' ],
],
'Target is blocked' => [
'1.2.3.4',
[ 'Target', 'Reason', 'Name' ],
],
];
}
/**
* @dataProvider provideProcessUnblockErrors
* @covers ::execute
*/
public function testProcessUnblockErrors( $options, $expected ) {
$performer = $this->getTestSysop()->getUser();
$target = '1.1.1.1';
if ( !empty( $options['block'] ) ) {
$block = new DatabaseBlock( [
'address' => $target,
'by' => $performer,
'hideName' => true,
] );
$this->getServiceContainer()->getDatabaseBlockStore()->insertBlock( $block );
}
if ( !empty( $options['readOnly'] ) ) {
$this->overrideConfigValue( MainConfigNames::ReadOnly, true );
$this->expectException( ReadOnlyError::class );
}
if ( isset( $options['permissions'] ) ) {
$this->overrideUserPermissions( $performer, $options['permissions'] );
}
$request = new FauxRequest( [
'wpTarget' => $target,
'wpReason' => '',
], true );
[ $html, ] = $this->executeSpecialPage( '', $request, 'qqx', $performer );
$this->assertStringContainsString( $expected, $html );
}
public static function provideProcessUnblockErrors() {
return [
'Target is not blocked' => [
[
'permissions' => [ 'block', 'hideuser' => true ],
],
'ipb_cant_unblock',
],
'Wrong permissions for unhiding user' => [
[
'block' => true,
'permissions' => [ 'block', 'hideuser' => false ],
],
'unblock-hideuser',
],
'Delete block failed' => [
[
'block' => true,
'permissions' => [ 'block', 'hideuser' ],
'readOnly' => true,
],
'ipb_cant_unblock',
],
];
}
/**
* @covers ::execute
*/
public function testProcessUnblockErrorsUnblockSelf() {
$performer = $this->getTestSysop()->getUser();
$this->overrideUserPermissions( $performer, [ 'block', 'unblockself' => false ] );
// Blocker must be different user for unblock self to be disallowed
$blocker = $this->getTestUser()->getUser();
$block = new DatabaseBlock( [
'by' => $blocker,
'address' => $performer,
] );
$this->getServiceContainer()->getDatabaseBlockStore()->insertBlock( $block );
$request = new FauxRequest( [
'wpTarget' => $performer->getName(),
'wpReason' => '',
], true );
[ $html, ] = $this->executeSpecialPage( '', $request, 'qqx', $performer );
$this->assertStringContainsString( 'ipbnounblockself', $html );
}
/**
* @covers ::execute
*/
public function testWatched() {
$performer = $this->getTestSysop()->getUser();
$target = '1.2.3.4';
$block = new DatabaseBlock( [
'by' => $performer,
'address' => $target,
] );
$this->getServiceContainer()->getDatabaseBlockStore()->insertBlock( $block );
$request = new FauxRequest( [
'wpTarget' => $target,
'wpReason' => '',
'wpWatch' => '1',
], true );
$this->executeSpecialPage( '', $request, 'qqx', $performer );
$userPage = Title::makeTitle( NS_USER, $target );
$this->assertTrue( $this->getServiceContainer()->getWatchlistManager()
->isWatched( $performer, $userPage ) );
}
}
|