Merge "Hard deprecrate Language::viewPrevNext()"
[lhc/web/wiklou.git] / tests / phpunit / includes / auth / AuthenticationResponseTest.php
1 <?php
2
3 namespace MediaWiki\Auth;
4
5 /**
6 * @group AuthManager
7 * @covers \MediaWiki\Auth\AuthenticationResponse
8 */
9 class AuthenticationResponseTest extends \MediaWikiTestCase {
10 /**
11 * @dataProvider provideConstructors
12 * @param string $constructor
13 * @param array $args
14 * @param array|Exception $expect
15 */
16 public function testConstructors( $constructor, $args, $expect ) {
17 if ( is_array( $expect ) ) {
18 $res = new AuthenticationResponse();
19 $res->messageType = 'warning';
20 foreach ( $expect as $field => $value ) {
21 $res->$field = $value;
22 }
23 $ret = call_user_func_array( "MediaWiki\\Auth\\AuthenticationResponse::$constructor", $args );
24 $this->assertEquals( $res, $ret );
25 } else {
26 try {
27 call_user_func_array( "MediaWiki\\Auth\\AuthenticationResponse::$constructor", $args );
28 $this->fail( 'Expected exception not thrown' );
29 } catch ( \Exception $ex ) {
30 $this->assertEquals( $expect, $ex );
31 }
32 }
33 }
34
35 public function provideConstructors() {
36 $req = $this->getMockForAbstractClass( AuthenticationRequest::class );
37 $msg = new \Message( 'mainpage' );
38
39 return [
40 [ 'newPass', [], [
41 'status' => AuthenticationResponse::PASS,
42 ] ],
43 [ 'newPass', [ 'name' ], [
44 'status' => AuthenticationResponse::PASS,
45 'username' => 'name',
46 ] ],
47 [ 'newPass', [ 'name', null ], [
48 'status' => AuthenticationResponse::PASS,
49 'username' => 'name',
50 ] ],
51
52 [ 'newFail', [ $msg ], [
53 'status' => AuthenticationResponse::FAIL,
54 'message' => $msg,
55 'messageType' => 'error',
56 ] ],
57
58 [ 'newRestart', [ $msg ], [
59 'status' => AuthenticationResponse::RESTART,
60 'message' => $msg,
61 ] ],
62
63 [ 'newAbstain', [], [
64 'status' => AuthenticationResponse::ABSTAIN,
65 ] ],
66
67 [ 'newUI', [ [ $req ], $msg ], [
68 'status' => AuthenticationResponse::UI,
69 'neededRequests' => [ $req ],
70 'message' => $msg,
71 'messageType' => 'warning',
72 ] ],
73
74 [ 'newUI', [ [ $req ], $msg, 'warning' ], [
75 'status' => AuthenticationResponse::UI,
76 'neededRequests' => [ $req ],
77 'message' => $msg,
78 'messageType' => 'warning',
79 ] ],
80
81 [ 'newUI', [ [ $req ], $msg, 'error' ], [
82 'status' => AuthenticationResponse::UI,
83 'neededRequests' => [ $req ],
84 'message' => $msg,
85 'messageType' => 'error',
86 ] ],
87 [ 'newUI', [ [], $msg ],
88 new \InvalidArgumentException( '$reqs may not be empty' )
89 ],
90
91 [ 'newRedirect', [ [ $req ], 'http://example.org/redir' ], [
92 'status' => AuthenticationResponse::REDIRECT,
93 'neededRequests' => [ $req ],
94 'redirectTarget' => 'http://example.org/redir',
95 ] ],
96 [
97 'newRedirect',
98 [ [ $req ], 'http://example.org/redir', [ 'foo' => 'bar' ] ],
99 [
100 'status' => AuthenticationResponse::REDIRECT,
101 'neededRequests' => [ $req ],
102 'redirectTarget' => 'http://example.org/redir',
103 'redirectApiData' => [ 'foo' => 'bar' ],
104 ]
105 ],
106 [ 'newRedirect', [ [], 'http://example.org/redir' ],
107 new \InvalidArgumentException( '$reqs may not be empty' )
108 ],
109 ];
110 }
111
112 }