7 class ApiBlockTest
extends ApiTestCase
{
14 function getTokens() {
15 return $this->getTokenList( self
::$users['sysop'] );
18 function addDBData() {
19 $user = User
::newFromName( 'UTApiBlockee' );
21 if ( $user->getId() == 0 ) {
22 $user->addToDatabase();
23 $user->setPassword( 'UTApiBlockeePassword' );
25 $user->saveSettings();
30 * This test has probably always been broken and use an invalid token
31 * Bug tracking brokenness is https://bugzilla.wikimedia.org/35646
33 * Root cause is https://gerrit.wikimedia.org/r/3434
34 * Which made the Block/Unblock API to actually verify the token
35 * previously always considered valid (bug 34212).
39 function testMakeNormalBlock() {
41 $data = $this->getTokens();
43 $user = User
::newFromName( 'UTApiBlockee' );
45 if ( !$user->getId() ) {
46 $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
49 if( !isset( $data[0]['query']['pages'] ) ) {
50 $this->markTestIncomplete( "No block token found" );
53 $keys = array_keys( $data[0]['query']['pages'] );
54 $key = array_pop( $keys );
55 $pageinfo = $data[0]['query']['pages'][$key];
57 $data = $this->doApiRequest( array(
59 'user' => 'UTApiBlockee',
60 'reason' => 'Some reason',
61 'token' => $pageinfo['blocktoken'] ), $data, false, self
::$users['sysop']->user
);
63 $block = Block
::newFromTarget('UTApiBlockee');
65 $this->assertTrue( !is_null( $block ), 'Block is valid' );
67 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
68 $this->assertEquals( 'Some reason', $block->mReason
);
69 $this->assertEquals( 'infinity', $block->mExpiry
);
74 * @dataProvider provideBlockUnblockAction
76 function testGetTokenUsingABlockingAction( $action ) {
77 $data = $this->doApiRequest(
80 'user' => 'UTApiBlockee',
84 self
::$users['sysop']->user
86 $this->assertEquals( 34, strlen( $data[0][$action]["{$action}token"] ) );
90 * Attempting to block without a token should give a UsageException with
92 * "The token parameter must be set"
94 * @dataProvider provideBlockUnblockAction
95 * @expectedException UsageException
97 function testBlockingActionWithNoToken( $action ) {
101 'user' => 'UTApiBlockee',
102 'reason' => 'Some reason',
106 self
::$users['sysop']->user
111 * Just provide the 'block' and 'unblock' action to test both API calls
113 function provideBlockUnblockAction() {