Merge "Show a warning in edit preview when a template loop is detected"
[lhc/web/wiklou.git] / tests / phpunit / includes / auth / AuthPluginPrimaryAuthenticationProviderTest.php
index 44f2743..6970313 100644 (file)
@@ -7,15 +7,6 @@ namespace MediaWiki\Auth;
  * @covers MediaWiki\Auth\AuthPluginPrimaryAuthenticationProvider
  */
 class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
-       protected function setUp() {
-               global $wgDisableAuthManager;
-
-               parent::setUp();
-               if ( $wgDisableAuthManager ) {
-                       $this->markTestSkipped( '$wgDisableAuthManager is set' );
-               }
-       }
-
        public function testConstruction() {
                $plugin = new AuthManagerAuthPlugin();
                try {
@@ -29,7 +20,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
                        );
                }
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
 
                $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin );
@@ -38,14 +29,14 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
                        $provider->getAuthenticationRequests( AuthManager::ACTION_LOGIN, [] )
                );
 
-               $req = $this->getMock( PasswordAuthenticationRequest::class );
+               $req = $this->createMock( PasswordAuthenticationRequest::class );
                $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin, get_class( $req ) );
                $this->assertEquals(
                        [ $req ],
                        $provider->getAuthenticationRequests( AuthManager::ACTION_LOGIN, [] )
                );
 
-               $reqType = get_class( $this->getMock( AuthenticationRequest::class ) );
+               $reqType = get_class( $this->createMock( AuthenticationRequest::class ) );
                try {
                        $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin, $reqType );
                        $this->fail( 'Expected exception not thrown' );
@@ -60,7 +51,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
        public function testOnUserSaveSettings() {
                $user = \User::newFromName( 'UTSysop' );
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->once() )->method( 'updateExternalDB' )
                        ->with( $this->identicalTo( $user ) );
@@ -72,7 +63,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
        public function testOnUserGroupsChanged() {
                $user = \User::newFromName( 'UTSysop' );
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->once() )->method( 'updateExternalDBGroups' )
                        ->with(
@@ -88,14 +79,14 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
        public function testOnUserLoggedIn() {
                $user = \User::newFromName( 'UTSysop' );
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->exactly( 2 ) )->method( 'updateUser' )
                        ->with( $this->identicalTo( $user ) );
                $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin );
                \Hooks::run( 'UserLoggedIn', [ $user ] );
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->once() )->method( 'updateUser' )
                        ->will( $this->returnCallback( function ( &$user ) {
@@ -116,14 +107,14 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
        public function testOnLocalUserCreated() {
                $user = \User::newFromName( 'UTSysop' );
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->exactly( 2 ) )->method( 'initUser' )
                        ->with( $this->identicalTo( $user ), $this->identicalTo( false ) );
                $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin );
                \Hooks::run( 'LocalUserCreated', [ $user, false ] );
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->once() )->method( 'initUser' )
                        ->will( $this->returnCallback( function ( &$user ) {
@@ -142,7 +133,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
        }
 
        public function testGetUniqueId() {
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin );
                $this->assertSame(
@@ -158,7 +149,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
         * @param bool $allowPasswordChange
         */
        public function testGetAuthenticationRequests( $action, $response, $allowPasswordChange ) {
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->any() )->method( 'allowPasswordChange' )
                        ->will( $this->returnValue( $allowPasswordChange ) );
@@ -330,7 +321,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
        }
 
        public function testTestUserExists() {
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->once() )->method( 'userExists' )
                        ->with( $this->equalTo( 'Foo' ) )
@@ -339,7 +330,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
 
                $this->assertTrue( $provider->testUserExists( 'foo' ) );
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->once() )->method( 'userExists' )
                        ->with( $this->equalTo( 'Foo' ) )
@@ -350,7 +341,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
        }
 
        public function testTestUserCanAuthenticate() {
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->once() )->method( 'userExists' )
                        ->with( $this->equalTo( 'Foo' ) )
@@ -364,7 +355,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
                        ->getMock();
                $pluginUser->expects( $this->once() )->method( 'isLocked' )
                        ->will( $this->returnValue( true ) );
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->once() )->method( 'userExists' )
                        ->with( $this->equalTo( 'Foo' ) )
