MediaWiki
REL1_22
|
00001 <?php 00002 00008 class ApiBlockTest extends ApiTestCase { 00009 protected function setUp() { 00010 parent::setUp(); 00011 $this->doLogin(); 00012 } 00013 00014 function getTokens() { 00015 return $this->getTokenList( self::$users['sysop'] ); 00016 } 00017 00018 function addDBData() { 00019 $user = User::newFromName( 'UTApiBlockee' ); 00020 00021 if ( $user->getId() == 0 ) { 00022 $user->addToDatabase(); 00023 $user->setPassword( 'UTApiBlockeePassword' ); 00024 00025 $user->saveSettings(); 00026 } 00027 } 00028 00037 public function testMakeNormalBlock() { 00038 $tokens = $this->getTokens(); 00039 00040 $user = User::newFromName( 'UTApiBlockee' ); 00041 00042 if ( !$user->getId() ) { 00043 $this->markTestIncomplete( "The user UTApiBlockee does not exist" ); 00044 } 00045 00046 if ( !array_key_exists( 'blocktoken', $tokens ) ) { 00047 $this->markTestIncomplete( "No block token found" ); 00048 } 00049 00050 $this->doApiRequest( array( 00051 'action' => 'block', 00052 'user' => 'UTApiBlockee', 00053 'reason' => 'Some reason', 00054 'token' => $tokens['blocktoken'] ), null, false, self::$users['sysop']->user ); 00055 00056 $block = Block::newFromTarget( 'UTApiBlockee' ); 00057 00058 $this->assertTrue( !is_null( $block ), 'Block is valid' ); 00059 00060 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() ); 00061 $this->assertEquals( 'Some reason', $block->mReason ); 00062 $this->assertEquals( 'infinity', $block->mExpiry ); 00063 } 00064 00073 public function testBlockingActionWithNoToken( $action ) { 00074 $this->doApiRequest( 00075 array( 00076 'action' => $action, 00077 'user' => 'UTApiBlockee', 00078 'reason' => 'Some reason', 00079 ), 00080 null, 00081 false, 00082 self::$users['sysop']->user 00083 ); 00084 } 00085 00089 public static function provideBlockUnblockAction() { 00090 return array( 00091 array( 'block' ), 00092 array( 'unblock' ), 00093 ); 00094 } 00095 }