* upgrade patches for oracle 1.17->1.19
[mediawiki.git] / tests / phpunit / includes / BlockTest.php
blob811e7eaf353f76148712dfd6481fb49b77af2e57
1 <?php
3 /**
4 * @group Database
5 */
6 class BlockTest extends MediaWikiLangTestCase {
8 private $block, $madeAt;
10 /* variable used to save up the blockID we insert in this test suite */
11 private $blockId;
13 function setUp() {
14 global $wgContLang;
15 parent::setUp();
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,
31 'Parce que'
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();
42 /**
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 ) {
49 print_r( $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");
62 /**
63 * per bug 26425
65 function testBug26425BlockTimestampDefaultsToTime() {
67 $this->assertEquals( $this->madeAt, $this->block->mTimestamp, "If no timestamp is specified, the block is recorded as time()");
71 /**
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 ) {
80 $block = new Block();
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 ) );
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.
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() {
98 return array(
99 array( null ),
100 array( '' ),
101 array( false )