Debian Codegraph @

tests/phpunit/includes/auth/ButtonAuthenticationRequestTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Auth;
4
5 use MediaWiki\Auth\ButtonAuthenticationRequest;
6
7 /**
8 * @group AuthManager
9 * @covers \MediaWiki\Auth\ButtonAuthenticationRequest
10 */
11 class ButtonAuthenticationRequestTest extends AuthenticationRequestTestCase {
12
13 protected function getInstance( array $args = [] ) {
14 $data = array_intersect_key( $args, [ 'name' => 1, 'label' => 1, 'help' => 1 ] );
15 if ( $args['name'] === 'foo' ) {
16 return ButtonAuthenticationRequestForLoadFromSubmission::__set_state( $data );
17 }
18 return ButtonAuthenticationRequest::__set_state( $data );
19 }
20
21 public static function provideGetFieldInfo() {
22 return [
23 [ [ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz' ] ]
24 ];
25 }
26
27 public static function provideLoadFromSubmission() {
28 return [
29 'Empty request' => [
30 [ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz' ],
31 [],
32 false
33 ],
34 'Button present' => [
35 [ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz' ],
36 [ 'foo' => 'Foobar' ],
37 [ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz', 'foo' => true ]
38 ],
39 ];
40 }
41
42 public function testGetUniqueId() {
43 $req = new ButtonAuthenticationRequest( 'foo', wfMessage( 'bar' ), wfMessage( 'baz' ) );
44 $this->assertSame(
45 'MediaWiki\\Auth\\ButtonAuthenticationRequest:foo', $req->getUniqueId()
46 );
47 }
48
49 public function testGetRequestByName() {
50 $reqs = [];
51 $reqs['testOne'] = new ButtonAuthenticationRequest(
52 'foo', wfMessage( 'msg' ), wfMessage( 'help' )
53 );
54 $reqs[] = new ButtonAuthenticationRequest( 'bar', wfMessage( 'msg1' ), wfMessage( 'help1' ) );
55 $reqs[] = new ButtonAuthenticationRequest( 'bar', wfMessage( 'msg2' ), wfMessage( 'help2' ) );
56 $reqs['testSub'] =
57 new ButtonAuthenticationRequest( 'subclass', wfMessage( 'msg3' ), wfMessage( 'help3' ) );
58
59 $this->assertNull( ButtonAuthenticationRequest::getRequestByName( $reqs, 'missing' ) );
60 $this->assertSame(
61 $reqs['testOne'], ButtonAuthenticationRequest::getRequestByName( $reqs, 'foo' )
62 );
63 $this->assertNull( ButtonAuthenticationRequest::getRequestByName( $reqs, 'bar' ) );
64 $this->assertSame(
65 $reqs['testSub'], ButtonAuthenticationRequest::getRequestByName( $reqs, 'subclass' )
66 );
67 }
68 }
69
70 // Dynamic properties from the testLoadFromSubmission not working in php8.2
71 class ButtonAuthenticationRequestForLoadFromSubmission extends ButtonAuthenticationRequest {
72 /** @var string */
73 public $foo;
74 }