Merge "Add missing return types to User::getOption()"
[lhc/web/wiklou.git] / tests / phpunit / includes / user / CentralIdLookupTest.php
index 386e7ab..dc9fe2a 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Wikimedia\TestingAccessWrapper;
+
 /**
  * @covers CentralIdLookup
  * @group Database
@@ -7,19 +9,19 @@
 class CentralIdLookupTest extends MediaWikiTestCase {
 
        public function testFactory() {
-               $mock = $this->getMockForAbstractClass( 'CentralIdLookup' );
+               $mock = $this->getMockForAbstractClass( CentralIdLookup::class );
 
-               $this->setMwGlobals( array(
-                       'wgCentralIdLookupProviders' => array(
-                               'local' => array( 'class' => 'LocalIdLookup' ),
-                               'local2' => array( 'class' => 'LocalIdLookup' ),
-                               'mock' => array( 'factory' => function () use ( $mock ) {
+               $this->setMwGlobals( [
+                       'wgCentralIdLookupProviders' => [
+                               'local' => [ 'class' => LocalIdLookup::class ],
+                               'local2' => [ 'class' => LocalIdLookup::class ],
+                               'mock' => [ 'factory' => function () use ( $mock ) {
                                        return $mock;
-                               } ),
-                               'bad' => array( 'class' => 'stdClass' ),
-                       ),
+                               } ],
+                               'bad' => [ 'class' => stdClass::class ],
+                       ],
                        'wgCentralIdLookupProvider' => 'mock',
-               ) );
+               ] );
 
                $this->assertSame( $mock, CentralIdLookup::factory() );
                $this->assertSame( $mock, CentralIdLookup::factory( 'mock' ) );
@@ -27,13 +29,13 @@ class CentralIdLookupTest extends MediaWikiTestCase {
 
                $local = CentralIdLookup::factory( 'local' );
                $this->assertNotSame( $mock, $local );
-               $this->assertInstanceOf( 'LocalIdLookup', $local );
+               $this->assertInstanceOf( LocalIdLookup::class, $local );
                $this->assertSame( $local, CentralIdLookup::factory( 'local' ) );
                $this->assertSame( 'local', $local->getProviderId() );
 
                $local2 = CentralIdLookup::factory( 'local2' );
                $this->assertNotSame( $local, $local2 );
-               $this->assertInstanceOf( 'LocalIdLookup', $local2 );
+               $this->assertInstanceOf( LocalIdLookup::class, $local2 );
                $this->assertSame( 'local2', $local2->getProviderId() );
 
                $this->assertNull( CentralIdLookup::factory( 'unconfigured' ) );
@@ -42,14 +44,14 @@ class CentralIdLookupTest extends MediaWikiTestCase {
 
        public function testCheckAudience() {
                $mock = TestingAccessWrapper::newFromObject(
-                       $this->getMockForAbstractClass( 'CentralIdLookup' )
+                       $this->getMockForAbstractClass( CentralIdLookup::class )
                );
 
-               $user = User::newFromName( 'UTSysop' );
+               $user = static::getTestSysop()->getUser();
                $this->assertSame( $user, $mock->checkAudience( $user ) );
 
                $user = $mock->checkAudience( CentralIdLookup::AUDIENCE_PUBLIC );
-               $this->assertInstanceOf( 'User', $user );
+               $this->assertInstanceOf( User::class, $user );
                $this->assertSame( 0, $user->getId() );
 
                $this->assertNull( $mock->checkAudience( CentralIdLookup::AUDIENCE_RAW ) );
@@ -63,14 +65,14 @@ class CentralIdLookupTest extends MediaWikiTestCase {
        }
 
        public function testNameFromCentralId() {
-               $mock = $this->getMockForAbstractClass( 'CentralIdLookup' );
+               $mock = $this->getMockForAbstractClass( CentralIdLookup::class );
                $mock->expects( $this->once() )->method( 'lookupCentralIds' )
                        ->with(
-                               $this->equalTo( array( 15 => null ) ),
+                               $this->equalTo( [ 15 => null ] ),
                                $this->equalTo( CentralIdLookup::AUDIENCE_RAW ),
                                $this->equalTo( CentralIdLookup::READ_LATEST )
                        )
-                       ->will( $this->returnValue( array( 15 => 'FooBar' ) ) );
+                       ->will( $this->returnValue( [ 15 => 'FooBar' ] ) );
 
                $this->assertSame(
                        'FooBar',
@@ -84,61 +86,61 @@ class CentralIdLookupTest extends MediaWikiTestCase {
         * @param bool $succeeds
         */
        public function testLocalUserFromCentralId( $name, $succeeds ) {
-               $mock = $this->getMockForAbstractClass( 'CentralIdLookup' );
+               $mock = $this->getMockForAbstractClass( CentralIdLookup::class );
                $mock->expects( $this->any() )->method( 'isAttached' )
                        ->will( $this->returnValue( true ) );
                $mock->expects( $this->once() )->method( 'lookupCentralIds' )
                        ->with(
-                               $this->equalTo( array( 42 => null ) ),
+                               $this->equalTo( [ 42 => null ] ),
                                $this->equalTo( CentralIdLookup::AUDIENCE_RAW ),
                                $this->equalTo( CentralIdLookup::READ_LATEST )
                        )
-                       ->will( $this->returnValue( array( 42 => $name ) ) );
+                       ->will( $this->returnValue( [ 42 => $name ] ) );
 
                $user = $mock->localUserFromCentralId(
                        42, CentralIdLookup::AUDIENCE_RAW, CentralIdLookup::READ_LATEST
                );
                if ( $succeeds ) {
-                       $this->assertInstanceOf( 'User', $user );
+                       $this->assertInstanceOf( User::class, $user );
                        $this->assertSame( $name, $user->getName() );
                } else {
                        $this->assertNull( $user );
                }
 
-               $mock = $this->getMockForAbstractClass( 'CentralIdLookup' );
+               $mock = $this->getMockForAbstractClass( CentralIdLookup::class );
                $mock->expects( $this->any() )->method( 'isAttached' )
                        ->will( $this->returnValue( false ) );
                $mock->expects( $this->once() )->method( 'lookupCentralIds' )
                        ->with(
-                               $this->equalTo( array( 42 => null ) ),
+                               $this->equalTo( [ 42 => null ] ),
                                $this->equalTo( CentralIdLookup::AUDIENCE_RAW ),
                                $this->equalTo( CentralIdLookup::READ_LATEST )
                        )
-                       ->will( $this->returnValue( array( 42 => $name ) ) );
+                       ->will( $this->returnValue( [ 42 => $name ] ) );
                $this->assertNull(
                        $mock->localUserFromCentralId( 42, CentralIdLookup::AUDIENCE_RAW, CentralIdLookup::READ_LATEST )
                );
        }
 
        public static function provideLocalUserFromCentralId() {
-               return array(
-                       array( 'UTSysop', true ),
-                       array( 'UTDoesNotExist', false ),
-                       array( null, false ),
-                       array( '', false ),
-                       array( '<X>', false ),
-               );
+               return [
+                       [ 'UTSysop', true ],
+                       [ 'UTDoesNotExist', false ],
+                       [ null, false ],
+                       [ '', false ],
+                       [ '<X>', false ],
+               ];
        }
 
        public function testCentralIdFromName() {
-               $mock = $this->getMockForAbstractClass( 'CentralIdLookup' );
+               $mock = $this->getMockForAbstractClass( CentralIdLookup::class );
                $mock->expects( $this->once() )->method( 'lookupUserNames' )
                        ->with(
-                               $this->equalTo( array( 'FooBar' => 0 ) ),
+                               $this->equalTo( [ 'FooBar' => 0 ] ),
                                $this->equalTo( CentralIdLookup::AUDIENCE_RAW ),
                                $this->equalTo( CentralIdLookup::READ_LATEST )
                        )
-                       ->will( $this->returnValue( array( 'FooBar' => 23 ) ) );
+                       ->will( $this->returnValue( [ 'FooBar' => 23 ] ) );
 
                $this->assertSame(
                        23,
@@ -147,16 +149,16 @@ class CentralIdLookupTest extends MediaWikiTestCase {
        }
 
        public function testCentralIdFromLocalUser() {
-               $mock = $this->getMockForAbstractClass( 'CentralIdLookup' );
+               $mock = $this->getMockForAbstractClass( CentralIdLookup::class );
                $mock->expects( $this->any() )->method( 'isAttached' )
                        ->will( $this->returnValue( true ) );
                $mock->expects( $this->once() )->method( 'lookupUserNames' )
                        ->with(
-                               $this->equalTo( array( 'FooBar' => 0 ) ),
+                               $this->equalTo( [ 'FooBar' => 0 ] ),
                                $this->equalTo( CentralIdLookup::AUDIENCE_RAW ),
                                $this->equalTo( CentralIdLookup::READ_LATEST )
                        )
-                       ->will( $this->returnValue( array( 'FooBar' => 23 ) ) );
+                       ->will( $this->returnValue( [ 'FooBar' => 23 ] ) );
 
                $this->assertSame(
                        23,
@@ -165,7 +167,7 @@ class CentralIdLookupTest extends MediaWikiTestCase {
                        )
                );
 
-               $mock = $this->getMockForAbstractClass( 'CentralIdLookup' );
+               $mock = $this->getMockForAbstractClass( CentralIdLookup::class );
                $mock->expects( $this->any() )->method( 'isAttached' )
                        ->will( $this->returnValue( false ) );
                $mock->expects( $this->never() )->method( 'lookupUserNames' );