Merge "Speed up password-handling in the unit tests"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiLoginTest.php
index 00701db..2f8ffcc 100644 (file)
@@ -13,6 +13,8 @@ class ApiLoginTest extends ApiTestCase {
         * Test result of attempted login with an empty username
         */
        public function testApiLoginNoName() {
+               global $wgDisableAuthManager;
+
                $session = [
                        'wsTokenSecrets' => [ 'login' => 'foobar' ],
                ];
@@ -20,14 +22,14 @@ class ApiLoginTest extends ApiTestCase {
                        'lgname' => '', 'lgpassword' => self::$users['sysop']->password,
                        'lgtoken' => (string)( new MediaWiki\Session\Token( 'foobar', '' ) )
                ], $session );
-               $this->assertEquals( 'NoName', $data[0]['login']['result'] );
+               $this->assertEquals( $wgDisableAuthManager ? 'NoName' : 'Failed', $data[0]['login']['result'] );
        }
 
        public function testApiLoginBadPass() {
-               global $wgServer;
+               global $wgServer, $wgDisableAuthManager;
 
                $user = self::$users['sysop'];
-               $user->getUser()->logOut();
+               $user->getUser()->logout();
 
                if ( !isset( $wgServer ) ) {
                        $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' );
@@ -61,7 +63,7 @@ class ApiLoginTest extends ApiTestCase {
                $this->assertNotInternalType( "bool", $result );
                $a = $result["login"]["result"];
 
-               $this->assertEquals( "WrongPass", $a );
+               $this->assertEquals( $wgDisableAuthManager ? 'WrongPass' : 'Failed', $a );
        }
 
        public function testApiLoginGoodPass() {
@@ -72,7 +74,7 @@ class ApiLoginTest extends ApiTestCase {
                }
 
                $user = self::$users['sysop'];
-               $user->getUser()->logOut();
+               $user->getUser()->logout();
 
                $ret = $this->doApiRequest( [
                                "action" => "login",
@@ -153,7 +155,7 @@ class ApiLoginTest extends ApiTestCase {
                $this->assertNotEquals( false, $serverName );
                $serializedCookie = $cj->serializeToHttpRequest( $wgScriptPath, $serverName );
                $this->assertNotEquals( '', $serializedCookie );
-               $this->assertRegexp(
+               $this->assertRegExp(
                        '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . $user->userName . '; .*Token=/',
                        $serializedCookie
                );
@@ -193,7 +195,7 @@ class ApiLoginTest extends ApiTestCase {
                $this->setMwGlobals( [
                        'wgSessionProviders' => array_merge( $wgSessionProviders, [
                                [
-                                       'class' => 'MediaWiki\\Session\\BotPasswordSessionProvider',
+                                       'class' => MediaWiki\Session\BotPasswordSessionProvider::class,
                                        'args' => [ [ 'priority' => 40 ] ],
                                ]
                        ] ),
@@ -207,14 +209,14 @@ class ApiLoginTest extends ApiTestCase {
 
                // Make sure our session provider is present
                $manager = TestingAccessWrapper::newFromObject( MediaWiki\Session\SessionManager::singleton() );
-               if ( !isset( $manager->sessionProviders['MediaWiki\\Session\\BotPasswordSessionProvider'] ) ) {
+               if ( !isset( $manager->sessionProviders[MediaWiki\Session\BotPasswordSessionProvider::class] ) ) {
                        $tmp = $manager->sessionProviders;
                        $manager->sessionProviders = null;
                        $manager->sessionProviders = $tmp + $manager->getProviders();
                }
                $this->assertNotNull(
                        MediaWiki\Session\SessionManager::singleton()->getProvider(
-                               'MediaWiki\\Session\\BotPasswordSessionProvider'
+                               MediaWiki\Session\BotPasswordSessionProvider::class
                        ),
                        'sanity check'
                );
@@ -226,8 +228,7 @@ class ApiLoginTest extends ApiTestCase {
                $passwordFactory = new PasswordFactory();
                $passwordFactory->init( RequestContext::getMain()->getConfig() );
                // A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
-               $passwordFactory->setDefaultType( 'A' );
-               $pwhash = $passwordFactory->newFromPlaintext( 'foobaz' );
+               $passwordHash = $passwordFactory->newFromPlaintext( 'foobaz' );
 
                $dbw = wfGetDB( DB_MASTER );
                $dbw->insert(
@@ -235,7 +236,7 @@ class ApiLoginTest extends ApiTestCase {
                        [
                                'bp_user' => $centralId,
                                'bp_app_id' => 'foo',
-                               'bp_password' => $pwhash->toString(),
+                               'bp_password' => $passwordHash->toString(),
                                'bp_token' => '',
                                'bp_restrictions' => MWRestrictions::newDefault()->toJson(),
                                'bp_grants' => '["test"]',