Merge "Fix incomplete Language::getDatePreferences() documentation"
[lhc/web/wiklou.git] / tests / phpunit / includes / user / UserTest.php
index 776dda1..b58d71c 100644 (file)
@@ -25,9 +25,7 @@ class UserTest extends MediaWikiTestCase {
 
                $this->setUpPermissionGlobals();
 
-               $this->user = new User;
-               $this->user->addToDatabase();
-               $this->user->addGroup( 'unittesters' );
+               $this->user = $this->getTestUser( [ 'unittesters' ] )->getUser();
        }
 
        private function setUpPermissionGlobals() {
@@ -100,10 +98,7 @@ class UserTest extends MediaWikiTestCase {
         * @covers User::getRights
         */
        public function testUserGetRightsHooks() {
-               $user = new User;
-               $user->addToDatabase();
-               $user->addGroup( 'unittesters' );
-               $user->addGroup( 'testwriters' );
+               $user = $this->getTestUser( [ 'unittesters', 'testwriters' ] )->getUser();
                $userWrapper = TestingAccessWrapper::newFromObject( $user );
 
                $rights = $user->getRights();
@@ -934,4 +929,50 @@ class UserTest extends MediaWikiTestCase {
 
                $this->assertFalse( $user->getExperienceLevel() );
        }
+
+       public static function provideIsLocallBlockedProxy() {
+               return [
+                       [ '1.2.3.4', '1.2.3.4' ],
+                       [ '1.2.3.4', '1.2.3.0/16' ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideIsLocallBlockedProxy
+        * @covers User::isLocallyBlockedProxy
+        */
+       public function testIsLocallyBlockedProxy( $ip, $blockListEntry ) {
+               $this->setMwGlobals(
+                       'wgProxyList', []
+               );
+               $this->assertFalse( User::isLocallyBlockedProxy( $ip ) );
+
+               $this->setMwGlobals(
+                       'wgProxyList',
+                       [
+                               $blockListEntry
+                       ]
+               );
+               $this->assertTrue( User::isLocallyBlockedProxy( $ip ) );
+
+               $this->setMwGlobals(
+                       'wgProxyList',
+                       [
+                               'test' => $blockListEntry
+                       ]
+               );
+               $this->assertTrue( User::isLocallyBlockedProxy( $ip ) );
+
+               $this->hideDeprecated(
+                       'IP addresses in the keys of $wgProxyList (found the following IP ' .
+                       'addresses in keys: ' . $blockListEntry . ', please move them to values)'
+               );
+               $this->setMwGlobals(
+                       'wgProxyList',
+                       [
+                               $blockListEntry => 'test'
+                       ]
+               );
+               $this->assertTrue( User::isLocallyBlockedProxy( $ip ) );
+       }
 }