From cdbfe8db8673f25c3caf70a1dc8c9b23dad54f45 Mon Sep 17 00:00:00 2001 From: Reedy Date: Tue, 3 Apr 2012 21:02:27 +0100 Subject: [PATCH] tests related to API block action and its gettoken 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 | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php index 84c0fc2414..2fa510ce64 100644 --- a/tests/phpunit/includes/api/ApiBlockTest.php +++ b/tests/phpunit/includes/api/ApiBlockTest.php @@ -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' ), + ); + } } -- 2.20.1