tests related to API block action and its gettoken
authorReedy <reedy@wikimedia.org>
Tue, 3 Apr 2012 20:02:27 +0000 (21:02 +0100)
committerAntoine Musso <hashar@free.fr>
Tue, 3 Apr 2012 20:27:57 +0000 (22:27 +0200)
Add tests for:
 - action=block and action=unblock gettoken
 - attempting to block or unblock a user with no token passed.

Patchset2: use a provider to have tests run against both 'block' and
'unblock' actions.

Change-Id: I686348ff4e2fe419c556acea2fa59dd203dc9440

tests/phpunit/includes/api/ApiBlockTest.php

index 84c0fc2..2fa510c 100644 (file)
@@ -70,4 +70,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' ),
+               );
+       }
 }