MediaWiki
REL1_24
|
00001 <?php 00002 00010 class ApiBlockTest extends ApiTestCase { 00011 protected function setUp() { 00012 parent::setUp(); 00013 $this->doLogin(); 00014 } 00015 00016 protected function getTokens() { 00017 return $this->getTokenList( self::$users['sysop'] ); 00018 } 00019 00020 function addDBData() { 00021 $user = User::newFromName( 'UTApiBlockee' ); 00022 00023 if ( $user->getId() == 0 ) { 00024 $user->addToDatabase(); 00025 $user->setPassword( 'UTApiBlockeePassword' ); 00026 00027 $user->saveSettings(); 00028 } 00029 } 00030 00039 public function testMakeNormalBlock() { 00040 $tokens = $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 ( !array_key_exists( 'blocktoken', $tokens ) ) { 00049 $this->markTestIncomplete( "No block token found" ); 00050 } 00051 00052 $this->doApiRequest( array( 00053 'action' => 'block', 00054 'user' => 'UTApiBlockee', 00055 'reason' => 'Some reason', 00056 'token' => $tokens['blocktoken'] ), null, false, self::$users['sysop']->user ); 00057 00058 $block = Block::newFromTarget( 'UTApiBlockee' ); 00059 00060 $this->assertTrue( !is_null( $block ), 'Block is valid' ); 00061 00062 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() ); 00063 $this->assertEquals( 'Some reason', $block->mReason ); 00064 $this->assertEquals( 'infinity', $block->mExpiry ); 00065 } 00066 00071 public function testBlockingActionWithNoToken( ) { 00072 $this->doApiRequest( 00073 array( 00074 'action' => 'block', 00075 'user' => 'UTApiBlockee', 00076 'reason' => 'Some reason', 00077 ), 00078 null, 00079 false, 00080 self::$users['sysop']->user 00081 ); 00082 } 00083 }