Skip to content

Commit

Permalink
test: Add test case for number/float field type.
Browse files Browse the repository at this point in the history
  • Loading branch information
mindctrl committed Feb 24, 2021
1 parent fe8f030 commit 3ea1a35
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ function map_html_field_type_to_graphql_field_type( string $field_type ): ?strin
case 'textarea':
case 'string':
case 'date':
case 'media': // ?
case 'media':
return 'String';
case 'number':
return 'Int';
return 'Float';
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
'show_in_rest' => false,
'show_in_graphql' => false,
),
'dog-weight' => array(
'type' => 'number',
'description' => 'dog-weight description',
'show_in_rest' => true,
'show_in_graphql' => true,
),
),
),
'cat' =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function setUp() {
] );

update_post_meta( $this->dog_post_id, 'dog-test-field', 'dog-test-field string value' );
update_post_meta( $this->dog_post_id, 'dog-weight', '100.25' );
}

public function tearDown() {
Expand All @@ -79,6 +80,9 @@ public function test_post_meta_that_is_configured_to_show_in_rest_is_accessible(
$response_data = $response->get_data();
$this->assertArrayHasKey( 'dog-test-field', $response_data['meta'] );
$this->assertSame( $response_data['meta']['dog-test-field'][0], 'dog-test-field string value' );

self::assertArrayHasKey( 'dog-weight', $response_data['meta'] );
self::assertEquals( '100.25', $response_data['meta']['dog-weight'][0] );
}

public function test_post_meta_that_is_configured_to_not_show_in_rest_is_not_accessible(): void {
Expand Down Expand Up @@ -126,15 +130,19 @@ public function test_graphql_query_result_has_custom_fields_data(): void {
title
content
dogTestField
dogWeight
}
}
}
'
] );

self::assertTrue( true, array_key_exists( 'dogTestField', $results['data']['dogs']['nodes'][0] ) );
self::assertArrayHasKey( 'dogTestField', $results['data']['dogs']['nodes'][0] );
self::assertSame( $results['data']['dogs']['nodes'][0]['dogTestField'], 'dog-test-field string value' );

self::assertArrayHasKey( 'dogWeight', $results['data']['dogs']['nodes'][0] );
self::assertSame( $results['data']['dogs']['nodes'][0]['dogWeight'], 100.25 );

} catch ( Exception $exception ) {
throw new PHPUnitRunnerException( sprintf( __FUNCTION__ . ' failed with exception: %s', $exception->getMessage() ) );
}
Expand Down

0 comments on commit 3ea1a35

Please sign in to comment.