Set API limits for page restrictions to 10
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiBlockTest.php
index 07e861f..e229f0c 100644 (file)
@@ -116,24 +116,6 @@ class ApiBlockTest extends ApiTestCase {
        }
 
        public function testBlockWithTag() {
-               $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH );
-               ChangeTags::defineTag( 'custom tag' );
-
-               $this->doBlock( [ 'tags' => 'custom tag' ] );
-
-               $dbw = wfGetDB( DB_MASTER );
-               $this->assertSame( 1, (int)$dbw->selectField(
-                       [ 'change_tag', 'logging' ],
-                       'COUNT(*)',
-                       [ 'log_type' => 'block', 'ct_tag' => 'custom tag' ],
-                       __METHOD__,
-                       [],
-                       [ 'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ] ]
-               ) );
-       }
-
-       public function testBlockWithTagNewBackend() {
-               $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW );
                ChangeTags::defineTag( 'custom tag' );
 
                $this->doBlock( [ 'tags' => 'custom tag' ] );
@@ -233,6 +215,26 @@ class ApiBlockTest extends ApiTestCase {
                $this->doBlock( [ 'expiry' => '' ] );
        }
 
+       public function testBlockWithRestrictions() {
+               $this->setMwGlobals( [
+                       'wgEnablePartialBlocks' => true,
+               ] );
+
+               $title = 'Foo';
+               $page = $this->getExistingTestPage( $title );
+
+               $this->doBlock( [
+                       'partial' => true,
+                       'pagerestrictions' => $title,
+               ] );
+
+               $block = Block::newFromTarget( $this->mUser->getName() );
+
+               $this->assertFalse( $block->isSitewide() );
+               $this->assertCount( 1, $block->getRestrictions() );
+               $this->assertEquals( $title, $block->getRestrictions()[0]->getTitle()->getText() );
+       }
+
        /**
         * @expectedException ApiUsageException
         * @expectedExceptionMessage The "token" parameter must be set
@@ -249,4 +251,51 @@ class ApiBlockTest extends ApiTestCase {
                        self::$users['sysop']->getUser()
                );
        }
+
+       /**
+        * @expectedException ApiUsageException
+        * @expectedExceptionMessage Invalid value "127.0.0.1/64" for user parameter "user".
+        */
+       public function testBlockWithLargeRange() {
+               $tokens = $this->getTokens();
+
+               $this->doApiRequest(
+                       [
+                               'action' => 'block',
+                               'user' => '127.0.0.1/64',
+                               'reason' => 'Some reason',
+                               'token' => $tokens['blocktoken'],
+                       ],
+                       null,
+                       false,
+                       self::$users['sysop']->getUser()
+               );
+       }
+
+       /**
+        * @expectedException ApiUsageException
+        * @expectedExceptionMessage Too many values supplied for parameter "pagerestrictions". The
+        * limit is 10.
+        */
+       public function testBlockingToManyRestrictions() {
+               $this->setMwGlobals( [
+                       'wgEnablePartialBlocks' => true,
+               ] );
+
+               $tokens = $this->getTokens();
+
+               $this->doApiRequest(
+                       [
+                               'action' => 'block',
+                               'user' => $this->mUser->getName(),
+                               'reason' => 'Some reason',
+                               'partial' => true,
+                               'pagerestrictions' => 'One|Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten|Eleven',
+                               'token' => $tokens['blocktoken'],
+                       ],
+                       null,
+                       false,
+                       self::$users['sysop']->getUser()
+               );
+       }
 }