MediaWiki
REL1_21
|
00001 <?php 00002 00008 class ApiBlockTest extends ApiTestCase { 00009 00010 protected function setUp() { 00011 parent::setUp(); 00012 $this->doLogin(); 00013 } 00014 00015 function getTokens() { 00016 return $this->getTokenList( self::$users['sysop'] ); 00017 } 00018 00019 function addDBData() { 00020 $user = User::newFromName( 'UTApiBlockee' ); 00021 00022 if ( $user->getId() == 0 ) { 00023 $user->addToDatabase(); 00024 $user->setPassword( 'UTApiBlockeePassword' ); 00025 00026 $user->saveSettings(); 00027 } 00028 } 00029 00038 function testMakeNormalBlock() { 00039 00040 $data = $this->getTokens(); 00041 00042 $user = User::newFromName( 'UTApiBlockee' ); 00043 00044 if ( !$user->getId() ) { 00045 $this->markTestIncomplete( "The user UTApiBlockee does not exist" ); 00046 } 00047 00048 if ( !isset( $data[0]['query']['pages'] ) ) { 00049 $this->markTestIncomplete( "No block token found" ); 00050 } 00051 00052 $keys = array_keys( $data[0]['query']['pages'] ); 00053 $key = array_pop( $keys ); 00054 $pageinfo = $data[0]['query']['pages'][$key]; 00055 00056 $data = $this->doApiRequest( array( 00057 'action' => 'block', 00058 'user' => 'UTApiBlockee', 00059 'reason' => 'Some reason', 00060 'token' => $pageinfo['blocktoken'] ), null, false, self::$users['sysop']->user ); 00061 00062 $block = Block::newFromTarget( 'UTApiBlockee' ); 00063 00064 $this->assertTrue( !is_null( $block ), 'Block is valid' ); 00065 00066 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() ); 00067 $this->assertEquals( 'Some reason', $block->mReason ); 00068 $this->assertEquals( 'infinity', $block->mExpiry ); 00069 00070 } 00071 00080 function testBlockingActionWithNoToken( $action ) { 00081 $this->doApiRequest( 00082 array( 00083 'action' => $action, 00084 'user' => 'UTApiBlockee', 00085 'reason' => 'Some reason', 00086 ), 00087 null, 00088 false, 00089 self::$users['sysop']->user 00090 ); 00091 } 00092 00096 function provideBlockUnblockAction() { 00097 return array( 00098 array( 'block' ), 00099 array( 'unblock' ), 00100 ); 00101 } 00102 }