@@ -3149,6 +3149,89 @@ public function test_edit_image_crop_one_axis() {
31493149 );
31503150 }
31513151
3152+ /**
3153+ * @ticket 65618
3154+ * @requires function imagejpeg
3155+ */
3156+ public function test_edit_image_returns_error_if_no_image_editor () {
3157+ wp_set_current_user ( self ::$ superadmin_id );
3158+ $ attachment = self ::factory ()->attachment ->create_upload_object ( self ::$ test_file );
3159+
3160+ add_filter ( 'wp_image_editors ' , '__return_empty_array ' );
3161+
3162+ $ request = new WP_REST_Request ( 'POST ' , "/wp/v2/media/ {$ attachment }/edit " );
3163+ $ request ->set_body_params (
3164+ array (
3165+ 'rotation ' => 60 ,
3166+ 'src ' => wp_get_attachment_image_url ( $ attachment , 'full ' ),
3167+ )
3168+ );
3169+ $ response = rest_do_request ( $ request );
3170+ $ this ->assertErrorResponse ( 'rest_unknown_image_file_type ' , $ response , 500 );
3171+ }
3172+
3173+ /**
3174+ * @ticket 65618
3175+ * @requires function imagejpeg
3176+ */
3177+ public function test_edit_image_applies_unbaked_exif_orientation_before_edits () {
3178+ wp_set_current_user ( self ::$ superadmin_id );
3179+ $ attachment = self ::factory ()->attachment ->create_upload_object ( self ::$ test_file );
3180+
3181+ $ this ->setup_mock_editor ();
3182+ add_filter (
3183+ 'wp_image_maybe_exif_rotate ' ,
3184+ static function () {
3185+ return 6 ;
3186+ }
3187+ );
3188+ WP_Image_Editor_Mock::$ edit_return ['rotate ' ] = new WP_Error ();
3189+
3190+ $ request = new WP_REST_Request ( 'POST ' , "/wp/v2/media/ {$ attachment }/edit " );
3191+ $ request ->set_body_params (
3192+ array (
3193+ 'rotation ' => 60 ,
3194+ 'src ' => wp_get_attachment_image_url ( $ attachment , 'full ' ),
3195+ )
3196+ );
3197+ $ response = rest_do_request ( $ request );
3198+ $ this ->assertErrorResponse ( 'rest_image_rotation_failed ' , $ response , 500 );
3199+
3200+ // The EXIF orientation correction (orientation 6 => rotate 270) must run before the requested edit.
3201+ $ this ->assertSame ( array ( array ( 270 ), array ( -60 ) ), WP_Image_Editor_Mock::$ spy ['rotate ' ] );
3202+ }
3203+
3204+ /**
3205+ * @ticket 65618
3206+ * @requires extension exif
3207+ * @requires function imagejpeg
3208+ */
3209+ public function test_edit_image_rotate_with_unbaked_exif_orientation () {
3210+ wp_set_current_user ( self ::$ superadmin_id );
3211+ $ attachment = self ::factory ()->attachment ->create_upload_object ( DIR_TESTDATA . '/images/test-image-rotated-90ccw.jpg ' );
3212+
3213+ $ request = new WP_REST_Request ( 'POST ' , "/wp/v2/media/ {$ attachment }/edit " );
3214+ $ request ->set_body_params (
3215+ array (
3216+ 'rotation ' => 90 ,
3217+ 'src ' => wp_get_attachment_image_url ( $ attachment , 'full ' ),
3218+ )
3219+ );
3220+ $ response = rest_do_request ( $ request );
3221+ $ item = $ response ->get_data ();
3222+
3223+ $ this ->assertSame ( 201 , $ response ->get_status () );
3224+
3225+ /*
3226+ * The original file is 1200x1800 raw pixels with an unapplied EXIF orientation of 6,
3227+ * so clients preview it upright as 1800x1200. Rotating that upright frame 90 degrees
3228+ * must produce 1200x1800. Without the orientation correction the edit rotates the raw
3229+ * pixels instead and produces 1800x1200.
3230+ */
3231+ $ this ->assertSame ( 1200 , $ item ['media_details ' ]['width ' ] );
3232+ $ this ->assertSame ( 1800 , $ item ['media_details ' ]['height ' ] );
3233+ }
3234+
31523235 /**
31533236 * @ticket 44405
31543237 * @requires function imagejpeg
0 commit comments