6 use Wikimedia\TestingAccessWrapper;
32 'wgEnablePartialBlocks' =>
false,
33 'wgBlockAllowsUTEdit' =>
true,
36 $wrappedPage = TestingAccessWrapper::newFromObject( $page );
37 $fields = $wrappedPage->getFormFields();
38 $this->assertInternalType(
'array', $fields );
39 $this->assertArrayHasKey(
'Target', $fields );
40 $this->assertArrayHasKey(
'Expiry', $fields );
41 $this->assertArrayHasKey(
'Reason', $fields );
42 $this->assertArrayHasKey(
'CreateAccount', $fields );
43 $this->assertArrayHasKey(
'DisableUTEdit', $fields );
44 $this->assertArrayHasKey(
'AutoBlock', $fields );
45 $this->assertArrayHasKey(
'HardBlock', $fields );
46 $this->assertArrayHasKey(
'PreviousTarget', $fields );
47 $this->assertArrayHasKey(
'Confirm', $fields );
49 $this->assertArrayNotHasKey(
'EditingRestriction', $fields );
50 $this->assertArrayNotHasKey(
'PageRestrictions', $fields );
51 $this->assertArrayNotHasKey(
'NamespaceRestrictions', $fields );
59 'wgEnablePartialBlocks' =>
true,
62 $wrappedPage = TestingAccessWrapper::newFromObject( $page );
63 $fields = $wrappedPage->getFormFields();
65 $this->assertArrayHasKey(
'EditingRestriction', $fields );
66 $this->assertArrayHasKey(
'PageRestrictions', $fields );
67 $this->assertArrayHasKey(
'NamespaceRestrictions', $fields );
75 'wgEnablePartialBlocks' =>
false,
76 'wgBlockAllowsUTEdit' =>
true,
86 $wrappedPage = TestingAccessWrapper::newFromObject( $page );
87 $wrappedPage->target = $block->getTarget();
88 $fields = $wrappedPage->getFormFields();
90 $this->assertSame( (
string)$block->getTarget(), $fields[
'Target'][
'default'] );
91 $this->assertSame( $block->isHardblock(), $fields[
'HardBlock'][
'default'] );
92 $this->assertSame( $block->isCreateAccountBlocked(), $fields[
'CreateAccount'][
'default'] );
93 $this->assertSame( $block->isAutoblocking(), $fields[
'AutoBlock'][
'default'] );
94 $this->assertSame( !$block->isUsertalkEditAllowed(), $fields[
'DisableUTEdit'][
'default'] );
95 $this->assertSame( $block->getReason(), $fields[
'Reason'][
'default'] );
96 $this->assertSame(
'infinite', $fields[
'Expiry'][
'default'] );
104 'wgEnablePartialBlocks' =>
true,
112 $block = new \Block( [
113 'address' => $badActor->getName(),
114 'user' => $badActor->getId(),
115 'by' => $sysop->getId(),
116 'expiry' =>
'infinity',
118 'enableAutoblock' =>
true,
121 $block->setRestrictions( [
136 $wrappedPage = TestingAccessWrapper::newFromObject( $page );
137 $wrappedPage->target = $block->getTarget();
138 $fields = $wrappedPage->getFormFields();
141 $pageMars->getTitle()->getPrefixedText(),
142 $pageSaturn->getTitle()->getPrefixedText(),
145 $this->assertSame( (
string)$block->getTarget(), $fields[
'Target'][
'default'] );
146 $this->assertSame(
'partial', $fields[
'EditingRestriction'][
'default'] );
147 $this->assertSame( implode(
"\n",
$titles ), $fields[
'PageRestrictions'][
'default'] );
155 'wgEnablePartialBlocks' =>
false,
162 $expiry =
'infinity';
164 'Target' => (
string)$badActor,
165 'Expiry' =>
'infinity',
170 'CreateAccount' =>
'0',
171 'DisableUTEdit' =>
'0',
172 'DisableEmail' =>
'0',
183 $this->assertSame( $reason, $block->getReason() );
184 $this->assertSame( $expiry, $block->getExpiry() );
192 'wgEnablePartialBlocks' =>
false,
199 $block = new \Block( [
200 'address' => $badActor->getName(),
201 'user' => $badActor->getId(),
202 'by' => $sysop->getId(),
203 'expiry' =>
'infinity',
205 'enableAutoblock' =>
false,
211 $expiry =
'infinity';
213 'Target' => (
string)$badActor,
214 'Expiry' =>
'infinity',
219 'CreateAccount' =>
'0',
220 'DisableUTEdit' =>
'0',
221 'DisableEmail' =>
'0',
232 $this->assertSame( $reason, $block->getReason() );
233 $this->assertSame( $expiry, $block->getExpiry() );
234 $this->assertSame(
'1', $block->isAutoblocking() );
242 'wgEnablePartialBlocks' =>
true,
251 $pageSaturn->getTitle()->getText(),
252 $pageMars->getTitle()->getText(),
257 $expiry =
'infinity';
259 'Target' => (
string)$badActor,
260 'Expiry' =>
'infinity',
265 'CreateAccount' =>
'0',
266 'DisableUTEdit' =>
'0',
267 'DisableEmail' =>
'0',
272 'EditingRestriction' =>
'partial',
273 'PageRestrictions' => implode(
"\n",
$titles ),
274 'NamespaceRestrictions' =>
'',
281 $this->assertSame( $reason, $block->getReason() );
282 $this->assertSame( $expiry, $block->getExpiry() );
283 $this->assertCount( 2, $block->getRestrictions() );
295 'wgEnablePartialBlocks' =>
true,
304 $pageSaturn->getTitle()->getText(),
305 $pageMars->getTitle()->getText(),
311 $expiry =
'infinity';
313 'Target' => (
string)$badActor,
314 'Expiry' =>
'infinity',
319 'CreateAccount' =>
'0',
320 'DisableUTEdit' =>
'0',
321 'DisableEmail' =>
'0',
326 'EditingRestriction' =>
'partial',
327 'PageRestrictions' => implode(
"\n",
$titles ),
328 'NamespaceRestrictions' =>
'',
335 $this->assertSame( $reason, $block->getReason() );
336 $this->assertSame( $expiry, $block->getExpiry() );
337 $this->assertFalse( $block->isSitewide() );
338 $this->assertCount( 2, $block->getRestrictions() );
345 $data[
'PageRestrictions'] = $pageMars->getTitle()->getText();
351 $this->assertSame( $reason, $block->getReason() );
352 $this->assertSame( $expiry, $block->getExpiry() );
353 $this->assertFalse( $block->isSitewide() );
354 $this->assertCount( 1, $block->getRestrictions() );
360 $data[
'PageRestrictions'] =
'';
366 $this->assertSame( $reason, $block->getReason() );
367 $this->assertSame( $expiry, $block->getExpiry() );
368 $this->assertFalse( $block->isSitewide() );
369 $this->assertCount( 0, $block->getRestrictions() );
372 $data[
'EditingRestriction'] =
'sitewide';
378 $this->assertSame( $reason, $block->getReason() );
379 $this->assertSame( $expiry, $block->getExpiry() );
380 $this->assertTrue( $block->isSitewide() );
381 $this->assertCount( 0, $block->getRestrictions() );
384 $count = $this->db->selectRowCount(
385 'ipblocks_restrictions',
387 [
'ir_ipb_id' => 0 ],
390 $this->assertSame( 0, $count );
406 'wgBlockDisablesLogin' =>
false,
419 foreach ( [
'blockedUser',
'blockPerformer',
'adjustPerformer',
'adjustTarget' ]
as $var ) {
423 $block = new \Block( [
424 'address' => $blockedUser->getName(),
425 'user' => $blockedUser->getId(),
426 'by' => $blockPerformer->getId(),
427 'expiry' =>
'infinity',
429 'enableAutoblock' =>
true,
444 [
'u1',
'u2',
'u3',
'u4',
true,
'Unrelated users' ],
445 [
'u1',
'u2',
'u1',
'u4',
'ipbblocked',
'Block unrelated while blocked' ],
446 [
'u1',
'u2',
'u1',
'u1',
true,
'Has unblockself' ],
447 [
'nonsysop',
'u2',
'nonsysop',
'nonsysop',
'ipbnounblockself',
'no unblockself' ],
448 [
'nonsysop',
'nonsysop',
'nonsysop',
'nonsysop',
true,
'no unblockself but can de-selfblock' ],
449 [
'u1',
'u2',
'u1',
'u2',
true,
'Can block user who blocked' ],
457 $block = new \Block( [
458 'address' => $badActor->getName(),
459 'user' => $badActor->getId(),
460 'by' => $sysop->getId(),
461 'expiry' =>
'infinity',
463 'enableAutoblock' =>
true,
472 $this->db->delete(
'ipblocks',
'*', __METHOD__ );
473 $this->db->delete(
'ipblocks_restrictions',
'*', __METHOD__ );
483 ->disableOriginalConstructor()