X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fauth%2FAuthPluginPrimaryAuthenticationProviderTest.php;h=57c3e7eb5dbf27bcb03c2266474c38d9e2e8c06f;hp=96e50e07ac1e9e9f8f7ec2f2130eb06f98484cfa;hb=a2c8c2969420a0f150c03f76e3a0bf9028fcda43;hpb=99dbf4e1d4d7f18e02935bdb8cd3be4413ffe729 diff --git a/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php index 96e50e07ac..57c3e7eb5d 100644 --- a/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php @@ -20,7 +20,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { ); } - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); @@ -29,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' ); @@ -51,7 +51,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { public function testOnUserSaveSettings() { $user = \User::newFromName( 'UTSysop' ); - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'updateExternalDB' ) ->with( $this->identicalTo( $user ) ); @@ -63,7 +63,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { public function testOnUserGroupsChanged() { $user = \User::newFromName( 'UTSysop' ); - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'updateExternalDBGroups' ) ->with( @@ -73,20 +73,20 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); - \Hooks::run( 'UserGroupsChanged', [ $user, [ 'added' ], [ 'removed' ] ] ); + \Hooks::run( 'UserGroupsChanged', [ $user, [ 'added' ], [ 'removed' ], false, false, [], [] ] ); } public function testOnUserLoggedIn() { $user = \User::newFromName( 'UTSysop' ); - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $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::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'updateUser' ) ->will( $this->returnCallback( function ( &$user ) { @@ -107,14 +107,14 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { public function testOnLocalUserCreated() { $user = \User::newFromName( 'UTSysop' ); - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $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::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'initUser' ) ->will( $this->returnCallback( function ( &$user ) { @@ -133,7 +133,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testGetUniqueId() { - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); $this->assertSame( @@ -149,7 +149,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { * @param bool $allowPasswordChange */ public function testGetAuthenticationRequests( $action, $response, $allowPasswordChange ) { - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->any() )->method( 'allowPasswordChange' ) ->will( $this->returnValue( $allowPasswordChange ) ); @@ -178,7 +178,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $req->action = AuthManager::ACTION_LOGIN; $reqs = [ PasswordAuthenticationRequest::class => $req ]; - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'authenticate' ] ) ->getMock(); $plugin->expects( $this->never() )->method( 'authenticate' ); @@ -206,7 +206,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $req->username = 'foo'; $req->password = 'bar'; - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'authenticate' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' ) @@ -220,7 +220,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider->beginPrimaryAuthentication( $reqs ) ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'authenticate' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' ) @@ -232,13 +232,13 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider->beginPrimaryAuthentication( $reqs ) ); - $pluginUser = $this->getMockBuilder( 'AuthPluginUser' ) + $pluginUser = $this->getMockBuilder( \AuthPluginUser::class ) ->setMethods( [ 'isLocked' ] ) ->disableOriginalConstructor() ->getMock(); $pluginUser->expects( $this->once() )->method( 'isLocked' ) ->will( $this->returnValue( true ) ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'getUserInstance', 'authenticate' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' ) @@ -252,7 +252,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider->beginPrimaryAuthentication( $reqs ) ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'authenticate' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' ) @@ -266,7 +266,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider->beginPrimaryAuthentication( $reqs ) ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'authenticate', 'strict' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' ) @@ -280,7 +280,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $this->assertSame( AuthenticationResponse::FAIL, $ret->status ); $this->assertSame( 'wrongpassword', $ret->message->getKey() ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'authenticate', 'strictUserAuth' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' ) @@ -296,7 +296,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $this->assertSame( AuthenticationResponse::FAIL, $ret->status ); $this->assertSame( 'wrongpassword', $ret->message->getKey() ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'domainList', 'validDomain', 'setDomain', 'userExists', 'authenticate' ] ) ->getMock(); $plugin->expects( $this->any() )->method( 'domainList' ) @@ -321,7 +321,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testTestUserExists() { - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'userExists' ) ->with( $this->equalTo( 'Foo' ) ) @@ -330,7 +330,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $this->assertTrue( $provider->testUserExists( 'foo' ) ); - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'userExists' ) ->with( $this->equalTo( 'Foo' ) ) @@ -341,7 +341,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testTestUserCanAuthenticate() { - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'userExists' ) ->with( $this->equalTo( 'Foo' ) ) @@ -350,19 +350,19 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); $this->assertFalse( $provider->testUserCanAuthenticate( 'foo' ) ); - $pluginUser = $this->getMockBuilder( 'AuthPluginUser' ) + $pluginUser = $this->getMockBuilder( \AuthPluginUser::class ) ->disableOriginalConstructor() ->getMock(); $pluginUser->expects( $this->once() )->method( 'isLocked' ) ->will( $this->returnValue( true ) ); - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'userExists' ) ->with( $this->equalTo( 'Foo' ) ) ->will( $this->returnValue( true ) ); $plugin->expects( $this->once() )->method( 'getUserInstance' ) ->with( $this->callback( function ( $user ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertEquals( 'Foo', $user->getName() ); return true; } ) ) @@ -370,19 +370,19 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); $this->assertFalse( $provider->testUserCanAuthenticate( 'foo' ) ); - $pluginUser = $this->getMockBuilder( 'AuthPluginUser' ) + $pluginUser = $this->getMockBuilder( \AuthPluginUser::class ) ->disableOriginalConstructor() ->getMock(); $pluginUser->expects( $this->once() )->method( 'isLocked' ) ->will( $this->returnValue( false ) ); - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'userExists' ) ->with( $this->equalTo( 'Foo' ) ) ->will( $this->returnValue( true ) ); $plugin->expects( $this->once() )->method( 'getUserInstance' ) ->with( $this->callback( function ( $user ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertEquals( 'Foo', $user->getName() ); return true; } ) ) @@ -392,7 +392,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testProviderRevokeAccessForUser() { - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'setPassword' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' )->willReturn( true ); @@ -404,7 +404,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); $provider->providerRevokeAccessForUser( 'foo' ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'domainList', 'userExists', 'setPassword' ] ) ->getMock(); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [ 'D1', 'D2', 'D3' ] ); @@ -433,7 +433,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testProviderAllowsPropertyChange() { - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->any() )->method( 'allowPropChange' ) ->will( $this->returnCallback( function ( $prop ) { @@ -453,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::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( $domains ); $plugin->expects( $allow === null ? $this->never() : $this->once() ) ->method( 'allowPasswordChange' )->will( $this->returnValue( $allow ) ); @@ -466,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'; @@ -502,12 +502,12 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testProviderChangeAuthenticationData() { - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $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(); @@ -515,7 +515,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $req->username = 'foo'; $req->password = 'bar'; - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'setPassword' ) ->with( $this->callback( function ( $u ) { @@ -525,7 +525,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); $provider->providerChangeAuthenticationData( $req ); - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'setPassword' ) ->with( $this->callback( function ( $u ) { @@ -541,7 +541,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $this->assertSame( 'authmanager-authplugin-setpass-failed-message', $e->msg ); } - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' ) ->will( $this->returnValue( [ 'Domain1', 'Domain2' ] ) ); $plugin->expects( $this->any() )->method( 'validDomain' ) @@ -569,7 +569,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { * @param string $expect */ public function testAccountCreationType( $can, $expect ) { - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() ) ->method( 'canCreateAccounts' )->will( $this->returnValue( $can ) ); @@ -588,7 +588,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { public function testTestForAccountCreation() { $user = \User::newFromName( 'foo' ); - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); $this->assertEquals( @@ -606,7 +606,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $req->action = AuthManager::ACTION_CREATE; $reqs = [ PasswordAuthenticationRequest::class => $req ]; - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->any() )->method( 'canCreateAccounts' ) ->will( $this->returnValue( false ) ); @@ -621,7 +621,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { ); } - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->any() )->method( 'canCreateAccounts' ) ->will( $this->returnValue( true ) ); @@ -650,7 +650,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $req->username = 'foo'; $req->password = 'bar'; - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->any() )->method( 'canCreateAccounts' ) ->will( $this->returnValue( true ) ); @@ -670,7 +670,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider->beginPrimaryAccountCreation( $user, $user, $reqs ) ); - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->any() )->method( 'canCreateAccounts' ) ->will( $this->returnValue( true ) ); @@ -689,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::class ); $plugin->expects( $this->any() )->method( 'canCreateAccounts' ) ->will( $this->returnValue( true ) ); $plugin->expects( $this->any() )->method( 'domainList' )