1<?php 2 3namespace MediaWiki\Auth; 4 5/** 6 * @group AuthManager 7 * @covers \MediaWiki\Auth\ButtonAuthenticationRequest 8 */ 9class 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'] = 52 new ButtonAuthenticationRequest( 'subclass', wfMessage( 'msg3' ), wfMessage( 'help3' ) ); 53 54 $this->assertNull( ButtonAuthenticationRequest::getRequestByName( $reqs, 'missing' ) ); 55 $this->assertSame( 56 $reqs['testOne'], ButtonAuthenticationRequest::getRequestByName( $reqs, 'foo' ) 57 ); 58 $this->assertNull( ButtonAuthenticationRequest::getRequestByName( $reqs, 'bar' ) ); 59 $this->assertSame( 60 $reqs['testSub'], ButtonAuthenticationRequest::getRequestByName( $reqs, 'subclass' ) 61 ); 62 } 63} 64