@@ -384,7 +375,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
                        ->getMock();
                $pluginUser->expects( $this->once() )->method( 'isLocked' )
                        ->will( $this->returnValue( false ) );
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->once() )->method( 'userExists' )
                        ->with( $this->equalTo( 'Foo' ) )
@@ -442,7 +433,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
        }
 
        public function testProviderAllowsPropertyChange() {
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->any() )->method( 'allowPropChange' )
                        ->will( $this->returnCallback( function ( $prop ) {
@@ -462,7 +453,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
         */
        public function testProviderAllowsAuthenticationDataChange( $type, $allow, $expect ) {
                $domains = $type instanceof PasswordDomainAuthenticationRequest ? [ 'foo', 'bar' ] : [];
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( $domains );
                $plugin->expects( $allow === null ? $this->never() : $this->once() )
                        ->method( 'allowPasswordChange' )->will( $this->returnValue( $allow ) );
@@ -475,7 +466,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
                if ( is_object( $type ) ) {
                        $req = $type;
                } else {
-                       $req = $this->getMock( $type );
+                       $req = $this->createMock( $type );
                }
                $req->action = AuthManager::ACTION_CHANGE;
                $req->username = 'UTSysop';
@@ -511,12 +502,12 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
        }
 
        public function testProviderChangeAuthenticationData() {
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->never() )->method( 'setPassword' );
                $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin );
                $provider->providerChangeAuthenticationData(
-                       $this->getMock( AuthenticationRequest::class )
+                       $this->createMock( AuthenticationRequest::class )
                );
 
                $req = new PasswordAuthenticationRequest();
@@ -524,7 +515,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
                $req->username = 'foo';
                $req->password = 'bar';
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->once() )->method( 'setPassword' )
                        ->with( $this->callback( function ( $u ) {
@@ -534,7 +525,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
                $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin );
                $provider->providerChangeAuthenticationData( $req );
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->once() )->method( 'setPassword' )
                        ->with( $this->callback( function ( $u ) {
@@ -550,7 +541,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
                        $this->assertSame( 'authmanager-authplugin-setpass-failed-message', $e->msg );
                }
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )
                        ->will( $this->returnValue( [ 'Domain1', 'Domain2' ] ) );
                $plugin->expects( $this->any() )->method( 'validDomain' )
@@ -578,7 +569,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
         * @param string $expect
         */
        public function testAccountCreationType( $can, $expect ) {
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->once() )
                        ->method( 'canCreateAccounts' )->will( $this->returnValue( $can ) );
@@ -597,7 +588,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
        public function testTestForAccountCreation() {
                $user = \User::newFromName( 'foo' );
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin );
                $this->assertEquals(
@@ -615,7 +606,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
                $req->action = AuthManager::ACTION_CREATE;
                $reqs = [ PasswordAuthenticationRequest::class => $req ];
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->any() )->method( 'canCreateAccounts' )
                        ->will( $this->returnValue( false ) );
@@ -630,7 +621,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
                        );
                }
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->any() )->method( 'canCreateAccounts' )
                        ->will( $this->returnValue( true ) );
@@ -659,7 +650,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
                $req->username = 'foo';
                $req->password = 'bar';
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->any() )->method( 'canCreateAccounts' )
                        ->will( $this->returnValue( true ) );
@@ -679,7 +670,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
                        $provider->beginPrimaryAccountCreation( $user, $user, $reqs )
                );
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
                $plugin->expects( $this->any() )->method( 'canCreateAccounts' )
                        ->will( $this->returnValue( true ) );
@@ -698,7 +689,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase {
                $this->assertSame( AuthenticationResponse::FAIL, $ret->status );
                $this->assertSame( 'authmanager-authplugin-create-fail', $ret->message->getKey() );
 
-               $plugin = $this->getMock( 'AuthPlugin' );
+               $plugin = $this->createMock( 'AuthPlugin' );
                $plugin->expects( $this->any() )->method( 'canCreateAccounts' )
                        ->will( $this->returnValue( true ) );
                $plugin->expects( $this->any() )->method( 'domainList' )