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