X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fuser%2FPasswordResetTest.php;h=b5677fa99fe44da49084f266c372f49a8adb5989;hp=4a7aa05b146420360e3ecca0c6ce0cfe20050004;hb=9feb18149101fb505b8d55beb38c2baa9f848384;hpb=60882bb6b07aa0a9cbf0f8a2224cc94e2575dc11 diff --git a/tests/phpunit/includes/user/PasswordResetTest.php b/tests/phpunit/includes/user/PasswordResetTest.php index 4a7aa05b14..b5677fa99f 100644 --- a/tests/phpunit/includes/user/PasswordResetTest.php +++ b/tests/phpunit/includes/user/PasswordResetTest.php @@ -4,23 +4,32 @@ use MediaWiki\Auth\AuthManager; use MediaWiki\Block\DatabaseBlock; use MediaWiki\Block\CompositeBlock; use MediaWiki\Block\SystemBlock; +use MediaWiki\Config\ServiceOptions; use MediaWiki\Permissions\PermissionManager; +use Psr\Log\NullLogger; +use Wikimedia\Rdbms\ILoadBalancer; /** * @covers PasswordReset * @group Database */ class PasswordResetTest extends MediaWikiTestCase { + private function makeConfig( $enableEmail, array $passwordResetRoutes = [] ) { + $hash = new HashConfig( [ + 'EnableEmail' => $enableEmail, + 'PasswordResetRoutes' => $passwordResetRoutes, + ] ); + + return new ServiceOptions( PasswordReset::$constructorOptions, $hash ); + } + /** * @dataProvider provideIsAllowed */ public function testIsAllowed( $passwordResetRoutes, $enableEmail, $allowsAuthenticationDataChange, $canEditPrivate, $block, $globalBlock, $isAllowed ) { - $config = new HashConfig( [ - 'PasswordResetRoutes' => $passwordResetRoutes, - 'EnableEmail' => $enableEmail, - ] ); + $config = $this->makeConfig( $enableEmail, $passwordResetRoutes ); $authManager = $this->getMockBuilder( AuthManager::class )->disableOriginalConstructor() ->getMock(); @@ -39,10 +48,14 @@ class PasswordResetTest extends MediaWikiTestCase { ->with( $user, 'editmyprivateinfo' ) ->willReturn( $canEditPrivate ); + $loadBalancer = $this->getMockBuilder( ILoadBalancer::class )->getMock(); + $passwordReset = new PasswordReset( $config, $authManager, - $permissionManager + $permissionManager, + $loadBalancer, + new NullLogger() ); $this->assertSame( $isAllowed, $passwordReset->isAllowed( $user )->isGood() ); @@ -187,10 +200,7 @@ class PasswordResetTest extends MediaWikiTestCase { } public function testExecute_email() { - $config = new HashConfig( [ - 'PasswordResetRoutes' => [ 'username' => true, 'email' => true ], - 'EnableEmail' => true, - ] ); + $config = $this->makeConfig( true, [ 'username' => true, 'email' => true ] ); // Unregister the hooks for proper unit testing $this->mergeMwGlobalArrayValue( 'wgHooks', [ @@ -204,6 +214,14 @@ class PasswordResetTest extends MediaWikiTestCase { ->willReturn( Status::newGood() ); $authManager->expects( $this->exactly( 2 ) )->method( 'changeAuthenticationData' ); + $permissionManager = $this->getMockBuilder( PermissionManager::class ) + ->disableOriginalConstructor() + ->getMock(); + $permissionManager->method( 'userHasRight' )->willReturn( true ); + + $loadBalancer = $this->getMockBuilder( ILoadBalancer::class ) + ->getMock(); + $request = new FauxRequest(); $request->setIP( '1.2.3.4' ); $performingUser = $this->getMockBuilder( User::class )->getMock(); @@ -228,8 +246,14 @@ class PasswordResetTest extends MediaWikiTestCase { $targetUser2->expects( $this->any() )->method( 'getEmail' )->willReturn( 'foo@bar.baz' ); $passwordReset = $this->getMockBuilder( PasswordReset::class ) - ->setConstructorArgs( [ $config, $authManager, $permissionManager ] ) ->setMethods( [ 'getUsersByEmail' ] ) + ->setConstructorArgs( [ + $config, + $authManager, + $permissionManager, + $loadBalancer, + new NullLogger() + ] ) ->getMock(); $passwordReset->expects( $this->any() )->method( 'getUsersByEmail' )->with( 'foo@bar.baz' ) ->willReturn( [ $targetUser1, $targetUser2 ] );