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 * 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() {