wiki.techinc.nl/tests/phpunit/includes/auth/ButtonAuthenticationRequestTest.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

63 lines
2 KiB
PHP

<?php
namespace MediaWiki\Auth;
/**
* @group AuthManager
* @covers \MediaWiki\Auth\ButtonAuthenticationRequest
*/
class ButtonAuthenticationRequestTest extends AuthenticationRequestTestCase {
protected function getInstance( array $args = [] ) {
$data = array_intersect_key( $args, [ 'name' => 1, 'label' => 1, 'help' => 1 ] );
return ButtonAuthenticationRequest::__set_state( $data );
}
public static function provideGetFieldInfo() {
return [
[ [ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz' ] ]
];
}
public static function provideLoadFromSubmission() {
return [
'Empty request' => [
[ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz' ],
[],
false
],
'Button present' => [
[ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz' ],
[ 'foo' => 'Foobar' ],
[ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz', 'foo' => true ]
],
];
}
public function testGetUniqueId() {
$req = new ButtonAuthenticationRequest( 'foo', wfMessage( 'bar' ), wfMessage( 'baz' ) );
$this->assertSame(
'MediaWiki\\Auth\\ButtonAuthenticationRequest:foo', $req->getUniqueId()
);
}
public function testGetRequestByName() {
$reqs = [];
$reqs['testOne'] = new ButtonAuthenticationRequest(
'foo', wfMessage( 'msg' ), wfMessage( 'help' )
);
$reqs[] = new ButtonAuthenticationRequest( 'bar', wfMessage( 'msg1' ), wfMessage( 'help1' ) );
$reqs[] = new ButtonAuthenticationRequest( 'bar', wfMessage( 'msg2' ), wfMessage( 'help2' ) );
$reqs['testSub'] =
new ButtonAuthenticationRequest( 'subclass', wfMessage( 'msg3' ), wfMessage( 'help3' ) );
$this->assertNull( ButtonAuthenticationRequest::getRequestByName( $reqs, 'missing' ) );
$this->assertSame(
$reqs['testOne'], ButtonAuthenticationRequest::getRequestByName( $reqs, 'foo' )
);
$this->assertNull( ButtonAuthenticationRequest::getRequestByName( $reqs, 'bar' ) );
$this->assertSame(
$reqs['testSub'], ButtonAuthenticationRequest::getRequestByName( $reqs, 'subclass' )
);
}
}