]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - tests/phpunit/includes/auth/ConfirmLinkAuthenticationRequestTest.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / tests / phpunit / includes / auth / ConfirmLinkAuthenticationRequestTest.php
1 <?php
2
3 namespace MediaWiki\Auth;
4
5 use InvalidArgumentException;
6
7 /**
8  * @group AuthManager
9  * @covers MediaWiki\Auth\ConfirmLinkAuthenticationRequest
10  */
11 class ConfirmLinkAuthenticationRequestTest extends AuthenticationRequestTestCase {
12
13         protected function getInstance( array $args = [] ) {
14                 return new ConfirmLinkAuthenticationRequest( $this->getLinkRequests() );
15         }
16
17         /**
18          * @expectedException InvalidArgumentException
19          * @expectedExceptionMessage $linkRequests must not be empty
20          */
21         public function testConstructorException() {
22                 new ConfirmLinkAuthenticationRequest( [] );
23         }
24
25         /**
26          * Get requests for testing
27          * @return AuthenticationRequest[]
28          */
29         private function getLinkRequests() {
30                 $reqs = [];
31
32                 $mb = $this->getMockBuilder( AuthenticationRequest::class )
33                         ->setMethods( [ 'getUniqueId' ] );
34                 for ( $i = 1; $i <= 3; $i++ ) {
35                         $req = $mb->getMockForAbstractClass();
36                         $req->expects( $this->any() )->method( 'getUniqueId' )
37                                 ->will( $this->returnValue( "Request$i" ) );
38                         $reqs[$req->getUniqueId()] = $req;
39                 }
40
41                 return $reqs;
42         }
43
44         public function provideLoadFromSubmission() {
45                 $reqs = $this->getLinkRequests();
46
47                 return [
48                         'Empty request' => [
49                                 [],
50                                 [],
51                                 [ 'linkRequests' => $reqs ],
52                         ],
53                         'Some confirmed' => [
54                                 [],
55                                 [ 'confirmedLinkIDs' => [ 'Request1', 'Request3' ] ],
56                                 [ 'confirmedLinkIDs' => [ 'Request1', 'Request3' ], 'linkRequests' => $reqs ],
57                         ],
58                 ];
59         }
60
61         public function testGetUniqueId() {
62                 $req = new ConfirmLinkAuthenticationRequest( $this->getLinkRequests() );
63                 $this->assertSame(
64                         get_class( $req ) . ':Request1|Request2|Request3',
65                         $req->getUniqueId()
66                 );
67         }
68 }