Merge "WebRequest: Change getFullRequestURL() to use local getProtocol()"
[lhc/web/wiklou.git] / tests / phpunit / includes / auth / ButtonAuthenticationRequestTest.php
1 <?php
2
3 namespace MediaWiki\Auth;
4
5 /**
6 * @group AuthManager
7 * @covers \MediaWiki\Auth\ButtonAuthenticationRequest
8 */
9 class ButtonAuthenticationRequestTest extends AuthenticationRequestTestCase {
10
11 protected function getInstance( array $args = [] ) {
12 $data = array_intersect_key( $args, [ 'name' => 1, 'label' => 1, 'help' => 1 ] );
13 return ButtonAuthenticationRequest::__set_state( $data );
14 }
15
16 public static function provideGetFieldInfo() {
17 return [
18 [ [ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz' ] ]
19 ];
20 }
21
22 public function provideLoadFromSubmission() {
23 return [
24 'Empty request' => [
25 [ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz' ],
26 [],
27 false
28 ],
29 'Button present' => [
30 [ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz' ],
31 [ 'foo' => 'Foobar' ],
32 [ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz', 'foo' => true ]
33 ],
34 ];
35 }
36
37 public function testGetUniqueId() {
38 $req = new ButtonAuthenticationRequest( 'foo', wfMessage( 'bar' ), wfMessage( 'baz' ) );
39 $this->assertSame(
40 'MediaWiki\\Auth\\ButtonAuthenticationRequest:foo', $req->getUniqueId()
41 );
42 }
43
44 public function testGetRequestByName() {
45 $reqs = [];
46 $reqs['testOne'] = new ButtonAuthenticationRequest(
47 'foo', wfMessage( 'msg' ), wfMessage( 'help' )
48 );
49 $reqs[] = new ButtonAuthenticationRequest( 'bar', wfMessage( 'msg1' ), wfMessage( 'help1' ) );
50 $reqs[] = new ButtonAuthenticationRequest( 'bar', wfMessage( 'msg2' ), wfMessage( 'help2' ) );
51 $reqs['testSub'] = $this->getMockBuilder( ButtonAuthenticationRequest::class )
52 ->setConstructorArgs( [ 'subclass', wfMessage( 'msg3' ), wfMessage( 'help3' ) ] )
53 ->getMock();
54
55 $this->assertNull( ButtonAuthenticationRequest::getRequestByName( $reqs, 'missing' ) );
56 $this->assertSame(
57 $reqs['testOne'], ButtonAuthenticationRequest::getRequestByName( $reqs, 'foo' )
58 );
59 $this->assertNull( ButtonAuthenticationRequest::getRequestByName( $reqs, 'bar' ) );
60 $this->assertSame(
61 $reqs['testSub'], ButtonAuthenticationRequest::getRequestByName( $reqs, 'subclass' )
62 );
63 }
64 }