Merge "phpunit: Use assertEquals(, $delta) in UserTest instead of greater/lessThan"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 6 Jan 2017 23:15:43 +0000 (23:15 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 6 Jan 2017 23:15:43 +0000 (23:15 +0000)
1  2 
tests/phpunit/includes/user/UserTest.php

@@@ -726,13 -726,11 +726,11 @@@ class UserTest extends MediaWikiTestCas
                $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() );
 +      }
 +
  }