Merge "mw.ForeignStructuredUpload.BookletLayout: Make licensing links clickable again"
[lhc/web/wiklou.git] / tests / phpunit / includes / auth / AbstractSecondaryAuthenticationProviderTest.php
1 <?php
2
3 namespace MediaWiki\Auth;
4
5 /**
6 * @group AuthManager
7 * @covers MediaWiki\Auth\AbstractSecondaryAuthenticationProvider
8 */
9 class AbstractSecondaryAuthenticationProviderTest extends \MediaWikiTestCase {
10 protected function setUp() {
11 global $wgDisableAuthManager;
12
13 parent::setUp();
14 if ( $wgDisableAuthManager ) {
15 $this->markTestSkipped( '$wgDisableAuthManager is set' );
16 }
17 }
18
19 public function testAbstractSecondaryAuthenticationProvider() {
20 $user = \User::newFromName( 'UTSysop' );
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->getMock( AuthenticationRequest::class );
68 $reqs[$i]->done = false;
69 }
70
71 $provider = $this->getMockBuilder( AbstractSecondaryAuthenticationProvider::class )
72 ->setMethods( [ 'providerChangeAuthenticationData' ] )
73 ->getMockForAbstractClass();
74 $provider->expects( $this->once() )->method( 'getAuthenticationRequests' )
75 ->with(
76 $this->identicalTo( AuthManager::ACTION_REMOVE ),
77 $this->identicalTo( [ 'username' => 'UTSysop' ] )
78 )
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 );
84 $req->done = true;
85 } ) );
86
87 $provider->providerRevokeAccessForUser( 'UTSysop' );
88
89 foreach ( $reqs as $i => $req ) {
90 $this->assertTrue( $req->done, "#$i" );
91 }
92 }
93 }