Removed testBug29116LoadWithEmptyIp. Fails due to wfDeprecated() call in load() and...
[lhc/web/wiklou.git] / tests / phpunit / includes / BlockTest.php
1 <?php
2
3 /**
4 * @group Database
5 */
6 class BlockTest extends MediaWikiLangTestCase {
7
8 const REASON = "Some reason";
9
10 private $block, $madeAt;
11
12 /* variable used to save up the blockID we insert in this test suite */
13 private $blockId;
14
15 function setUp() {
16 global $wgContLang;
17 parent::setUp();
18 $wgContLang = Language::factory( 'en' );
19 }
20
21 function addDBData() {
22 //$this->dumpBlocks();
23
24 $user = User::newFromName( 'UTBlockee' );
25 if( $user->getID() == 0 ) {
26 $user->addToDatabase();
27 $user->setPassword( 'UTBlockeePassword' );
28
29 $user->saveSettings();
30 }
31
32 // Delete the last round's block if it's still there
33 $oldBlock = Block::newFromTarget( 'UTBlockee' );
34 if ( $oldBlock ) {
35 // An old block will prevent our new one from saving.
36 $oldBlock->delete();
37 }
38
39 $this->block = new Block( 'UTBlockee', 1, 0,
40 self::REASON
41 );
42 $this->madeAt = wfTimestamp( TS_MW );
43
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();
49 if ($newBlockId) {
50 $this->blockId = $newBlockId;
51 } else {
52 throw new MWException( "Failed to insert block for BlockTest; old leftover block remaining?" );
53 }
54 }
55
56 /**
57 * debug function : dump the ipblocks table
58 */
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 ) {
63 print_r( $row );
64 }
65 }
66
67 function testInitializerFunctionsReturnCorrectBlock() {
68 // $this->dumpBlocks();
69
70 $this->assertTrue( $this->block->equals( Block::newFromTarget('UTBlockee') ), "newFromTarget() returns the same block as the one that was made");
71
72 $this->assertTrue( $this->block->equals( Block::newFromID( $this->blockId ) ), "newFromID() returns the same block as the one that was made");
73
74 }
75
76 /**
77 * per bug 26425
78 */
79 function testBug26425BlockTimestampDefaultsToTime() {
80
81 $this->assertEquals( $this->madeAt, $this->block->mTimestamp, "If no timestamp is specified, the block is recorded as time()");
82
83 }
84
85 /**
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.
89 *
90 * @dataProvider dataBug29116
91 */
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 ) );
95 }
96
97 function dataBug29116() {
98 return array(
99 array( null ),
100 array( '' ),
101 array( false )
102 );
103 }
104 }
105