Merge "Fixed dependencies for jquery.collapsibleTabs"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiBlockTest.php
index d9ea7b5..52f1d28 100644 (file)
@@ -6,7 +6,7 @@
  */
 class ApiBlockTest extends ApiTestCase {
 
-       function setUp() {
+       protected function setUp() {
                parent::setUp();
                $this->doLogin();
        }
@@ -26,6 +26,14 @@ class ApiBlockTest extends ApiTestCase {
                }
        }
 
+       /**
+        * This test has probably always been broken and use an invalid token
+        * Bug tracking brokenness is https://bugzilla.wikimedia.org/35646
+        *
+        * 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).
+        */
        function testMakeNormalBlock() {
 
                $data = $this->getTokens();
@@ -48,7 +56,7 @@ class ApiBlockTest extends ApiTestCase {
                        'action' => 'block',
                        'user' => 'UTApiBlockee',
                        'reason' => 'Some reason',
-                       'token' => $pageinfo['blocktoken'] ), $data, false, self::$users['sysop']->user );
+                       'token' => $pageinfo['blocktoken'] ), null, false, self::$users['sysop']->user );
 
                $block = Block::newFromTarget('UTApiBlockee');
 
@@ -60,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' ),
+               );
+       }
 }