6 class ApiBlockTest
extends ApiTestCase
{
13 function getTokens() {
14 return $this->getTokenList( self
::$users['sysop'] );
17 function addDBData() {
18 $user = User
::newFromName( 'UTApiBlockee' );
20 if ( $user->getId() == 0 ) {
21 $user->addToDatabase();
22 $user->setPassword( 'UTApiBlockeePassword' );
24 $user->saveSettings();
28 function testMakeNormalBlock() {
30 $data = $this->getTokens();
32 $user = User
::newFromName( 'UTApiBlockee' );
34 if ( !$user->getId() ) {
35 $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
38 if( !isset( $data[0]['query']['pages'] ) ) {
39 $this->markTestIncomplete( "No block token found" );
42 $keys = array_keys( $data[0]['query']['pages'] );
43 $key = array_pop( $keys );
44 $pageinfo = $data[0]['query']['pages'][$key];
46 $data = $this->doApiRequest( array(
48 'user' => 'UTApiBlockee',
49 'reason' => 'Some reason',
50 'token' => $pageinfo['blocktoken'] ), $data, false, self
::$users['sysop']->user
);
52 $block = Block
::newFromTarget('UTApiBlockee');
54 $this->assertTrue( !is_null( $block ), 'Block is valid' );
56 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
57 $this->assertEquals( 'Some reason', $block->mReason
);
58 $this->assertEquals( 'infinity', $block->mExpiry
);