3 namespace MediaWiki\Auth
;
8 abstract class AuthenticationRequestTestCase
extends \MediaWikiTestCase
{
9 abstract protected function getInstance( array $args = [] );
12 * @dataProvider provideGetFieldInfo
14 public function testGetFieldInfo( array $args ) {
15 $info = $this->getInstance( $args )->getFieldInfo();
16 $this->assertType( 'array', $info );
18 foreach ( $info as $field => $data ) {
19 $this->assertType( 'array', $data, "Field $field" );
20 $this->assertArrayHasKey( 'type', $data, "Field $field" );
21 $this->assertArrayHasKey( 'label', $data, "Field $field" );
22 $this->assertInstanceOf( 'Message', $data['label'], "Field $field, label" );
24 if ( $data['type'] !== 'null' ) {
25 $this->assertArrayHasKey( 'help', $data, "Field $field" );
26 $this->assertInstanceOf( 'Message', $data['help'], "Field $field, help" );
29 if ( isset( $data['optional'] ) ) {
30 $this->assertType( 'bool', $data['optional'], "Field $field, optional" );
32 if ( isset( $data['image'] ) ) {
33 $this->assertType( 'string', $data['image'], "Field $field, image" );
35 if ( isset( $data['sensitive'] ) ) {
36 $this->assertType( 'bool', $data['sensitive'], "Field $field, sensitive" );
38 if ( $data['type'] === 'password' ) {
39 $this->assertTrue( !empty( $data['sensitive'] ),
40 "Field $field, password field must be sensitive" );
43 switch ( $data['type'] ) {
50 $this->assertArrayHasKey( 'options', $data, "Field $field" );
51 $this->assertType( 'array', $data['options'], "Field $field, options" );
52 foreach ( $data['options'] as $val => $msg ) {
53 $this->assertInstanceOf( 'Message', $msg, "Field $field, option $val" );
63 $this->fail( "Field $field, unknown type " . $data['type'] );
69 public static function provideGetFieldInfo() {
76 * @dataProvider provideLoadFromSubmission
79 * @param array|bool $expectState
81 public function testLoadFromSubmission( array $args, array $data, $expectState ) {
82 $instance = $this->getInstance( $args );
83 $ret = $instance->loadFromSubmission( $data );
84 if ( is_array( $expectState ) ) {
85 $this->assertTrue( $ret );
86 $expect = call_user_func( [ get_class( $instance ), '__set_state' ], $expectState );
87 $this->assertEquals( $expect, $instance );
89 $this->assertFalse( $ret );
93 abstract public function provideLoadFromSubmission();