Followup r89311: rv unrelated changes
[lhc/web/wiklou.git] / tests / phpunit / includes / BlockTest.php
1 <?php
2
3 /**
4 * @group Database
5 * @group Broken
6 */
7 class BlockTest extends MediaWikiLangTestCase {
8
9 private $block, $madeAt;
10
11 /* variable used to save up the blockID we insert in this test suite */
12 private $blockId;
13
14 function setUp() {
15 global $wgContLang;
16 parent::setUp();
17 $wgContLang = Language::factory( 'en' );
18 }
19
20 function addDBData() {
21 //$this->dumpBlocks();
22
23 $user = User::newFromName( 'UTBlockee' );
24 if( $user->getID() == 0 ) {
25 $user->addToDatabase();
26 $user->setPassword( 'UTBlockeePassword' );
27
28 $user->saveSettings();
29 }
30
31 $this->block = new Block( 'UTBlockee', 1, 0,
32 'Parce que'
33 );
34 $this->madeAt = wfTimestamp( TS_MW );
35
36 $this->block->insert();
37 // save up ID for use in assertion. Since ID is an autoincrement,
38 // its value might change depending on the order the tests are run.
39 // ApiBlockTest insert its own blocks!
40 $this->blockId = $this->block->getId();
41 }
42
43 /**
44 * debug function : dump the ipblocks table
45 */
46 function dumpBlocks() {
47 $v = $this->db->query( 'SELECT * FROM unittest_ipblocks' );
48 print "Got " . $v->numRows() . " rows. Full dump follow:\n";
49 foreach( $v as $row ) {
50 print_r( $row );
51 }
52 }
53
54 function testInitializerFunctionsReturnCorrectBlock() {
55 // $this->dumpBlocks();
56
57 $this->assertTrue( $this->block->equals( Block::newFromTarget('UTBlockee') ), "newFromTarget() returns the same block as the one that was made");
58
59 $this->assertTrue( $this->block->equals( Block::newFromID( $this->blockId ) ), "newFromID() returns the same block as the one that was made");
60
61 }
62
63 /**
64 * per bug 26425
65 */
66 function testBug26425BlockTimestampDefaultsToTime() {
67
68 $this->assertEquals( $this->madeAt, $this->block->mTimestamp, "If no timestamp is specified, the block is recorded as time()");
69
70 }
71
72 /**
73 * This is the method previously used to load block info in CheckUser etc
74 * passing an empty value (empty string, null, etc) as the ip parameter bypasses IP lookup checks.
75 *
76 * This stopped working with r84475 and friends: regression being fixed for bug 29116.
77 *
78 * @dataProvider dataBug29116
79 */
80 function testBug29116LoadWithEmptyIp( $vagueTarget ) {
81 $block = new Block();
82 $block->load( $vagueTarget, 'UTBlockee' );
83 $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 ) );
84 }
85
86 /**
87 * CheckUser since being changed to use Block::newFromTarget started failing
88 * because the new function didn't accept empty strings like Block::load()
89 * had. Regression bug 29116.
90 *
91 * @dataProvider dataBug29116
92 */
93 function testBug29116NewFromTargetWithEmptyIp( $vagueTarget ) {
94 $block = Block::newFromTarget('UTBlockee', $vagueTarget);
95 $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 ) );
96 }
97
98 function dataBug29116() {
99 return array(
100 array( null ),
101 array( '' ),
102 array( false )
103 );
104 }
105 }
106