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();
29 function testMakeNormalBlock() {
31 $data = $this->getTokens();
33 $user = User
::newFromName( 'UTApiBlockee' );
35 if ( !$user->getId() ) {
36 $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
39 if( !isset( $data[0]['query']['pages'] ) ) {
40 $this->markTestIncomplete( "No block token found" );
43 $keys = array_keys( $data[0]['query']['pages'] );
44 $key = array_pop( $keys );
45 $pageinfo = $data[0]['query']['pages'][$key];
47 $data = $this->doApiRequest( array(
49 'user' => 'UTApiBlockee',
50 'reason' => 'Some reason',
51 'token' => $pageinfo['blocktoken'] ), $data, false, self
::$users['sysop']->user
);
53 $block = Block
::newFromTarget('UTApiBlockee');
55 $this->assertTrue( !is_null( $block ), 'Block is valid' );
57 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
58 $this->assertEquals( 'Some reason', $block->mReason
);
59 $this->assertEquals( 'infinity', $block->mExpiry
);