Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / auth / AuthenticationRequestTestCase.php
blobb5c8a36cd1d7406e220f3f1f94874be58088f363
1 <?php
3 namespace MediaWiki\Auth;
5 /**
6 * @group AuthManager
7 */
8 abstract class AuthenticationRequestTestCase extends \MediaWikiTestCase {
9 abstract protected function getInstance( array $args = [] );
11 /**
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'] ) {
44 case 'string':
45 case 'password':
46 case 'hidden':
47 break;
48 case 'select':
49 case 'multiselect':
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" );
55 break;
56 case 'checkbox':
57 break;
58 case 'button':
59 break;
60 case 'null':
61 break;
62 default:
63 $this->fail( "Field $field, unknown type " . $data['type'] );
64 break;
69 public static function provideGetFieldInfo() {
70 return [
71 [ [] ]
75 /**
76 * @dataProvider provideLoadFromSubmission
77 * @param array $args
78 * @param array $data
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 );
88 } else {
89 $this->assertFalse( $ret );
93 abstract public function provideLoadFromSubmission();