13 $allowsAuthenticationDataChange, $canEditPrivate, $canSeePassword,
14 $userIsBlocked, $isAllowed, $isAllowedToDisplayPassword
17 'PasswordResetRoutes' => $passwordResetRoutes,
18 'EnableEmail' => $enableEmail,
21 $authManager = $this->getMockBuilder( AuthManager::class )->disableOriginalConstructor()
23 $authManager->expects( $this->any() )->method(
'allowsAuthenticationDataChange' )
24 ->willReturn( $allowsAuthenticationDataChange ? Status::newGood() : Status::newFatal(
'foo' ) );
26 $user = $this->getMock( User::class );
27 $user->expects( $this->any() )->method(
'getName' )->willReturn(
'Foo' );
28 $user->expects( $this->any() )->method(
'isBlocked' )->willReturn( $userIsBlocked );
29 $user->expects( $this->any() )->method(
'isAllowed' )
30 ->will( $this->returnCallback(
function ( $perm )
use ( $canEditPrivate, $canSeePassword ) {
31 if ( $perm ===
'editmyprivateinfo' ) {
32 return $canEditPrivate;
33 } elseif ( $perm ===
'passwordreset' ) {
34 return $canSeePassword;
36 $this->fail(
'Unexpected permission check' );
42 $this->assertSame( $isAllowed, $passwordReset->isAllowed(
$user )->isGood() );
43 $this->assertSame( $isAllowedToDisplayPassword,
44 $passwordReset->isAllowed(
$user,
true )->isGood() );
124 'PasswordResetRoutes' => [
'username' =>
true,
'email' =>
true ],
125 'EnableEmail' =>
true,
128 $authManager = $this->getMockBuilder( AuthManager::class )->disableOriginalConstructor()
130 $authManager->expects( $this->any() )->method(
'allowsAuthenticationDataChange' )
131 ->willReturn( Status::newGood() );
132 $authManager->expects( $this->exactly( 2 ) )->method(
'changeAuthenticationData' );
136 $performingUser = $this->getMock( User::class );
137 $performingUser->expects( $this->any() )->method(
'getRequest' )->willReturn(
$request );
138 $performingUser->expects( $this->any() )->method(
'isAllowed' )->willReturn(
true );
140 $targetUser1 = $this->getMock( User::class );
141 $targetUser2 = $this->getMock( User::class );
142 $targetUser1->expects( $this->any() )->method(
'getName' )->willReturn(
'User1' );
143 $targetUser2->expects( $this->any() )->method(
'getName' )->willReturn(
'User2' );
144 $targetUser1->expects( $this->any() )->method(
'getId' )->willReturn( 1 );
145 $targetUser2->expects( $this->any() )->method(
'getId' )->willReturn( 2 );
146 $targetUser1->expects( $this->any() )->method(
'getEmail' )->willReturn(
'foo@bar.baz' );
147 $targetUser2->expects( $this->any() )->method(
'getEmail' )->willReturn(
'foo@bar.baz' );
149 $passwordReset = $this->getMockBuilder( PasswordReset::class )
150 ->setMethods( [
'getUsersByEmail' ] )->setConstructorArgs( [ $config, $authManager ] )
152 $passwordReset->expects( $this->any() )->method(
'getUsersByEmail' )->with(
'foo@bar.baz' )
153 ->willReturn( [ $targetUser1, $targetUser2 ] );
155 $status = $passwordReset->isAllowed( $performingUser );
156 $this->assertTrue(
$status->isGood() );
158 $status = $passwordReset->execute( $performingUser,
null,
'foo@bar.baz' );
159 $this->assertTrue(
$status->isGood() );