$this->assertArrayHasKey( 'wm_infinite_blockBlockID', $cookies );
$expOneDay = wfTimestamp() + ( 24 * 60 * 60 );
// Check for expiry dates in a 10-second window, to account for slow testing.
- $this->assertGreaterThan(
- $expOneDay - 5,
- $cookies['wm_infinite_blockBlockID']['expire']
- );
- $this->assertLessThan(
- $expOneDay + 5,
- $cookies['wm_infinite_blockBlockID']['expire']
+ $this->assertEquals(
+ $expOneDay,
+ $cookies['wm_infinite_blockBlockID']['expire'],
+ 'Expiry date',
+ 5.0
);
// 3. Change the block's expiry (to 2 hours), and the cookie's should be changed also.
// Clean up.
$block->delete();
}
+
+ public function testSoftBlockRanges() {
+ global $wgUser;
+
+ $this->setMwGlobals( [
+ 'wgSoftBlockRanges' => [ '10.0.0.0/8' ],
+ 'wgUser' => null,
+ ] );
+
+ // IP isn't in $wgSoftBlockRanges
+ $request = new FauxRequest();
+ $request->setIP( '192.168.0.1' );
+ $wgUser = User::newFromSession( $request );
+ $this->assertNull( $wgUser->getBlock() );
+
+ // IP is in $wgSoftBlockRanges
+ $request = new FauxRequest();
+ $request->setIP( '10.20.30.40' );
+ $wgUser = User::newFromSession( $request );
+ $block = $wgUser->getBlock();
+ $this->assertInstanceOf( Block::class, $block );
+ $this->assertSame( 'wgSoftBlockRanges', $block->getSystemBlockType() );
+
+ // Make sure the block is really soft
+ $request->getSession()->setUser( $this->getTestUser()->getUser() );
+ $wgUser = User::newFromSession( $request );
+ $this->assertFalse( $wgUser->isAnon(), 'sanity check' );
+ $this->assertNull( $wgUser->getBlock() );
+ }
+
}