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