Merge "Introduce {{#time: xit}} for days in the month in Iranian calendar"
[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 foreach ( $expect as $field => $value ) {
20 $res->$field = $value;
21 }
22 $ret = call_user_func_array( "MediaWiki\\Auth\\AuthenticationResponse::$constructor", $args );
23 $this->assertEquals( $res, $ret );
24 } else {
25 try {
26 call_user_func_array( "MediaWiki\\Auth\\AuthenticationResponse::$constructor", $args );
27 $this->fail( 'Expected exception not thrown' );
28 } catch ( \Exception $ex ) {
29 $this->assertEquals( $expect, $ex );
30 }
31 }
32 }
33
34 public function provideConstructors() {
35 $req = $this->getMockForAbstractClass( AuthenticationRequest::class );
36 $msg = new \Message( 'mainpage' );
37
38 return [
39 [ 'newPass', [], [
40 'status' => AuthenticationResponse::PASS,
41 ] ],
42 [ 'newPass', [ 'name' ], [
43 'status' => AuthenticationResponse::PASS,
44 'username' => 'name',
45 ] ],
46 [ 'newPass', [ 'name', null ], [
47 'status' => AuthenticationResponse::PASS,
48 'username' => 'name',
49 ] ],
50
51 [ 'newFail', [ $msg ], [
52 'status' => AuthenticationResponse::FAIL,
53 'message' => $msg,
54 ] ],
55
56 [ 'newRestart', [ $msg ], [
57 'status' => AuthenticationResponse::RESTART,
58 'message' => $msg,
59 ] ],
60
61 [ 'newAbstain', [], [
62 'status' => AuthenticationResponse::ABSTAIN,
63 ] ],
64
65 [ 'newUI', [ [ $req ], $msg ], [
66 'status' => AuthenticationResponse::UI,
67 'neededRequests' => [ $req ],
68 'message' => $msg,
69 ] ],
70 [ 'newUI', [ [], $msg ],
71 new \InvalidArgumentException( '$reqs may not be empty' )
72 ],
73
74 [ 'newRedirect', [ [ $req ], 'http://example.org/redir' ], [
75 'status' => AuthenticationResponse::REDIRECT,
76 'neededRequests' => [ $req ],
77 'redirectTarget' => 'http://example.org/redir',
78 ] ],
79 [
80 'newRedirect',
81 [ [ $req ], 'http://example.org/redir', [ 'foo' => 'bar' ] ],
82 [
83 'status' => AuthenticationResponse::REDIRECT,
84 'neededRequests' => [ $req ],
85 'redirectTarget' => 'http://example.org/redir',
86 'redirectApiData' => [ 'foo' => 'bar' ],
87 ]
88 ],
89 [ 'newRedirect', [ [], 'http://example.org/redir' ],
90 new \InvalidArgumentException( '$reqs may not be empty' )
91 ],
92 ];
93 }
94
95 }