15 $info = $this->
getInstance( $args )->getFieldInfo();
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" );
24 if ( $data[
'type'] !==
'null' ) {
25 $this->assertArrayHasKey(
'help', $data,
"Field $field" );
26 $this->assertInstanceOf( \Message::class, $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::class, $msg,
"Field $field, option $val" );
63 $this->fail(
"Field $field, unknown type " . $data[
'type'] );
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 );