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 foreach ( $expect as $field => $value ) {
20 $res->$field = $value;
22 $ret = call_user_func_array( "MediaWiki\\Auth\\AuthenticationResponse::$constructor", $args );
23 $this->assertEquals( $res, $ret );
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 );
34 public function provideConstructors() {
35 $req = $this->getMockForAbstractClass( AuthenticationRequest
::class );
36 $msg = new \
Message( 'mainpage' );
40 'status' => AuthenticationResponse
::PASS
,
42 [ 'newPass', [ 'name' ], [
43 'status' => AuthenticationResponse
::PASS
,
46 [ 'newPass', [ 'name', null ], [
47 'status' => AuthenticationResponse
::PASS
,
51 [ 'newFail', [ $msg ], [
52 'status' => AuthenticationResponse
::FAIL
,
56 [ 'newRestart', [ $msg ], [
57 'status' => AuthenticationResponse
::RESTART
,
62 'status' => AuthenticationResponse
::ABSTAIN
,
65 [ 'newUI', [ [ $req ], $msg ], [
66 'status' => AuthenticationResponse
::UI
,
67 'neededRequests' => [ $req ],
70 [ 'newUI', [ [], $msg ],
71 new \
InvalidArgumentException( '$reqs may not be empty' )
74 [ 'newRedirect', [ [ $req ], 'http://example.org/redir' ], [
75 'status' => AuthenticationResponse
::REDIRECT
,
76 'neededRequests' => [ $req ],
77 'redirectTarget' => 'http://example.org/redir',
81 [ [ $req ], 'http://example.org/redir', [ 'foo' => 'bar' ] ],
83 'status' => AuthenticationResponse
::REDIRECT
,
84 'neededRequests' => [ $req ],
85 'redirectTarget' => 'http://example.org/redir',
86 'redirectApiData' => [ 'foo' => 'bar' ],
89 [ 'newRedirect', [ [], 'http://example.org/redir' ],
90 new \
InvalidArgumentException( '$reqs may not be empty' )