Merge "tests related to API block action and its gettoken"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiBlockTest.php
index 84c0fc2..1f40b5a 100644 (file)
@@ -33,8 +33,6 @@ class ApiBlockTest extends ApiTestCase {
         * Root cause is https://gerrit.wikimedia.org/r/3434
         * Which made the Block/Unblock API to actually verify the token
         * previously always considered valid (bug 34212).
-        *
-        * @group Broken
         */
        function testMakeNormalBlock() {
 
@@ -70,4 +68,50 @@ class ApiBlockTest extends ApiTestCase {
 
        }
 
+       /**
+        * @dataProvider provideBlockUnblockAction
+        */
+       function testGetTokenUsingABlockingAction( $action ) {
+               $data = $this->doApiRequest(
+                       array(
+                               'action' => $action,
+                               'user' => 'UTApiBlockee',
+                               'gettoken' => '' ),
+                       null,
+                       false,
+                       self::$users['sysop']->user
+               );
+               $this->assertEquals( 34, strlen( $data[0][$action]["{$action}token"] ) );
+       }
+
+       /**
+        * Attempting to block without a token should give a UsageException with
+        * error message:
+        *   "The token parameter must be set"
+        *
+        * @dataProvider provideBlockUnblockAction
+        * @expectedException UsageException
+        */
+       function testBlockingActionWithNoToken( $action ) {
+               $this->doApiRequest(
+                       array(
+                               'action' => $action,
+                               'user' => 'UTApiBlockee',
+                               'reason' => 'Some reason',
+                               ),
+                       null,
+                       false,
+                       self::$users['sysop']->user
+               );
+       }
+
+       /**
+        * Just provide the 'block' and 'unblock' action to test both API calls
+        */
+       function provideBlockUnblockAction() {
+               return array(
+                       array( 'block'   ),
+                       array( 'unblock' ),
+               );
+       }
 }