wiki.techinc.nl/tests/phpunit/includes/auth/ButtonAuthenticationRequestTest.php
Brad Jorsch d245bd25ae Add AuthManager
This implements the AuthManager class and its needed interfaces and
subclasses, and integrates them into the backend portion of MediaWiki.
Integration with frontend portions of MediaWiki (e.g. ApiLogin,
Special:Login) is left for a followup.

Bug: T91699
Bug: T71589
Bug: T111299
Co-Authored-By: Gergő Tisza <gtisza@wikimedia.org>
Change-Id: If89d24838e326fe25fe867d02181eebcfbb0e196
2016-05-16 15:11:02 +00:00

64 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 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'] = $this->getMockBuilder( ButtonAuthenticationRequest::class )
->setConstructorArgs( [ 'subclass', wfMessage( 'msg3' ), wfMessage( 'help3' ) ] )
->getMock();
$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' )
);
}
}