wiki.techinc.nl/tests/phpunit/unit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php
Thiemo Kreuz 40764d277c Replace PHPUnit ->returnValue() with ->willReturn() shortcut
It's the same and makes the test code much more readable, I
would like to argue.

Because of the was I split all the changes I made into smaller
patches this patch contains some other changes in the same
lines where I could not split them off. E.g. removal of
->any(), which is the default anyway and doesn't do anything.

Change-Id: Ib297b989d4aec33b31a4e33fe9d5032865b39be0
2021-04-22 10:37:45 +02:00

89 lines
2.8 KiB
PHP

<?php
namespace MediaWiki\Tests\Unit\Auth;
use MediaWiki\Auth\AbstractSecondaryAuthenticationProvider;
use MediaWiki\Auth\AuthenticationRequest;
use MediaWiki\Auth\AuthenticationResponse;
use MediaWiki\Auth\AuthManager;
/**
* @group AuthManager
* @covers \MediaWiki\Auth\AbstractSecondaryAuthenticationProvider
*/
class AbstractSecondaryAuthenticationProviderTest extends \MediaWikiUnitTestCase {
public function testAbstractSecondaryAuthenticationProvider() {
$user = $this->createMock( \User::class );
$provider = $this->getMockForAbstractClass( AbstractSecondaryAuthenticationProvider::class );
try {
$provider->continueSecondaryAuthentication( $user, [] );
$this->fail( 'Expected exception not thrown' );
} catch ( \BadMethodCallException $ex ) {
}
try {
$provider->continueSecondaryAccountCreation( $user, $user, [] );
$this->fail( 'Expected exception not thrown' );
} catch ( \BadMethodCallException $ex ) {
}
$req = $this->getMockForAbstractClass( AuthenticationRequest::class );
$this->assertTrue( $provider->providerAllowsPropertyChange( 'foo' ) );
$this->assertEquals(
\StatusValue::newGood( 'ignored' ),
$provider->providerAllowsAuthenticationDataChange( $req )
);
$this->assertEquals(
\StatusValue::newGood(),
$provider->testForAccountCreation( $user, $user, [] )
);
$this->assertEquals(
\StatusValue::newGood(),
$provider->testUserForCreation( $user, AuthManager::AUTOCREATE_SOURCE_SESSION )
);
$this->assertEquals(
\StatusValue::newGood(),
$provider->testUserForCreation( $user, false )
);
$provider->providerChangeAuthenticationData( $req );
$provider->autoCreatedAccount( $user, AuthManager::AUTOCREATE_SOURCE_SESSION );
$res = AuthenticationResponse::newPass();
$provider->postAuthentication( $user, $res );
$provider->postAccountCreation( $user, $user, $res );
}
public function testProviderRevokeAccessForUser() {
$reqs = [];
for ( $i = 0; $i < 3; $i++ ) {
$reqs[$i] = $this->createMock( AuthenticationRequest::class );
$reqs[$i]->done = false;
}
$provider = $this->getMockBuilder( AbstractSecondaryAuthenticationProvider::class )
->onlyMethods( [ 'providerChangeAuthenticationData' ] )
->getMockForAbstractClass();
$provider->expects( $this->once() )->method( 'getAuthenticationRequests' )
->with(
$this->identicalTo( AuthManager::ACTION_REMOVE ),
$this->identicalTo( [ 'username' => 'UTSysop' ] )
)
->willReturn( $reqs );
$provider->expects( $this->exactly( 3 ) )->method( 'providerChangeAuthenticationData' )
->will( $this->returnCallback( function ( $req ) {
$this->assertSame( 'UTSysop', $req->username );
$this->assertFalse( $req->done );
$req->done = true;
} ) );
$provider->providerRevokeAccessForUser( 'UTSysop' );
foreach ( $reqs as $i => $req ) {
$this->assertTrue( $req->done, "#$i" );
}
}
}