Merge "Move around "ا" to after "آ" and not before"
[lhc/web/wiklou.git] / tests / phpunit / includes / user / UserTest.php
index 776dda1..aa368de 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();
@@ -222,6 +217,8 @@ class UserTest extends MediaWikiTestCase {
                        [ 'Ab/cd', false, 'Contains slash' ],
                        [ 'Ab cd', true, 'Whitespace' ],
                        [ '192.168.1.1', false, 'IP' ],
+                       [ '116.17.184.5/32', false, 'IP range' ],
+                       [ '::e:f:2001/96', false, 'IPv6 range' ],
                        [ 'User:Abcd', false, 'Reserved Namespace' ],
                        [ '12abcd232', true, 'Starts with Numbers' ],
                        [ '?abcd', true, 'Start with ? mark' ],
@@ -934,4 +931,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 ) );
+       }
 }