X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiBlockTest.php;h=e06f82814814df24b1272c9af52cd20632847d25;hb=756827cae7483b5aae7d45228e89ae4cfc203364;hp=01455edcafeff974a41268954ef19ff2de4a0c75;hpb=1e1c24d12c94a90442de5af89df393d1042a246a;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php index 01455edcaf..e06f828148 100644 --- a/tests/phpunit/includes/api/ApiBlockTest.php +++ b/tests/phpunit/includes/api/ApiBlockTest.php @@ -1,5 +1,6 @@ mUser = $this->getMutableTestUser()->getUser(); + $this->setMwGlobals( 'wgBlockCIDRLimit', [ + 'IPv4' => 16, + 'IPv6' => 19, + ] ); } protected function getTokens() { @@ -40,7 +45,6 @@ class ApiBlockTest extends ApiTestCase { $tokens = $this->getTokens(); $this->assertNotNull( $this->mUser, 'Sanity check' ); - $this->assertNotSame( 0, $this->mUser->getId(), 'Sanity check' ); $this->assertArrayHasKey( 'blocktoken', $tokens, 'Sanity check' ); @@ -57,12 +61,12 @@ class ApiBlockTest extends ApiTestCase { $ret = $this->doApiRequest( array_merge( $params, $extraParams ), null, false, $blocker ); - $block = Block::newFromTarget( $this->mUser->getName() ); + $block = DatabaseBlock::newFromTarget( $this->mUser->getName() ); $this->assertTrue( !is_null( $block ), 'Block is valid' ); $this->assertSame( $this->mUser->getName(), (string)$block->getTarget() ); - $this->assertSame( 'Some reason', $block->mReason ); + $this->assertSame( 'Some reason', $block->getReason() ); return $ret; } @@ -89,7 +93,7 @@ class ApiBlockTest extends ApiTestCase { 'You cannot block or unblock other users because you are yourself blocked.' ); $blocked = $this->getMutableTestUser( [ 'sysop' ] )->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $blocked->getName(), 'by' => self::$users['sysop']->getUser()->getId(), 'reason' => 'Capriciousness', @@ -175,6 +179,12 @@ class ApiBlockTest extends ApiTestCase { } public function testBlockWithEmailBlock() { + $this->setMwGlobals( [ + 'wgEnableEmail' => true, + 'wgEnableUserEmail' => true, + 'wgSysopEmailBans' => true, + ] ); + $res = $this->doBlock( [ 'noemail' => '' ] ); $dbw = wfGetDB( DB_MASTER ); @@ -187,6 +197,12 @@ class ApiBlockTest extends ApiTestCase { } public function testBlockWithProhibitedEmailBlock() { + $this->setMwGlobals( [ + 'wgEnableEmail' => true, + 'wgEnableUserEmail' => true, + 'wgSysopEmailBans' => true, + ] ); + $this->setExpectedException( ApiUsageException::class, "You don't have permission to block users from sending email through the wiki." ); @@ -225,7 +241,7 @@ class ApiBlockTest extends ApiTestCase { $this->doBlock(); - $block = Block::newFromTarget( $this->mUser->getName() ); + $block = DatabaseBlock::newFromTarget( $this->mUser->getName() ); $this->assertTrue( $block->isSitewide() ); $this->assertCount( 0, $block->getRestrictions() ); @@ -246,7 +262,7 @@ class ApiBlockTest extends ApiTestCase { 'namespacerestrictions' => $namespace, ] ); - $block = Block::newFromTarget( $this->mUser->getName() ); + $block = DatabaseBlock::newFromTarget( $this->mUser->getName() ); $this->assertFalse( $block->isSitewide() ); $this->assertCount( 2, $block->getRestrictions() ); @@ -319,4 +335,18 @@ class ApiBlockTest extends ApiTestCase { self::$users['sysop']->getUser() ); } + + public function testRangeBlock() { + $this->mUser = User::newFromName( '128.0.0.0/16', false ); + $this->doBlock(); + } + + /** + * @expectedException ApiUsageException + * @expectedExceptionMessage Range blocks larger than /16 are not allowed. + */ + public function testVeryLargeRangeBlock() { + $this->mUser = User::newFromName( '128.0.0.0/1', false ); + $this->doBlock(); + } }