Merge "Add missing return types to User::getOption()"
[lhc/web/wiklou.git] / tests / phpunit / includes / user / BotPasswordTest.php
index 58f1e5f..3bbc2df 100644 (file)
@@ -32,14 +32,14 @@ class BotPasswordTest extends MediaWikiTestCase {
                $this->testUser = $this->getMutableTestUser();
                $this->testUserName = $this->testUser->getUser()->getName();
 
-               $mock1 = $this->getMockForAbstractClass( 'CentralIdLookup' );
+               $mock1 = $this->getMockForAbstractClass( CentralIdLookup::class );
                $mock1->expects( $this->any() )->method( 'isAttached' )
                        ->will( $this->returnValue( true ) );
                $mock1->expects( $this->any() )->method( 'lookupUserNames' )
                        ->will( $this->returnValue( [ $this->testUserName => 42, 'UTDummy' => 43, 'UTInvalid' => 0 ] ) );
                $mock1->expects( $this->never() )->method( 'lookupCentralIds' );
 
-               $mock2 = $this->getMockForAbstractClass( 'CentralIdLookup' );
+               $mock2 = $this->getMockForAbstractClass( CentralIdLookup::class );
                $mock2->expects( $this->any() )->method( 'isAttached' )
                        ->will( $this->returnValue( false ) );
                $mock2->expects( $this->any() )->method( 'lookupUserNames' )
@@ -96,7 +96,7 @@ class BotPasswordTest extends MediaWikiTestCase {
        public function testBasics() {
                $user = $this->testUser->getUser();
                $bp = BotPassword::newFromUser( $user, 'BotPassword' );
-               $this->assertInstanceOf( 'BotPassword', $bp );
+               $this->assertInstanceOf( BotPassword::class, $bp );
                $this->assertTrue( $bp->isSaved() );
                $this->assertSame( 42, $bp->getUserCentralId() );
                $this->assertSame( 'BotPassword', $bp->getAppId() );
@@ -124,7 +124,7 @@ class BotPasswordTest extends MediaWikiTestCase {
                        'user' => $user,
                        'appId' => 'DoesNotExist'
                ] );
-               $this->assertInstanceOf( 'BotPassword', $bp );
+               $this->assertInstanceOf( BotPassword::class, $bp );
                $this->assertFalse( $bp->isSaved() );
                $this->assertSame( 42, $bp->getUserCentralId() );
                $this->assertSame( 'DoesNotExist', $bp->getAppId() );
@@ -137,7 +137,7 @@ class BotPasswordTest extends MediaWikiTestCase {
                        'restrictions' => MWRestrictions::newFromJson( '{"IPAddresses":["127.0.0.0/8"]}' ),
                        'grants' => [ 'test' ],
                ] );
-               $this->assertInstanceOf( 'BotPassword', $bp );
+               $this->assertInstanceOf( BotPassword::class, $bp );
                $this->assertFalse( $bp->isSaved() );
                $this->assertSame( 43, $bp->getUserCentralId() );
                $this->assertSame( 'DoesNotExist2', $bp->getAppId() );
@@ -149,7 +149,7 @@ class BotPasswordTest extends MediaWikiTestCase {
                        'centralId' => 45,
                        'appId' => 'DoesNotExist'
                ] );
-               $this->assertInstanceOf( 'BotPassword', $bp );
+               $this->assertInstanceOf( BotPassword::class, $bp );
                $this->assertFalse( $bp->isSaved() );
                $this->assertSame( 45, $bp->getUserCentralId() );
                $this->assertSame( 'DoesNotExist', $bp->getAppId() );
@@ -159,7 +159,7 @@ class BotPasswordTest extends MediaWikiTestCase {
                        'user' => $user,
                        'appId' => 'BotPassword'
                ] );
