8 class ApiBlockTest
extends ApiTestCase
{
9 protected function setUp() {
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() {
38 $tokens = $this->getTokens();
40 $user = User
::newFromName( 'UTApiBlockee' );
42 if ( !$user->getId() ) {
43 $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
46 if ( !array_key_exists( 'blocktoken', $tokens ) ) {
47 $this->markTestIncomplete( "No block token found" );
50 $this->doApiRequest( array(
52 'user' => 'UTApiBlockee',
53 'reason' => 'Some reason',
54 'token' => $tokens['blocktoken'] ), null, false, self
::$users['sysop']->user
);
56 $block = Block
::newFromTarget( 'UTApiBlockee' );
58 $this->assertTrue( !is_null( $block ), 'Block is valid' );
60 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
61 $this->assertEquals( 'Some reason', $block->mReason
);
62 $this->assertEquals( 'infinity', $block->mExpiry
);
66 * Attempting to block without a token should give a UsageException with
68 * "The token parameter must be set"
70 * @dataProvider provideBlockUnblockAction
71 * @expectedException UsageException
73 function testBlockingActionWithNoToken( $action ) {
77 'user' => 'UTApiBlockee',
78 'reason' => 'Some reason',
82 self
::$users['sysop']->user
87 * Just provide the 'block' and 'unblock' action to test both API calls
89 public static function provideBlockUnblockAction() {