6 class BlockTest
extends MediaWikiLangTestCase
{
8 private $block, $madeAt;
13 $wgContLang = Language
::factory( 'en' );
16 function addDBData() {
18 $user = User
::newFromName( 'UTBlockee' );
19 if( $user->getID() == 0 ) {
20 $user->addToDatabase();
21 $user->setPassword( 'UTBlockeePassword' );
23 $user->saveSettings();
26 $this->block
= new Block( 'UTBlockee', 1, 0,
29 $this->madeAt
= wfTimestamp( TS_MW
);
31 $this->block
->insert();
34 function testInitializerFunctionsReturnCorrectBlock() {
36 $this->assertTrue( $this->block
->equals( Block
::newFromTarget('UTBlockee') ), "newFromTarget() returns the same block as the one that was made");
38 $this->assertTrue( $this->block
->equals( Block
::newFromID( 1 ) ), "newFromID() returns the same block as the one that was made");
45 function testBug26425BlockTimestampDefaultsToTime() {
47 $this->assertEquals( $this->madeAt
, $this->block
->mTimestamp
, "If no timestamp is specified, the block is recorded as time()");
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.
55 * This stopped working with r84475 and friends: regression being fixed for bug 29116.
57 * @dataProvider dataBug29116
59 function testBug29116LoadWithEmptyIp( $vagueTarget ) {
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 ) );
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.
70 * @dataProvider dataBug29116
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 ) );
77 function dataBug29116() {