-               $this->assertInstanceOf( 'BotPassword', $bp );
+               $this->assertInstanceOf( BotPassword::class, $bp );
                $this->assertFalse( $bp->isSaved() );
 
                $this->assertNull( BotPassword::newUnsaved( [
@@ -187,12 +187,12 @@ class BotPasswordTest extends MediaWikiTestCase {
                $bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
 
                $password = $bp->getPassword();
-               $this->assertInstanceOf( 'Password', $password );
+               $this->assertInstanceOf( Password::class, $password );
                $this->assertTrue( $password->equals( 'foobaz' ) );
 
                $bp->centralId = 44;
                $password = $bp->getPassword();
-               $this->assertInstanceOf( 'InvalidPassword', $password );
+               $this->assertInstanceOf( InvalidPassword::class, $password );
 
                $bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
                $dbw = wfGetDB( DB_MASTER );
@@ -203,21 +203,21 @@ class BotPasswordTest extends MediaWikiTestCase {
                        __METHOD__
                );
                $password = $bp->getPassword();
-               $this->assertInstanceOf( 'InvalidPassword', $password );
+               $this->assertInstanceOf( InvalidPassword::class, $password );
        }
 
        public function testInvalidateAllPasswordsForUser() {
                $bp1 = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
                $bp2 = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 43, 'BotPassword' ) );
 
-               $this->assertNotInstanceOf( 'InvalidPassword', $bp1->getPassword(), 'sanity check' );
-               $this->assertNotInstanceOf( 'InvalidPassword', $bp2->getPassword(), 'sanity check' );
+               $this->assertNotInstanceOf( InvalidPassword::class, $bp1->getPassword(), 'sanity check' );
+               $this->assertNotInstanceOf( InvalidPassword::class, $bp2->getPassword(), 'sanity check' );
                BotPassword::invalidateAllPasswordsForUser( $this->testUserName );
-               $this->assertInstanceOf( 'InvalidPassword', $bp1->getPassword() );
-               $this->assertNotInstanceOf( 'InvalidPassword', $bp2->getPassword() );
+               $this->assertInstanceOf( InvalidPassword::class, $bp1->getPassword() );
+               $this->assertNotInstanceOf( InvalidPassword::class, $bp2->getPassword() );
 
                $bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
-               $this->assertInstanceOf( 'InvalidPassword', $bp->getPassword() );
+               $this->assertInstanceOf( InvalidPassword::class, $bp->getPassword() );
        }
 
        public function testRemoveAllPasswordsForUser() {
@@ -312,7 +312,7 @@ class BotPasswordTest extends MediaWikiTestCase {
                );
 
                // Failed restriction
-               $request = $this->getMockBuilder( 'FauxRequest' )
+               $request = $this->getMockBuilder( FauxRequest::class )
                        ->setMethods( [ 'getIP' ] )
                        ->getMock();
                $request->expects( $this->any() )->method( 'getIP' )
@@ -333,7 +333,7 @@ class BotPasswordTest extends MediaWikiTestCase {
                        'sanity check'
                );
                $status = BotPassword::login( "{$this->testUserName}@BotPassword", 'foobaz', $request );
-               $this->assertInstanceOf( 'Status', $status );
+               $this->assertInstanceOf( Status::class, $status );
                $this->assertTrue( $status->isGood() );
                $session = $status->getValue();
                $this->assertInstanceOf( MediaWiki\Session\Session::class, $session );
@@ -368,7 +368,7 @@ class BotPasswordTest extends MediaWikiTestCase {
                $this->assertFalse( $bp->save( 'update', $passwordHash ) );
                $this->assertTrue( $bp->save( 'insert', $passwordHash ) );
                $bp2 = BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST );
-               $this->assertInstanceOf( 'BotPassword', $bp2 );
+               $this->assertInstanceOf( BotPassword::class, $bp2 );
                $this->assertEquals( $bp->getUserCentralId(), $bp2->getUserCentralId() );
                $this->assertEquals( $bp->getAppId(), $bp2->getAppId() );
                $this->assertEquals( $bp->getToken(), $bp2->getToken() );
@@ -376,21 +376,23 @@ class BotPasswordTest extends MediaWikiTestCase {
                $this->assertEquals( $bp->getGrants(), $bp2->getGrants() );
                $pw = TestingAccessWrapper::newFromObject( $bp )->getPassword();
                if ( $password === null ) {
-                       $this->assertInstanceOf( 'InvalidPassword', $pw );
+                       $this->assertInstanceOf( InvalidPassword::class, $pw );
                } else {
                        $this->assertTrue( $pw->equals( $password ) );
                }
 
                $token = $bp->getToken();
+               $this->assertEquals( 42, $bp->getUserCentralId() );
+               $this->assertEquals( 'TestSave', $bp->getAppId() );
                $this->assertFalse( $bp->save( 'insert' ) );
                $this->assertTrue( $bp->save( 'update' ) );
                $this->assertNotEquals( $token, $bp->getToken() );
                $bp2 = BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST );
-               $this->assertInstanceOf( 'BotPassword', $bp2 );
+               $this->assertInstanceOf( BotPassword::class, $bp2 );
                $this->assertEquals( $bp->getToken(), $bp2->getToken() );
                $pw = TestingAccessWrapper::newFromObject( $bp )->getPassword();
                if ( $password === null ) {
-                       $this->assertInstanceOf( 'InvalidPassword', $pw );
+                       $this->assertInstanceOf( InvalidPassword::class, $pw );
                } else {
                        $this->assertTrue( $pw->equals( $password ) );
                }