mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-01 19:24:34 +00:00
REST API: Allow sending an empty array to delete multi meta keys.
Previously, only `null` was supported. Fixes #50790. Props chrisvanpatten. git-svn-id: https://develop.svn.wordpress.org/trunk@49966 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1027,6 +1027,31 @@ class WP_Test_REST_Post_Meta_Fields extends WP_Test_REST_TestCase {
|
||||
$this->assertSame( $post_original->post_content, $post_updated->post_content );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50790
|
||||
*/
|
||||
public function test_remove_multi_value_with_empty_array() {
|
||||
add_post_meta( self::$post_id, 'test_multi', 'val1' );
|
||||
$values = get_post_meta( self::$post_id, 'test_multi', false );
|
||||
$this->assertSame( array( 'val1' ), $values );
|
||||
|
||||
$this->grant_write_permission();
|
||||
|
||||
$data = array(
|
||||
'meta' => array(
|
||||
'test_multi' => array(),
|
||||
),
|
||||
);
|
||||
$request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
|
||||
$request->set_body_params( $data );
|
||||
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
|
||||
$meta = get_post_meta( self::$post_id, 'test_multi', false );
|
||||
$this->assertEmpty( $meta );
|
||||
}
|
||||
|
||||
public function test_remove_multi_value_db_error() {
|
||||
add_post_meta( self::$post_id, 'test_multi', 'val1' );
|
||||
$values = get_post_meta( self::$post_id, 'test_multi', false );
|
||||
|
||||
Reference in New Issue
Block a user