10 class ApiBlockTest
extends ApiTestCase
{
11 protected function setUp() {
16 protected function getTokens() {
17 return $this->getTokenList( self
::$users['sysop'] );
20 function addDBData() {
21 $user = User
::newFromName( 'UTApiBlockee' );
23 if ( $user->getId() == 0 ) {
24 $user->addToDatabase();
25 $user->setPassword( 'UTApiBlockeePassword' );
27 $user->saveSettings();
32 * This test has probably always been broken and use an invalid token
33 * Bug tracking brokenness is https://bugzilla.wikimedia.org/35646
35 * Root cause is https://gerrit.wikimedia.org/r/3434
36 * Which made the Block/Unblock API to actually verify the token
37 * previously always considered valid (bug 34212).
39 public function testMakeNormalBlock() {
40 $tokens = $this->getTokens();
42 $user = User
::newFromName( 'UTApiBlockee' );
44 if ( !$user->getId() ) {
45 $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
48 if ( !array_key_exists( 'blocktoken', $tokens ) ) {
49 $this->markTestIncomplete( "No block token found" );
52 $this->doApiRequest( array(
54 'user' => 'UTApiBlockee',
55 'reason' => 'Some reason',
56 'token' => $tokens['blocktoken'] ), null, false, self
::$users['sysop']->user
);
58 $block = Block
::newFromTarget( 'UTApiBlockee' );
60 $this->assertTrue( !is_null( $block ), 'Block is valid' );
62 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
63 $this->assertEquals( 'Some reason', $block->mReason
);
64 $this->assertEquals( 'infinity', $block->mExpiry
);
68 * @expectedException UsageException
69 * @expectedExceptionMessage The token parameter must be set
71 public function testBlockingActionWithNoToken( ) {
75 'user' => 'UTApiBlockee',
76 'reason' => 'Some reason',
80 self
::$users['sysop']->user