* (bug 29116) Fix regression breaking CheckUser extension
[lhc/web/wiklou.git] / tests / phpunit / includes / BlockTest.php
1 <?php
2
3 /**
4 * @group Database
5 */
6 class BlockTest extends MediaWikiLangTestCase {
7
8 private $block, $madeAt;
9
10 function setUp() {
11 global $wgContLang;
12 parent::setUp();
13 $wgContLang = Language::factory( 'en' );
14 }
15
16 function addDBData() {
17
18 $user = User::newFromName( 'UTBlockee' );
19 if( $user->getID() == 0 ) {
20 $user->addToDatabase();
21 $user->setPassword( 'UTBlockeePassword' );
22
23 $user->saveSettings();
24 }
25
26 $this->block = new Block( 'UTBlockee', 1, 0,
27 'Parce que'
28 );
29 $this->madeAt = wfTimestamp( TS_MW );
30
31 $this->block->insert();
32 }
33
34 function testInitializerFunctionsReturnCorrectBlock() {
35
36 $this->assertTrue( $this->block->equals( Block::newFromTarget('UTBlockee') ), "newFromTarget() returns the same block as the one that was made");
37
38 $this->assertTrue( $this->block->equals( Block::newFromID( 1 ) ), "newFromID() returns the same block as the one that was made");
39
40 }
41
42 /**
43 * per bug 26425
44 */
45 function testBug26425BlockTimestampDefaultsToTime() {
46
47 $this->assertEquals( $this->madeAt, $this->block->mTimestamp, "If no timestamp is specified, the block is recorded as time()");
48
49 }
50
51 /**
52 * This is the method previously used to load block info in CheckUser etc
53 * passing an empty value (empty string, null, etc) as the ip parameter bypasses IP lookup checks.
54 *
55 * This stopped working with r84475 and friends: regression being fixed for bug 29116.
56 *
57 * @dataProvider dataBug29116
58 */
59 function testBug29116LoadWithEmptyIp( $vagueTarget ) {
60 $block = new Block();
61 $block->load( $vagueTarget, 'UTBlockee' );
62 $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 ) );
63 }
64
65 /**
66 * CheckUser since being changed to use Block::newFromTarget started failing
67 * because the new function didn't accept empty strings like Block::load()
68 * had. Regression bug 29116.
69 *
70 * @dataProvider dataBug29116
71 */
72 function testBug29116NewFromTargetWithEmptyIp( $vagueTarget ) {
73 $block = Block::newFromTarget('UTBlockee', $vagueTarget);
74 $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 ) );
75 }
76
77 function dataBug29116() {
78 return array(
79 array( null ),
80 array( '' ),
81 array( false )
82 );
83 }
84 }
85