X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fspecials%2FSpecialBlockTest.php;h=0643e0e5ad1c47a8029be798449d48a498aff0cb;hb=d7678fa45e949a5a5eaa369b45e48667a6132c07;hp=080c6e4c43c7064db7dbebf3bc666cae68fcaa92;hpb=9aedec343e124c7fcdff2be634cff0cf12c93334;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/specials/SpecialBlockTest.php b/tests/phpunit/includes/specials/SpecialBlockTest.php index 080c6e4c43..0643e0e5ad 100644 --- a/tests/phpunit/includes/specials/SpecialBlockTest.php +++ b/tests/phpunit/includes/specials/SpecialBlockTest.php @@ -2,6 +2,7 @@ use MediaWiki\Block\BlockRestriction; use MediaWiki\Block\Restriction\PageRestriction; +use MediaWiki\Block\Restriction\NamespaceRestriction; use Wikimedia\TestingAccessWrapper; /** @@ -28,6 +29,7 @@ class SpecialBlockTest extends SpecialPageTestBase { public function testGetFormFields() { $this->setMwGlobals( [ 'wgEnablePartialBlocks' => false, + 'wgBlockAllowsUTEdit' => true, ] ); $page = $this->newSpecialPage(); $wrappedPage = TestingAccessWrapper::newFromObject( $page ); @@ -38,7 +40,6 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertArrayHasKey( 'Reason', $fields ); $this->assertArrayHasKey( 'CreateAccount', $fields ); $this->assertArrayHasKey( 'DisableUTEdit', $fields ); - $this->assertArrayHasKey( 'DisableUTEdit', $fields ); $this->assertArrayHasKey( 'AutoBlock', $fields ); $this->assertArrayHasKey( 'HardBlock', $fields ); $this->assertArrayHasKey( 'PreviousTarget', $fields ); @@ -46,6 +47,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertArrayNotHasKey( 'EditingRestriction', $fields ); $this->assertArrayNotHasKey( 'PageRestrictions', $fields ); + $this->assertArrayNotHasKey( 'NamespaceRestrictions', $fields ); } /** @@ -61,6 +63,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertArrayHasKey( 'EditingRestriction', $fields ); $this->assertArrayHasKey( 'PageRestrictions', $fields ); + $this->assertArrayHasKey( 'NamespaceRestrictions', $fields ); } /** @@ -69,6 +72,7 @@ class SpecialBlockTest extends SpecialPageTestBase { public function testMaybeAlterFormDefaults() { $this->setMwGlobals( [ 'wgEnablePartialBlocks' => false, + 'wgBlockAllowsUTEdit' => true, ] ); $block = $this->insertBlock(); @@ -116,6 +120,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $block->setRestrictions( [ new PageRestriction( 0, $pageSaturn->getId() ), new PageRestriction( 0, $pageMars->getId() ), + new NamespaceRestriction( 0, NS_TALK ), ] ); $block->insert(); @@ -229,7 +234,7 @@ class SpecialBlockTest extends SpecialPageTestBase { /** * @covers ::processForm() */ - public function testProcessFormRestictions() { + public function testProcessFormRestrictions() { $this->setMwGlobals( [ 'wgEnablePartialBlocks' => true, ] ); @@ -263,6 +268,7 @@ class SpecialBlockTest extends SpecialPageTestBase { 'Watch' => '0', 'EditingRestriction' => 'partial', 'PageRestrictions' => implode( "\n", $titles ), + 'NamespaceRestrictions' => '', ]; $result = $page->processForm( $data, $context ); @@ -316,6 +322,7 @@ class SpecialBlockTest extends SpecialPageTestBase { 'Watch' => '0', 'EditingRestriction' => 'partial', 'PageRestrictions' => implode( "\n", $titles ), + 'NamespaceRestrictions' => '', ]; $result = $page->processForm( $data, $context ); @@ -380,6 +387,63 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertSame( 0, $count ); } + /** + * @dataProvider provideCheckUnblockSelf + * @covers ::checkUnblockSelf + */ + public function testCheckUnblockSelf( + $blockedUser, + $blockPerformer, + $adjustPerformer, + $adjustTarget, + $expectedResult, + $reason + ) { + $this->setGroupPermissions( 'sysop', 'unblockself', true ); + $this->setGroupPermissions( 'user', 'block', true ); + // Getting errors about creating users in db in provider. + // Need to use mutable to ensure different named testusers. + $users = [ + 'u1' => TestUserRegistry::getMutableTestUser( __CLASS__, 'sysop' )->getUser(), + 'u2' => TestUserRegistry::getMutableTestUser( __CLASS__, 'sysop' )->getUser(), + 'u3' => TestUserRegistry::getMutableTestUser( __CLASS__, 'sysop' )->getUser(), + 'u4' => TestUserRegistry::getMutableTestUser( __CLASS__, 'sysop' )->getUser(), + 'nonsysop' => $this->getTestUser()->getUser() + ]; + foreach ( [ 'blockedUser', 'blockPerformer', 'adjustPerformer', 'adjustTarget' ] as $var ) { + $$var = $users[$$var]; + } + + $block = new \Block( [ + 'address' => $blockedUser->getName(), + 'user' => $blockedUser->getId(), + 'by' => $blockPerformer->getId(), + 'expiry' => 'infinity', + 'sitewide' => 1, + 'enableAutoblock' => true, + ] ); + + $block->insert(); + + $this->assertSame( + SpecialBlock::checkUnblockSelf( $adjustTarget, $adjustPerformer ), + $expectedResult, + $reason + ); + } + + public function provideCheckUnblockSelf() { + // 'blockedUser', 'blockPerformer', 'adjustPerformer', 'adjustTarget' + return [ + [ 'u1', 'u2', 'u3', 'u4', true, 'Unrelated users' ], + [ 'u1', 'u2', 'u1', 'u4', 'ipbblocked', 'Block unrelated while blocked' ], + [ 'u1', 'u2', 'u1', 'u1', true, 'Has unblockself' ], + [ 'nonsysop', 'u2', 'nonsysop', 'nonsysop', 'ipbnounblockself', 'no unblockself' ], + [ 'nonsysop', 'nonsysop', 'nonsysop', 'nonsysop', true, 'no unblockself but can de-selfblock' ], + [ 'u1', 'u2', 'u1', 'u2', true, 'Can block user who blocked' ], + ]; + } + protected function insertBlock() { $badActor = $this->getTestUser()->getUser(); $sysop = $this->getTestSysop()->getUser();