3 require_once dirname( __FILE__
) . '/ApiSetup.php';
9 class ApiBlockTest
extends ApiTestSetup
{
16 function getTokens() {
17 return $this->getTokenList( $this->sysopUser
);
20 function addDBData() {
21 $user = User
::newFromName( 'UTBlockee' );
23 if ( $user->getId() == 0 ) {
24 $user->addToDatabase();
25 $user->setPassword( 'UTBlockeePassword' );
27 $user->saveSettings();
31 function testMakeNormalBlock() {
33 $data = $this->getTokens();
35 $user = User
::newFromName( 'UTBlockee' );
37 if ( !$user->getId() ) {
38 $this->markTestIncomplete( "The user UTBlockee does not exist" );
41 if( !isset( $data[0]['query']['pages'] ) ) {
42 $this->markTestIncomplete( "No block token found" );
45 $keys = array_keys( $data[0]['query']['pages'] );
46 $key = array_pop( $keys );
47 $pageinfo = $data[0]['query']['pages'][$key];
49 $data = $this->doApiRequest( array(
51 'user' => 'UTBlockee',
52 'reason' => 'Some reason',
53 'token' => $pageinfo['blocktoken'] ), $data );
55 $block = Block
::newFromTarget('UTBlockee');
57 $this->assertTrue( !is_null( $block ), 'Block is valid' );
59 $this->assertEquals( 'UTBlockee', (string)$block->getTarget() );
60 $this->assertEquals( 'Some reason', $block->mReason
);
61 $this->assertEquals( 'infinity', $block->mExpiry
);