*/
class BlockTest extends MediaWikiLangTestCase {
- private $block, $madeAt;
+ /** @var Block */
+ private $block;
+ private $madeAt;
/* variable used to save up the blockID we insert in this test suite */
private $blockId;
} else {
throw new MWException( "Failed to insert block for BlockTest; old leftover block remaining?" );
}
+
+ $this->addXffBlocks();
}
/**
* debug function : dump the ipblocks table
*/
function dumpBlocks() {
- $v = $this->db->query( 'SELECT * FROM unittest_ipblocks' );
+ $v = $this->db->select( 'ipblocks', '*' );
print "Got " . $v->numRows() . " rows. Full dump follow:\n";
foreach ( $v as $row ) {
print_r( $row );
}
}
- function testInitializerFunctionsReturnCorrectBlock() {
- // $this->dumpBlocks();
-
+ /**
+ * @covers Block::newFromTarget
+ */
+ public function testINewFromTargetReturnsCorrectBlock() {
$this->assertTrue( $this->block->equals( Block::newFromTarget( 'UTBlockee' ) ), "newFromTarget() returns the same block as the one that was made" );
+ }
+ /**
+ * @covers Block::newFromID
+ */
+ public function testINewFromIDReturnsCorrectBlock() {
$this->assertTrue( $this->block->equals( Block::newFromID( $this->blockId ) ), "newFromID() returns the same block as the one that was made" );
-
}
/**
* per bug 26425
*/
- function testBug26425BlockTimestampDefaultsToTime() {
+ public function testBug26425BlockTimestampDefaultsToTime() {
// delta to stop one-off errors when things happen to go over a second mark.
$delta = abs( $this->madeAt - $this->block->mTimestamp );
$this->assertLessThan( 2, $delta, "If no timestamp is specified, the block is recorded as time()" );
-
}
/**
* This stopped working with r84475 and friends: regression being fixed for bug 29116.
*
* @dataProvider provideBug29116Data
+ * @covers Block::load
*/
- function testBug29116LoadWithEmptyIp( $vagueTarget ) {
+ public function testBug29116LoadWithEmptyIp( $vagueTarget ) {
$this->hideDeprecated( 'Block::load' );
$uid = User::idFromName( 'UTBlockee' );
* had. Regression bug 29116.
*
* @dataProvider provideBug29116Data
+ * @covers Block::newFromTarget
*/
- function testBug29116NewFromTargetWithEmptyIp( $vagueTarget ) {
+ public function testBug29116NewFromTargetWithEmptyIp( $vagueTarget ) {
$block = Block::newFromTarget( 'UTBlockee', $vagueTarget );
$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 ) );
}
);
}
- function testBlockedUserCanNotCreateAccount() {
+ /**
+ * @covers Block::prevents
+ */
+ public function testBlockedUserCanNotCreateAccount() {
$username = 'BlockedUserToCreateAccountWith';
$u = User::newFromName( $username );
$u->setPassword( 'NotRandomPass' );
$u->addToDatabase();
unset( $u );
-
// Sanity check
$this->assertNull(
Block::newFromTarget( $username ),
);
}
- function testCrappyCrossWikiBlocks() {
+ /**
+ * @covers Block::insert
+ */
+ public function testCrappyCrossWikiBlocks() {
// Delete the last round's block if it's still there
$oldBlock = Block::newFromTarget( 'UserOnForeignWiki' );
if ( $oldBlock ) {
$this->assertEquals( 0, $block->getBy(), 'Correct blocker id' );
}
- function testBlocksOnXff() {
+ protected function addXffBlocks() {
+ static $inited = false;
+
+ if ( $inited ) {
+ return;
+ }
+
+ $inited = true;
$blockList = array(
array( 'target' => '70.2.0.0/16',
- 'type' => Block::TYPE_RANGE,
+ 'type' => Block::TYPE_RANGE,
'desc' => 'Range Hardblock',
'ACDisable' => false,
'isHardblock' => true,
'isAutoBlocking' => false,
),
array( 'target' => '2001:4860:4001::/48',
- 'type' => Block::TYPE_RANGE,
+ 'type' => Block::TYPE_RANGE,
'desc' => 'Range6 Hardblock',
'ACDisable' => false,
'isHardblock' => true,
'isAutoBlocking' => false,
),
array( 'target' => '60.2.0.0/16',
- 'type' => Block::TYPE_RANGE,
+ 'type' => Block::TYPE_RANGE,
'desc' => 'Range Softblock with AC Disabled',
'ACDisable' => true,
'isHardblock' => false,
'isAutoBlocking' => false,
),
array( 'target' => '50.2.0.0/16',
- 'type' => Block::TYPE_RANGE,
+ 'type' => Block::TYPE_RANGE,
'desc' => 'Range Softblock',
'ACDisable' => false,
'isHardblock' => false,
'isAutoBlocking' => false,
),
array( 'target' => '50.1.1.1',
- 'type' => Block::TYPE_IP,
+ 'type' => Block::TYPE_IP,
'desc' => 'Exact Softblock',
'ACDisable' => false,
'isHardblock' => false,
$block->isAutoblocking( $insBlock['isAutoBlocking'] );
$block->insert();
}
+ }
- $xffHeaders = array(
+ public static function providerXff() {
+ return array(
array( 'xff' => '1.2.3.4, 70.2.1.1, 60.2.1.1, 2.3.4.5',
'count' => 2,
'result' => 'Range Hardblock'
'result' => 'Range6 Hardblock'
),
);
+ }
- foreach ( $xffHeaders as $test ) {
- $list = array_map( 'trim', explode( ',', $test['xff'] ) );
- $xffblocks = Block::getBlocksForIPList( $list, true );
- $this->assertEquals( $test['count'], count( $xffblocks ), 'Number of blocks for ' . $test['xff'] );
- $block = Block::chooseBlock( $xffblocks, $list );
- $this->assertEquals( $test['result'], $block->mReason, 'Correct block type for XFF header ' . $test['xff'] );
- }
-
+ /**
+ * @dataProvider providerXff
+ * @covers Block::getBlocksForIPList
+ * @covers Block::chooseBlock
+ */
+ public function testBlocksOnXff( $xff, $exCount, $exResult ) {
+ $list = array_map( 'trim', explode( ',', $xff ) );
+ $xffblocks = Block::getBlocksForIPList( $list, true );
+ $this->assertEquals( $exCount, count( $xffblocks ), 'Number of blocks for ' . $xff );
+ $block = Block::chooseBlock( $xffblocks, $list );
+ $this->assertEquals( $exResult, $block->mReason, 'Correct block type for XFF header ' . $xff );
}
}