diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/tests/phpunit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php |
first commit
Diffstat (limited to 'www/wiki/tests/phpunit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php')
-rw-r--r-- | www/wiki/tests/phpunit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/www/wiki/tests/phpunit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php b/www/wiki/tests/phpunit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php new file mode 100644 index 00000000..41cf62ea --- /dev/null +++ b/www/wiki/tests/phpunit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php @@ -0,0 +1,84 @@ +<?php + +namespace MediaWiki\Auth; + +/** + * @group AuthManager + * @covers MediaWiki\Auth\AbstractSecondaryAuthenticationProvider + */ +class AbstractSecondaryAuthenticationProviderTest extends \MediaWikiTestCase { + public function testAbstractSecondaryAuthenticationProvider() { + $user = \User::newFromName( 'UTSysop' ); + + $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 ) + ->setMethods( [ 'providerChangeAuthenticationData' ] ) + ->getMockForAbstractClass(); + $provider->expects( $this->once() )->method( 'getAuthenticationRequests' ) + ->with( + $this->identicalTo( AuthManager::ACTION_REMOVE ), + $this->identicalTo( [ 'username' => 'UTSysop' ] ) + ) + ->will( $this->returnValue( $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" ); + } + } +} |