wiki.techinc.nl/tests/phpunit/includes/auth/ConfirmLinkAuthenticationRequestTest.php
mainframe98 7299aed7a5 tests: Allow overridable data providers to be static
This uses some reflection to identify if the data provider is static or
not. If it isn't, a deprecation notice is emitted. This doesn't fail the
tests, but is still printed in the output.

To facilitate this, the relevant abstract method has been uncommented,
as PHP does not like it when function signatures do not match up.

This approach means that tests in extensions or skins do not immediately
break when making data providers static. Instead, they can do so at
their own pace.

Bug: T332865
Change-Id: I5ff35ad0e894f0a27beae00257dc1fc599ad518d
2023-05-16 16:28:43 +01: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 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()
);
}
}