6 class BlockTest
extends MediaWikiLangTestCase
{
8 private $block, $madeAt;
10 /* variable used to save up the blockID we insert in this test suite */
16 $wgContLang = Language
::factory( 'en' );
19 function addDBData() {
20 //$this->dumpBlocks();
22 $user = User
::newFromName( 'UTBlockee' );
23 if( $user->getID() == 0 ) {
24 $user->addToDatabase();
25 $user->setPassword( 'UTBlockeePassword' );
27 $user->saveSettings();
30 $this->block
= new Block( 'UTBlockee', 1, 0,
33 $this->madeAt
= wfTimestamp( TS_MW
);
35 $this->block
->insert();
36 // save up ID for use in assertion. Since ID is an autoincrement,
37 // its value might change depending on the order the tests are run.
38 // ApiBlockTest insert its own blocks!
39 $this->blockId
= $this->block
->getId();
43 * debug function : dump the ipblocks table
45 function dumpBlocks() {
46 $v = $this->db
->query( 'SELECT * FROM unittest_ipblocks' );
47 print "Got " . $v->numRows() . " rows. Full dump follow:\n";
48 foreach( $v as $row ) {
53 function testInitializerFunctionsReturnCorrectBlock() {
54 // $this->dumpBlocks();
56 $this->assertTrue( $this->block
->equals( Block
::newFromTarget('UTBlockee') ), "newFromTarget() returns the same block as the one that was made");
58 $this->assertTrue( $this->block
->equals( Block
::newFromID( $this->blockId
) ), "newFromID() returns the same block as the one that was made");
65 function testBug26425BlockTimestampDefaultsToTime() {
67 $this->assertEquals( $this->madeAt
, $this->block
->mTimestamp
, "If no timestamp is specified, the block is recorded as time()");
72 * This is the method previously used to load block info in CheckUser etc
73 * passing an empty value (empty string, null, etc) as the ip parameter bypasses IP lookup checks.
75 * This stopped working with r84475 and friends: regression being fixed for bug 29116.
77 * @dataProvider dataBug29116
79 function testBug29116LoadWithEmptyIp( $vagueTarget ) {
81 $block->load( $vagueTarget, 'UTBlockee' );
82 $this->assertTrue( $this->block
->equals( Block
::newFromTarget('UTBlockee', $vagueTarget) ), "Block->load() returns the same block as the one that was made when given empty ip param " . var_export( $vagueTarget, true ) );
86 * CheckUser since being changed to use Block::newFromTarget started failing
87 * because the new function didn't accept empty strings like Block::load()
88 * had. Regression bug 29116.
90 * @dataProvider dataBug29116
92 function testBug29116NewFromTargetWithEmptyIp( $vagueTarget ) {
93 $block = Block
::newFromTarget('UTBlockee', $vagueTarget);
94 $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 ) );
97 function dataBug29116() {