6 class BlockTest
extends MediaWikiLangTestCase
{
8 const REASON
= "Some reason";
10 private $block, $madeAt;
12 /* variable used to save up the blockID we insert in this test suite */
18 $wgContLang = Language
::factory( 'en' );
21 function addDBData() {
22 //$this->dumpBlocks();
24 $user = User
::newFromName( 'UTBlockee' );
25 if( $user->getID() == 0 ) {
26 $user->addToDatabase();
27 $user->setPassword( 'UTBlockeePassword' );
29 $user->saveSettings();
32 // Delete the last round's block if it's still there
33 $oldBlock = Block
::newFromTarget( 'UTBlockee' );
35 // An old block will prevent our new one from saving.
39 $this->block
= new Block( 'UTBlockee', 1, 0,
42 $this->madeAt
= wfTimestamp( TS_MW
);
44 $this->block
->insert();
45 // save up ID for use in assertion. Since ID is an autoincrement,
46 // its value might change depending on the order the tests are run.
47 // ApiBlockTest insert its own blocks!
48 $newBlockId = $this->block
->getId();
50 $this->blockId
= $newBlockId;
52 throw new MWException( "Failed to insert block for BlockTest; old leftover block remaining?" );
57 * debug function : dump the ipblocks table
59 function dumpBlocks() {
60 $v = $this->db
->query( 'SELECT * FROM unittest_ipblocks' );
61 print "Got " . $v->numRows() . " rows. Full dump follow:\n";
62 foreach( $v as $row ) {
67 function testInitializerFunctionsReturnCorrectBlock() {
68 // $this->dumpBlocks();
70 $this->assertTrue( $this->block
->equals( Block
::newFromTarget('UTBlockee') ), "newFromTarget() returns the same block as the one that was made");
72 $this->assertTrue( $this->block
->equals( Block
::newFromID( $this->blockId
) ), "newFromID() returns the same block as the one that was made");
79 function testBug26425BlockTimestampDefaultsToTime() {
81 $this->assertEquals( $this->madeAt
, $this->block
->mTimestamp
, "If no timestamp is specified, the block is recorded as time()");
86 * This is the method previously used to load block info in CheckUser etc
87 * passing an empty value (empty string, null, etc) as the ip parameter bypasses IP lookup checks.
89 * This stopped working with r84475 and friends: regression being fixed for bug 29116.
91 * @dataProvider dataBug29116
93 function testBug29116LoadWithEmptyIp( $vagueTarget ) {
94 $uid = User
::idFromName( 'UTBlockee' );
95 $this->assertTrue( ($uid > 0), 'Must be able to look up the target user during tests' );
98 $ok = $block->load( $vagueTarget, $uid );
99 $this->assertTrue( $ok, "Block->load() with empty IP and user ID '$uid' should return a block" );
101 $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 ) );
105 * CheckUser since being changed to use Block::newFromTarget started failing
106 * because the new function didn't accept empty strings like Block::load()
107 * had. Regression bug 29116.
109 * @dataProvider dataBug29116
111 function testBug29116NewFromTargetWithEmptyIp( $vagueTarget ) {
112 $block = Block
::newFromTarget('UTBlockee', $vagueTarget);
113 $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 ) );
116 function dataBug29116() {