3 namespace MediaWiki\Auth
;
8 abstract class AuthenticationRequestTestCase
extends \MediaWikiTestCase
{
9 protected function setUp() {
10 global $wgDisableAuthManager;
13 if ( $wgDisableAuthManager ) {
14 $this->markTestSkipped( '$wgDisableAuthManager is set' );
18 abstract protected function getInstance( array $args = [] );
21 * @dataProvider provideGetFieldInfo
23 public function testGetFieldInfo( array $args ) {
24 $info = $this->getInstance( $args )->getFieldInfo();
25 $this->assertType( 'array', $info );
27 foreach ( $info as $field => $data ) {
28 $this->assertType( 'array', $data, "Field $field" );
29 $this->assertArrayHasKey( 'type', $data, "Field $field" );
30 $this->assertArrayHasKey( 'label', $data, "Field $field" );
31 $this->assertInstanceOf( 'Message', $data['label'], "Field $field, label" );
33 if ( $data['type'] !== 'null' ) {
34 $this->assertArrayHasKey( 'help', $data, "Field $field" );
35 $this->assertInstanceOf( 'Message', $data['help'], "Field $field, help" );
38 if ( isset( $data['optional'] ) ) {
39 $this->assertType( 'bool', $data['optional'], "Field $field, optional" );
41 if ( isset( $data['image'] ) ) {
42 $this->assertType( 'string', $data['image'], "Field $field, image" );
45 switch ( $data['type'] ) {
52 $this->assertArrayHasKey( 'options', $data, "Field $field" );
53 $this->assertType( 'array', $data['options'], "Field $field, options" );
54 foreach ( $data['options'] as $val => $msg ) {
55 $this->assertInstanceOf( 'Message', $msg, "Field $field, option $val" );
65 $this->fail( "Field $field, unknown type " . $data['type'] );
71 public static function provideGetFieldInfo() {
78 * @dataProvider provideLoadFromSubmission
81 * @param array|bool $expectState
83 public function testLoadFromSubmission( array $args, array $data, $expectState ) {
84 $instance = $this->getInstance( $args );
85 $ret = $instance->loadFromSubmission( $data );
86 if ( is_array( $expectState ) ) {
87 $this->assertTrue( $ret );
88 $expect = call_user_func( [ get_class( $instance ), '__set_state' ], $expectState );
89 $this->assertEquals( $expect, $instance );
91 $this->assertFalse( $ret );
95 abstract public function provideLoadFromSubmission();