*/
class ApiBlockTest extends ApiTestCase {
- function setUp() {
+ protected function setUp() {
parent::setUp();
$this->doLogin();
}
* 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() {
'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');
}
+ /**
+ * @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' ),
+ );
+ }
}