wiki.techinc.nl/tests/phpunit/includes/auth/ConfirmLinkAuthenticationRequestTest.php
Umherirrender d36073cdcf tests: Make some PHPUnit data providers static
Initally used a new sniff with autofix (T333745),
but some provide are defined non-static in TestBase class
and need more work to make them static in a compatible way

Bug: T332865
Change-Id: I889d33424f0c01fb26f2d86f8d4fc3de3e568843
2023-05-20 01:05:27 +02:00

77 lines
1.7 KiB
PHP

<?php
namespace MediaWiki\Auth;
use InvalidArgumentException;
/**
* @group AuthManager
* @covers \MediaWiki\Auth\ConfirmLinkAuthenticationRequest
*/
class ConfirmLinkAuthenticationRequestTest extends AuthenticationRequestTestCase {
protected function getInstance( array $args = [] ) {
return new ConfirmLinkAuthenticationRequest( self::getLinkRequests() );
}
public function testConstructorException() {
$this->expectException( InvalidArgumentException::class );
$this->expectExceptionMessage( '$linkRequests must not be empty' );
new ConfirmLinkAuthenticationRequest( [] );
}
/**
* Get requests for testing
* @return AuthenticationRequest[]
*/
private static function getLinkRequests() {
$reqs = [];
for ( $i = 1; $i <= 3; $i++ ) {
$req = new class( "Request$i" ) extends AuthenticationRequest {
private $uniqueId;
public function __construct( $uniqueId ) {
$this->uniqueId = $uniqueId;
}
public function getFieldInfo() {
return [];
}
public function getUniqueId() {
return $this->uniqueId;
}
};
$reqs[$req->getUniqueId()] = $req;
}
return $reqs;
}
public static function provideLoadFromSubmission() {
$reqs = self::getLinkRequests();
return [
'Empty request' => [
[],
[],
[ 'linkRequests' => $reqs ],
],
'Some confirmed' => [
[],
[ 'confirmedLinkIDs' => [ 'Request1', 'Request3' ] ],
[ 'confirmedLinkIDs' => [ 'Request1', 'Request3' ], 'linkRequests' => $reqs ],
],
];
}
public function testGetUniqueId() {
$req = new ConfirmLinkAuthenticationRequest( self::getLinkRequests() );
$this->assertSame(
get_class( $req ) . ':Request1|Request2|Request3',
$req->getUniqueId()
);
}
}