3 namespace MediaWiki\Auth
;
7 * @covers MediaWiki\Auth\AuthenticationResponse
9 class AuthenticationResponseTest
extends \MediaWikiTestCase
{
10 protected function setUp() {
11 global $wgDisableAuthManager;
14 if ( $wgDisableAuthManager ) {
15 $this->markTestSkipped( '$wgDisableAuthManager is set' );
20 * @dataProvider provideConstructors
21 * @param string $constructor
23 * @param array|Exception $expect
25 public function testConstructors( $constructor, $args, $expect ) {
26 if ( is_array( $expect ) ) {
27 $res = new AuthenticationResponse();
28 foreach ( $expect as $field => $value ) {
29 $res->$field = $value;
31 $ret = call_user_func_array( "MediaWiki\\Auth\\AuthenticationResponse::$constructor", $args );
32 $this->assertEquals( $res, $ret );
35 call_user_func_array( "MediaWiki\\Auth\\AuthenticationResponse::$constructor", $args );
36 $this->fail( 'Expected exception not thrown' );
37 } catch ( \Exception
$ex ) {
38 $this->assertEquals( $expect, $ex );
43 public function provideConstructors() {
44 $req = $this->getMockForAbstractClass( AuthenticationRequest
::class );
45 $msg = new \
Message( 'mainpage' );
49 'status' => AuthenticationResponse
::PASS
,
51 [ 'newPass', [ 'name' ], [
52 'status' => AuthenticationResponse
::PASS
,
55 [ 'newPass', [ 'name', null ], [
56 'status' => AuthenticationResponse
::PASS
,
60 [ 'newFail', [ $msg ], [
61 'status' => AuthenticationResponse
::FAIL
,
65 [ 'newRestart', [ $msg ], [
66 'status' => AuthenticationResponse
::RESTART
,
71 'status' => AuthenticationResponse
::ABSTAIN
,
74 [ 'newUI', [ [ $req ], $msg ], [
75 'status' => AuthenticationResponse
::UI
,
76 'neededRequests' => [ $req ],
79 [ 'newUI', [ [], $msg ],
80 new \
InvalidArgumentException( '$reqs may not be empty' )
83 [ 'newRedirect', [ [ $req ], 'http://example.org/redir' ], [
84 'status' => AuthenticationResponse
::REDIRECT
,
85 'neededRequests' => [ $req ],
86 'redirectTarget' => 'http://example.org/redir',
90 [ [ $req ], 'http://example.org/redir', [ 'foo' => 'bar' ] ],
92 'status' => AuthenticationResponse
::REDIRECT
,
93 'neededRequests' => [ $req ],
94 'redirectTarget' => 'http://example.org/redir',
95 'redirectApiData' => [ 'foo' => 'bar' ],
98 [ 'newRedirect', [ [], 'http://example.org/redir' ],
99 new \
InvalidArgumentException( '$reqs may not be empty' )