125 ->setMethods( [
'getUniqueId' ] )
126 ->getMockForAbstractClass();
127 $badReq->expects( $this->
any() )->method(
'getUniqueId' )
130 $user = \User::newFromName(
'UTSysop' );
131 $provider = TestingAccessWrapper::newFromObject(
136 ->setMethods( [
'allowsAuthenticationDataChange' ] )
137 ->setConstructorArgs( [
$request, \RequestContext::getMain()->getConfig() ] )
139 $manager->expects( $this->
any() )->method(
'allowsAuthenticationDataChange' )
141 return $req->getUniqueId() !==
'BadReq'
142 ? \StatusValue::newGood()
143 : \StatusValue::newFatal(
'no' );
145 $provider->setManager( $manager );
149 $provider->beginLinkAttempt( $user,
'state' )
152 $request->getSession()->setSecret(
'state', [
157 $provider->beginLinkAttempt( $user,
'state' )
161 $request->getSession()->setSecret(
'state', [
162 'maybeLink' => $reqs + [
'BadReq' => $badReq ]
164 $res = $provider->beginLinkAttempt( $user,
'state' );
167 $this->
assertSame(
'authprovider-confirmlink-message',
$res->message->getKey() );
172 foreach ( $expectReqs as $r ) {
174 $r->username = $user->getName();
176 $this->
assertEquals( $expectReqs, TestingAccessWrapper::newFromObject(
$req )->linkRequests );
180 $user = \User::newFromName(
'UTSysop' );
184 $done = [
false,
false,
false ];
187 $mock = $this->
getMockBuilder( ConfirmLinkSecondaryAuthenticationProvider::class )
188 ->setMethods( [
'beginLinkAttempt' ] )
190 $mock->expects( $this->
once() )->method(
'beginLinkAttempt' )
195 TestingAccessWrapper::newFromObject( $mock )->continueLinkAttempt( $user,
'state', $reqs )
199 $provider = $this->
getMockBuilder( ConfirmLinkSecondaryAuthenticationProvider::class )
201 'beginLinkAttempt',
'providerAllowsAuthenticationDataChange',
202 'providerChangeAuthenticationData'
205 $provider->expects( $this->never() )->method(
'beginLinkAttempt' );
206 $provider->expects( $this->
any() )->method(
'providerAllowsAuthenticationDataChange' )
208 return $req->getUniqueId() ===
'Request3'
209 ? \StatusValue::newFatal(
'foo' ) : \StatusValue::newGood();
211 $provider->expects( $this->
any() )->method(
'providerChangeAuthenticationData' )
213 $done[
$req->id] =
true;
216 'AuthManagerConfig' => [
220 [
'factory' =>
function () use ( $provider ) {
228 $provider->setManager( $manager );
229 $provider = TestingAccessWrapper::newFromObject( $provider );
235 $provider->continueLinkAttempt( $user,
'state', [
$req ] )
238 $request->getSession()->setSecret(
'state', [
243 $provider->continueLinkAttempt( $user,
'state', [
$req ] )
246 $request->getSession()->setSecret(
'state', [
251 $res = $provider->continueLinkAttempt( $user,
'state', [
$req ] )
253 $this->
assertSame( [
false,
false,
false ], $done );
255 $request->getSession()->setSecret(
'state', [
256 'maybeLink' => [ $reqs[
'Request2'] ],
258 $req->confirmedLinkIDs = [
'Request1',
'Request2' ];
259 $res = $provider->continueLinkAttempt( $user,
'state', [
$req ] );
261 $this->
assertSame( [
false,
true,
false ], $done );
262 $done = [
false,
false,
false ];
264 $request->getSession()->setSecret(
'state', [
265 'maybeLink' => $reqs,
267 $req->confirmedLinkIDs = [
'Request1',
'Request2' ];
268 $res = $provider->continueLinkAttempt( $user,
'state', [
$req ] );
270 $this->
assertSame( [
true,
true,
false ], $done );
271 $done = [
false,
false,
false ];
273 $request->getSession()->setSecret(
'state', [
274 'maybeLink' => $reqs,
276 $req->confirmedLinkIDs = [
'Request1',
'Request3' ];
277 $res = $provider->continueLinkAttempt( $user,
'state', [
$req ] );
281 $this->
assertSame( [
true,
false,
false ], $done );
282 $done = [
false,
false,
false ];
284 $res = $provider->continueLinkAttempt( $user,
'state', [
$res->neededRequests[0] ] );
286 $this->
assertSame( [
false,
false,
false ], $done );