wiki.techinc.nl/tests/phpunit/unit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php
Umherirrender 77792c225d tests: Change assertion in AbstractSecondaryAuthenticationProviderTest
Creation of dynamic property Mock_AuthenticationRequest_4d271de1::$done
is deprecated in php8.2

Bug: T314099
Change-Id: I21e7a257a5e695cc32f183add5ba6785a6898118
2023-01-06 04:06:32 +01:00

86 lines
2.7 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 );
}
$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' )
->willReturnCallback( function ( $req ) {
$this->assertSame( 'UTSysop', $req->username );
} );
$provider->providerRevokeAccessForUser( 'UTSysop' );
foreach ( $reqs as $i => $req ) {
$this->assertNotNull( $req->username, "#$i" );
}
}
}