From 413118332dbe4c546e2332f9443106d736b8c38f Mon Sep 17 00:00:00 2001 From: Sainath Poojary Date: Sun, 20 Sep 2026 01:22:15 +0530 Subject: [PATCH] Tests: Reduce fixture cost in WP_Test_REST_Attachments_Controller --- .../rest-api/rest-attachments-controller.php | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index 282c0f6b95e22..4f5603f72065f 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -2973,10 +2973,15 @@ public function filter_rest_after_insert_attachment( $attachment ) { /** * @ticket 44405 - * @requires function imagejpeg */ public function test_edit_image_returns_error_if_logged_out() { - $attachment = self::factory()->attachment->create_upload_object( self::$test_file ); + $attachment = self::factory()->attachment->create( + array( + 'file' => 'canola.jpg', + 'post_mime_type' => 'image/jpeg', + 'post_status' => 'inherit', + ) + ); $request = new WP_REST_Request( 'POST', "/wp/v2/media/{$attachment}/edit" ); $request->set_body_params( array( 'src' => wp_get_attachment_image_url( $attachment, 'full' ) ) ); @@ -2986,14 +2991,19 @@ public function test_edit_image_returns_error_if_logged_out() { /** * @ticket 44405 - * @requires function imagejpeg */ public function test_edit_image_returns_error_if_cannot_upload() { $user = self::factory()->user->create_and_get( array( 'role' => 'editor' ) ); $user->add_cap( 'upload_files', false ); wp_set_current_user( $user->ID ); - $attachment = self::factory()->attachment->create_upload_object( self::$test_file ); + $attachment = self::factory()->attachment->create( + array( + 'file' => 'canola.jpg', + 'post_mime_type' => 'image/jpeg', + 'post_status' => 'inherit', + ) + ); $request = new WP_REST_Request( 'POST', "/wp/v2/media/{$attachment}/edit" ); $request->set_body_params( array( 'src' => wp_get_attachment_image_url( $attachment, 'full' ) ) ); @@ -3003,11 +3013,16 @@ public function test_edit_image_returns_error_if_cannot_upload() { /** * @ticket 44405 - * @requires function imagejpeg */ public function test_edit_image_returns_error_if_cannot_edit() { wp_set_current_user( self::$uploader_id ); - $attachment = self::factory()->attachment->create_upload_object( self::$test_file ); + $attachment = self::factory()->attachment->create( + array( + 'file' => 'canola.jpg', + 'post_mime_type' => 'image/jpeg', + 'post_status' => 'inherit', + ) + ); $request = new WP_REST_Request( 'POST', "/wp/v2/media/{$attachment}/edit" ); $request->set_body_params( array( 'src' => wp_get_attachment_image_url( $attachment, 'full' ) ) ); @@ -3219,6 +3234,9 @@ static function () { * @requires function imagejpeg */ public function test_edit_image_rotate_with_unbaked_exif_orientation() { + // Only the full-size image dimensions are checked, so no intermediate sizes are needed. + add_filter( 'intermediate_image_sizes_advanced', '__return_empty_array' ); + wp_set_current_user( self::$superadmin_id ); $attachment = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image-rotated-90ccw.jpg' );