MediaWiki REL1_32
AuthenticationRequestTestCase.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Auth;
4
9 abstract protected function getInstance( array $args = [] );
10
14 public function testGetFieldInfo( array $args ) {
15 $info = $this->getInstance( $args )->getFieldInfo();
16 $this->assertType( 'array', $info );
17
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::class, $data['label'], "Field $field, label" );
23
24 if ( $data['type'] !== 'null' ) {
25 $this->assertArrayHasKey( 'help', $data, "Field $field" );
26 $this->assertInstanceOf( \Message::class, $data['help'], "Field $field, help" );
27 }
28
29 if ( isset( $data['optional'] ) ) {
30 $this->assertType( 'bool', $data['optional'], "Field $field, optional" );
31 }
32 if ( isset( $data['image'] ) ) {
33 $this->assertType( 'string', $data['image'], "Field $field, image" );
34 }
35 if ( isset( $data['sensitive'] ) ) {
36 $this->assertType( 'bool', $data['sensitive'], "Field $field, sensitive" );
37 }
38 if ( $data['type'] === 'password' ) {
39 $this->assertTrue( !empty( $data['sensitive'] ),
40 "Field $field, password field must be sensitive" );
41 }
42
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::class, $msg, "Field $field, option $val" );
54 }
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;
65 }
66 }
67 }
68
69 public static function provideGetFieldInfo() {
70 return [
71 [ [] ]
72 ];
73 }
74
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 );
90 }
91 }
92
93 abstract public function provideLoadFromSubmission();
94}
if( $line===false) $args
Definition cdb.php:64
assertType( $type, $actual, $message='')
Asserts the type of the provided value.
testLoadFromSubmission(array $args, array $data, $expectState)
provideLoadFromSubmission
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition hooks.txt:2054
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))