3 namespace MediaWiki\Auth
;
7 * @covers MediaWiki\Auth\AbstractSecondaryAuthenticationProvider
9 class AbstractSecondaryAuthenticationProviderTest
extends \MediaWikiTestCase
{
10 protected function setUp() {
11 global $wgDisableAuthManager;
14 if ( $wgDisableAuthManager ) {
15 $this->markTestSkipped( '$wgDisableAuthManager is set' );
19 public function testAbstractSecondaryAuthenticationProvider() {
20 $user = \User
::newFromName( 'UTSysop' );
22 $provider = $this->getMockForAbstractClass( AbstractSecondaryAuthenticationProvider
::class );
25 $provider->continueSecondaryAuthentication( $user, [] );
26 $this->fail( 'Expected exception not thrown' );
27 } catch ( \BadMethodCallException
$ex ) {
31 $provider->continueSecondaryAccountCreation( $user, $user, [] );
32 $this->fail( 'Expected exception not thrown' );
33 } catch ( \BadMethodCallException
$ex ) {
36 $req = $this->getMockForAbstractClass( AuthenticationRequest
::class );
38 $this->assertTrue( $provider->providerAllowsPropertyChange( 'foo' ) );
40 \StatusValue
::newGood( 'ignored' ),
41 $provider->providerAllowsAuthenticationDataChange( $req )
44 \StatusValue
::newGood(),
45 $provider->testForAccountCreation( $user, $user, [] )
48 \StatusValue
::newGood(),
49 $provider->testUserForCreation( $user, AuthManager
::AUTOCREATE_SOURCE_SESSION
)
52 \StatusValue
::newGood(),
53 $provider->testUserForCreation( $user, false )
56 $provider->providerChangeAuthenticationData( $req );
57 $provider->autoCreatedAccount( $user, AuthManager
::AUTOCREATE_SOURCE_SESSION
);
59 $res = AuthenticationResponse
::newPass();
60 $provider->postAuthentication( $user, $res );
61 $provider->postAccountCreation( $user, $user, $res );
64 public function testProviderRevokeAccessForUser() {
66 for ( $i = 0; $i < 3; $i++
) {
67 $reqs[$i] = $this->getMock( AuthenticationRequest
::class );
68 $reqs[$i]->done
= false;
71 $provider = $this->getMockBuilder( AbstractSecondaryAuthenticationProvider
::class )
72 ->setMethods( [ 'providerChangeAuthenticationData' ] )
73 ->getMockForAbstractClass();
74 $provider->expects( $this->once() )->method( 'getAuthenticationRequests' )
76 $this->identicalTo( AuthManager
::ACTION_REMOVE
),
77 $this->identicalTo( [ 'username' => 'UTSysop' ] )
79 ->will( $this->returnValue( $reqs ) );
80 $provider->expects( $this->exactly( 3 ) )->method( 'providerChangeAuthenticationData' )
81 ->will( $this->returnCallback( function ( $req ) {
82 $this->assertSame( 'UTSysop', $req->username
);
83 $this->assertFalse( $req->done
);
87 $provider->providerRevokeAccessForUser( 'UTSysop' );
89 foreach ( $reqs as $i => $req ) {
90 $this->assertTrue( $req->done
, "#$i" );