Debian Codegraph @

tests/phpunit/unit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Unit\Auth;
4
5 use BadMethodCallException;
6 use MediaWiki\Auth\AbstractSecondaryAuthenticationProvider;
7 use MediaWiki\Auth\AuthenticationRequest;
8 use MediaWiki\Auth\AuthenticationResponse;
9 use MediaWiki\Auth\AuthManager;
10 use MediaWiki\User\User;
11 use MediaWikiUnitTestCase;
12 use StatusValue;
13
14 /**
15 * @group AuthManager
16 * @covers \MediaWiki\Auth\AbstractSecondaryAuthenticationProvider
17 */
18 class AbstractSecondaryAuthenticationProviderTest extends MediaWikiUnitTestCase {
19 public function testAbstractSecondaryAuthenticationProvider() {
20 $user = $this->createMock( User::class );
21
22 $provider = $this->getMockForAbstractClass( AbstractSecondaryAuthenticationProvider::class );
23
24 try {
25 $provider->continueSecondaryAuthentication( $user, [] );
26 $this->fail( 'Expected exception not thrown' );
27 } catch ( BadMethodCallException $ex ) {
28 }
29
30 try {
31 $provider->continueSecondaryAccountCreation( $user, $user, [] );
32 $this->fail( 'Expected exception not thrown' );
33 } catch ( BadMethodCallException $ex ) {
34 }
35
36 $req = $this->getMockForAbstractClass( AuthenticationRequest::class );
37
38 $this->assertTrue( $provider->providerAllowsPropertyChange( 'foo' ) );
39 $this->assertEquals(
40 StatusValue::newGood( 'ignored' ),
41 $provider->providerAllowsAuthenticationDataChange( $req )
42 );
43 $this->assertEquals(
44 StatusValue::newGood(),
45 $provider->testForAccountCreation( $user, $user, [] )
46 );
47 $this->assertEquals(
48 StatusValue::newGood(),
49 $provider->testUserForCreation( $user, AuthManager::AUTOCREATE_SOURCE_SESSION )
50 );
51 $this->assertEquals(
52 StatusValue::newGood(),
53 $provider->testUserForCreation( $user, false )
54 );
55
56 $provider->providerChangeAuthenticationData( $req );
57 $provider->autoCreatedAccount( $user, AuthManager::AUTOCREATE_SOURCE_SESSION );
58
59 $res = AuthenticationResponse::newPass();
60 $provider->postAuthentication( $user, $res );
61 $provider->postAccountCreation( $user, $user, $res );
62 }
63
64 public function testProviderRevokeAccessForUser() {
65 $reqs = [];
66 for ( $i = 0; $i < 3; $i++ ) {
67 $reqs[$i] = $this->createMock( AuthenticationRequest::class );
68 }
69 $userName = 'TestProviderRevokeAccessForUser';
70
71 $provider = $this->getMockBuilder( AbstractSecondaryAuthenticationProvider::class )
72 ->onlyMethods( [ 'providerChangeAuthenticationData' ] )
73 ->getMockForAbstractClass();
74 $provider->expects( $this->once() )->method( 'getAuthenticationRequests' )
75 ->with(
76 $this->identicalTo( AuthManager::ACTION_REMOVE ),
77 $this->identicalTo( [ 'username' => $userName ] )
78 )
79 ->willReturn( $reqs );
80 $provider->expects( $this->exactly( 3 ) )->method( 'providerChangeAuthenticationData' )
81 ->willReturnCallback( function ( $req ) use ( $userName ) {
82 $this->assertSame( $userName, $req->username );
83 } );
84
85 $provider->providerRevokeAccessForUser( $userName );
86
87 foreach ( $reqs as $i => $req ) {
88 $this->assertNotNull( $req->username, "#$i" );
89 }
90 }
91 }