Move ResultWrapper subclasses to Rdbms
[mediawiki.git] / tests / phpunit / includes / auth / AuthenticationResponseTest.php
blob194b49e01acf7addc6d7cc3d4e76b3d4002ffcc9
1 <?php
3 namespace MediaWiki\Auth;
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
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;
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 );
35 public function provideConstructors() {
36 $req = $this->getMockForAbstractClass( AuthenticationRequest::class );
37 $msg = new \Message( 'mainpage' );
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 ] ],
52 [ 'newFail', [ $msg ], [
53 'status' => AuthenticationResponse::FAIL,
54 'message' => $msg,
55 'messageType' => 'error',
56 ] ],
58 [ 'newRestart', [ $msg ], [
59 'status' => AuthenticationResponse::RESTART,
60 'message' => $msg,
61 ] ],
63 [ 'newAbstain', [], [
64 'status' => AuthenticationResponse::ABSTAIN,
65 ] ],
67 [ 'newUI', [ [ $req ], $msg ], [
68 'status' => AuthenticationResponse::UI,
69 'neededRequests' => [ $req ],
70 'message' => $msg,
71 'messageType' => 'warning',
72 ] ],
74 [ 'newUI', [ [ $req ], $msg, 'warning' ], [
75 'status' => AuthenticationResponse::UI,
76 'neededRequests' => [ $req ],
77 'message' => $msg,
78 'messageType' => 'warning',
79 ] ],
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' )
91 [ 'newRedirect', [ [ $req ], 'http://example.org/redir' ], [
92 'status' => AuthenticationResponse::REDIRECT,
93 'neededRequests' => [ $req ],
94 'redirectTarget' => 'http://example.org/redir',
95 ] ],
97 'newRedirect',
98 [ [ $req ], 'http://example.org/redir', [ 'foo' => 'bar' ] ],
100 'status' => AuthenticationResponse::REDIRECT,
101 'neededRequests' => [ $req ],
102 'redirectTarget' => 'http://example.org/redir',
103 'redirectApiData' => [ 'foo' => 'bar' ],
106 [ 'newRedirect', [ [], 'http://example.org/redir' ],
107 new \InvalidArgumentException( '$reqs may not be empty' )