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).
37 function testMakeNormalBlock() {
39 $data = $this->getTokens();
41 $user = User
::newFromName( 'UTApiBlockee' );
43 if ( !$user->getId() ) {
44 $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
47 if( !isset( $data[0]['query']['pages'] ) ) {
48 $this->markTestIncomplete( "No block token found" );
51 $keys = array_keys( $data[0]['query']['pages'] );
52 $key = array_pop( $keys );
53 $pageinfo = $data[0]['query']['pages'][$key];
55 $data = $this->doApiRequest( array(
57 'user' => 'UTApiBlockee',
58 'reason' => 'Some reason',
59 'token' => $pageinfo['blocktoken'] ), null, false, self
::$users['sysop']->user
);
61 $block = Block
::newFromTarget('UTApiBlockee');
63 $this->assertTrue( !is_null( $block ), 'Block is valid' );
65 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
66 $this->assertEquals( 'Some reason', $block->mReason
);
67 $this->assertEquals( 'infinity', $block->mExpiry
);
72 * @dataProvider provideBlockUnblockAction
74 function testGetTokenUsingABlockingAction( $action ) {
75 $data = $this->doApiRequest(
78 'user' => 'UTApiBlockee',
82 self
::$users['sysop']->user
84 $this->assertEquals( 34, strlen( $data[0][$action]["{$action}token"] ) );
88 * Attempting to block without a token should give a UsageException with
90 * "The token parameter must be set"
92 * @dataProvider provideBlockUnblockAction
93 * @expectedException UsageException
95 function testBlockingActionWithNoToken( $action ) {
99 'user' => 'UTApiBlockee',
100 'reason' => 'Some reason',
104 self
::$users['sysop']->user
109 * Just provide the 'block' and 'unblock' action to test both API calls
111 function provideBlockUnblockAction() {