@@ -3307,6 +3307,7 @@ public function test_create_update_post_with_featured_media() {
33073307
33083308 wp_set_current_user ( self ::$ editor_id );
33093309
3310+ // Set the featured image initially.
33103311 $ request = new WP_REST_Request ( 'POST ' , '/wp/v2/posts ' );
33113312 $ params = $ this ->set_post_data (
33123313 array (
@@ -3315,11 +3316,27 @@ public function test_create_update_post_with_featured_media() {
33153316 );
33163317 $ request ->set_body_params ( $ params );
33173318 $ response = rest_get_server ()->dispatch ( $ request );
3319+ $ this ->assertSame ( 201 , $ response ->get_status () );
33183320 $ data = $ response ->get_data ();
33193321 $ new_post = get_post ( $ data ['id ' ] );
33203322 $ this ->assertSame ( $ attachment_id , $ data ['featured_media ' ] );
33213323 $ this ->assertSame ( $ attachment_id , (int ) get_post_thumbnail_id ( $ new_post ->ID ) );
33223324
3325+ // Try updating the post with the same value.
3326+ $ request = new WP_REST_Request ( 'POST ' , '/wp/v2/posts/ ' . $ new_post ->ID );
3327+ $ params = $ this ->set_post_data (
3328+ array (
3329+ 'featured_media ' => $ attachment_id ,
3330+ )
3331+ );
3332+ $ request ->set_body_params ( $ params );
3333+ $ response = rest_get_server ()->dispatch ( $ request );
3334+ $ this ->assertSame ( 200 , $ response ->get_status () );
3335+ $ data = $ response ->get_data ();
3336+ $ this ->assertSame ( $ attachment_id , $ data ['featured_media ' ] );
3337+ $ this ->assertSame ( $ attachment_id , (int ) get_post_thumbnail_id ( $ new_post ->ID ) );
3338+
3339+ // Try deleting the featured media.
33233340 $ request = new WP_REST_Request ( 'POST ' , '/wp/v2/posts/ ' . $ new_post ->ID );
33243341 $ params = $ this ->set_post_data (
33253342 array (
@@ -3328,7 +3345,8 @@ public function test_create_update_post_with_featured_media() {
33283345 );
33293346 $ request ->set_body_params ( $ params );
33303347 $ response = rest_get_server ()->dispatch ( $ request );
3331- $ data = $ response ->get_data ();
3348+ $ this ->assertSame ( 200 , $ response ->get_status () );
3349+ $ data = $ response ->get_data ();
33323350 $ this ->assertSame ( 0 , $ data ['featured_media ' ] );
33333351 $ this ->assertSame ( 0 , (int ) get_post_thumbnail_id ( $ new_post ->ID ) );
33343352 }
0 commit comments