3 namespace MediaWiki\Auth
;
7 * @covers MediaWiki\Auth\AuthenticationResponse
9 class AuthenticationResponseTest
extends \MediaWikiTestCase
{
11 * @dataProvider provideConstructors
12 * @param string $constructor
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 );
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' );
41 'status' => AuthenticationResponse
::PASS
,
43 [ 'newPass', [ 'name' ], [
44 'status' => AuthenticationResponse
::PASS
,
47 [ 'newPass', [ 'name', null ], [
48 'status' => AuthenticationResponse
::PASS
,
52 [ 'newFail', [ $msg ], [
53 'status' => AuthenticationResponse
::FAIL
,
55 'messageType' => 'error',
58 [ 'newRestart', [ $msg ], [
59 'status' => AuthenticationResponse
::RESTART
,
64 'status' => AuthenticationResponse
::ABSTAIN
,
67 [ 'newUI', [ [ $req ], $msg ], [
68 'status' => AuthenticationResponse
::UI
,
69 'neededRequests' => [ $req ],
71 'messageType' => 'warning',
74 [ 'newUI', [ [ $req ], $msg, 'warning' ], [
75 'status' => AuthenticationResponse
::UI
,
76 'neededRequests' => [ $req ],
78 'messageType' => 'warning',
81 [ 'newUI', [ [ $req ], $msg, 'error' ], [
82 'status' => AuthenticationResponse
::UI
,
83 'neededRequests' => [ $req ],
85 'messageType' => 'error',
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',
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' )