mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-03-31 18:54:29 +00:00
REST API: Issue warning if array meta is registered without item schema.
The purpose of meta registration is to assert that the meta key will contain a predictable value conforming to a schema, so the schema is therefore considered to be required. Props TimothyBlynJacobs, grapplerulrich. Fixes #43392. git-svn-id: https://develop.svn.wordpress.org/trunk@46186 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2204,6 +2204,66 @@ class WP_Test_REST_Post_Meta_Fields extends WP_Test_REST_TestCase {
|
||||
$this->assertEquals( array( 'project' => 'WordCamp' ), $data['meta']['object'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 43392
|
||||
*/
|
||||
public function test_register_meta_issues_doing_it_wrong_when_show_in_rest_is_true() {
|
||||
$this->setExpectedIncorrectUsage( 'register_meta' );
|
||||
|
||||
$registered = register_meta(
|
||||
'post',
|
||||
'invalid_array',
|
||||
array(
|
||||
'type' => 'array',
|
||||
'show_in_rest' => true,
|
||||
)
|
||||
);
|
||||
|
||||
self::assertFalse( $registered );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 43392
|
||||
*/
|
||||
public function test_register_meta_issues_doing_it_wrong_when_show_in_rest_omits_schema() {
|
||||
$this->setExpectedIncorrectUsage( 'register_meta' );
|
||||
|
||||
$registered = register_meta(
|
||||
'post',
|
||||
'invalid_array',
|
||||
array(
|
||||
'type' => 'array',
|
||||
'show_in_rest' => array(
|
||||
'prepare_callback' => 'rest_sanitize_value_from_schema',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
self::assertFalse( $registered );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 43392
|
||||
*/
|
||||
public function test_register_meta_issues_doing_it_wrong_when_show_in_rest_omits_schema_items() {
|
||||
$this->setExpectedIncorrectUsage( 'register_meta' );
|
||||
|
||||
$registered = register_meta(
|
||||
'post',
|
||||
'invalid_array',
|
||||
array(
|
||||
'type' => 'array',
|
||||
'show_in_rest' => array(
|
||||
'schema' => array(
|
||||
'default' => array( 'Hi!' ),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
self::assertFalse( $registered );
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function used to disable an insert query which
|
||||
* will trigger a wpdb error for testing purposes.
|
||||
|
||||
Reference in New Issue
Block a user