MediaWiki
REL1_19
|
00001 <?php 00002 00007 class BlockTest extends MediaWikiLangTestCase { 00008 00009 private $block, $madeAt; 00010 00011 /* variable used to save up the blockID we insert in this test suite */ 00012 private $blockId; 00013 00014 function setUp() { 00015 global $wgContLang; 00016 parent::setUp(); 00017 $wgContLang = Language::factory( 'en' ); 00018 } 00019 00020 function addDBData() { 00021 //$this->dumpBlocks(); 00022 00023 $user = User::newFromName( 'UTBlockee' ); 00024 if( $user->getID() == 0 ) { 00025 $user->addToDatabase(); 00026 $user->setPassword( 'UTBlockeePassword' ); 00027 00028 $user->saveSettings(); 00029 } 00030 00031 // Delete the last round's block if it's still there 00032 $oldBlock = Block::newFromTarget( 'UTBlockee' ); 00033 if ( $oldBlock ) { 00034 // An old block will prevent our new one from saving. 00035 $oldBlock->delete(); 00036 } 00037 00038 $this->block = new Block( 'UTBlockee', $user->getID(), 0, 00039 'Parce que', 0, false, time() + 100500 00040 ); 00041 $this->madeAt = wfTimestamp( TS_MW ); 00042 00043 $this->block->insert(); 00044 // save up ID for use in assertion. Since ID is an autoincrement, 00045 // its value might change depending on the order the tests are run. 00046 // ApiBlockTest insert its own blocks! 00047 $newBlockId = $this->block->getId(); 00048 if ($newBlockId) { 00049 $this->blockId = $newBlockId; 00050 } else { 00051 throw new MWException( "Failed to insert block for BlockTest; old leftover block remaining?" ); 00052 } 00053 } 00054 00058 function dumpBlocks() { 00059 $v = $this->db->query( 'SELECT * FROM unittest_ipblocks' ); 00060 print "Got " . $v->numRows() . " rows. Full dump follow:\n"; 00061 foreach( $v as $row ) { 00062 print_r( $row ); 00063 } 00064 } 00065 00066 function testInitializerFunctionsReturnCorrectBlock() { 00067 // $this->dumpBlocks(); 00068 00069 $this->assertTrue( $this->block->equals( Block::newFromTarget('UTBlockee') ), "newFromTarget() returns the same block as the one that was made"); 00070 00071 $this->assertTrue( $this->block->equals( Block::newFromID( $this->blockId ) ), "newFromID() returns the same block as the one that was made"); 00072 00073 } 00074 00078 function testBug26425BlockTimestampDefaultsToTime() { 00079 // delta to stop one-off errors when things happen to go over a second mark. 00080 $delta = abs( $this->madeAt - $this->block->mTimestamp ); 00081 $this->assertLessThan( 2, $delta, "If no timestamp is specified, the block is recorded as time()"); 00082 00083 } 00084 00093 function testBug29116LoadWithEmptyIp( $vagueTarget ) { 00094 $this->hideDeprecated( 'Block::load' ); 00095 00096 $uid = User::idFromName( 'UTBlockee' ); 00097 $this->assertTrue( ($uid > 0), 'Must be able to look up the target user during tests' ); 00098 00099 $block = new Block(); 00100 $ok = $block->load( $vagueTarget, $uid ); 00101 $this->assertTrue( $ok, "Block->load() with empty IP and user ID '$uid' should return a block" ); 00102 00103 $this->assertTrue( $this->block->equals( $block ), "Block->load() returns the same block as the one that was made when given empty ip param " . var_export( $vagueTarget, true ) ); 00104 } 00105 00113 function testBug29116NewFromTargetWithEmptyIp( $vagueTarget ) { 00114 $block = Block::newFromTarget('UTBlockee', $vagueTarget); 00115 $this->assertTrue( $this->block->equals( $block ), "newFromTarget() returns the same block as the one that was made when given empty vagueTarget param " . var_export( $vagueTarget, true ) ); 00116 } 00117 00118 function dataBug29116() { 00119 return array( 00120 array( null ), 00121 array( '' ), 00122 array( false ) 00123 ); 00124 } 00125 }