Merge "resourceloader: Add test coverage for WikiModule::getType"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiBlockTest.php
index 1c53147..b29d333 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 
+use MediaWiki\Block\DatabaseBlock;
 use MediaWiki\Block\Restriction\PageRestriction;
 use MediaWiki\Block\Restriction\NamespaceRestriction;
 
@@ -21,6 +22,10 @@ class ApiBlockTest extends ApiTestCase {
                );
 
                $this->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,7 +61,7 @@ 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' );
 
@@ -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',
@@ -146,6 +150,8 @@ class ApiBlockTest extends ApiTestCase {
                $this->setMwGlobals( 'wgRevokePermissions',
                        [ 'user' => [ 'applychangetags' => true ] ] );
 
+               $this->resetServices();
+
                $this->doBlock( [ 'tags' => 'custom tag' ] );
        }
 
@@ -156,6 +162,7 @@ class ApiBlockTest extends ApiTestCase {
                $this->mergeMwGlobalArrayValue( 'wgGroupPermissions',
                        [ 'sysop' => $newPermissions ] );
 
+               $this->resetServices();
                $res = $this->doBlock( [ 'hidename' => '' ] );
 
                $dbw = wfGetDB( DB_MASTER );
@@ -205,6 +212,8 @@ class ApiBlockTest extends ApiTestCase {
                $this->setMwGlobals( 'wgRevokePermissions',
                        [ 'sysop' => [ 'blockemail' => true ] ] );
 
+               $this->resetServices();
+
                $this->doBlock( [ 'noemail' => '' ] );
        }
 
@@ -237,7 +246,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() );
@@ -258,7 +267,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() );
@@ -310,7 +319,7 @@ class ApiBlockTest extends ApiTestCase {
         * @expectedExceptionMessage Too many values supplied for parameter "pagerestrictions". The
         * limit is 10.
         */
-       public function testBlockingToManyPageRestrictions() {
+       public function testBlockingTooManyPageRestrictions() {
                $this->setMwGlobals( [
                        'wgEnablePartialBlocks' => true,
                ] );
@@ -331,4 +340,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();
+       }
 }