From 44e7429d754f34d9b2c713d0f01b564807dfb09b Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Thu, 27 Jun 2024 13:03:10 +1000 Subject: [PATCH] Add unit test --- .../rest-api/rest-attachments-controller.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index 074c710c740f5..737c32b8e1ab1 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -2381,6 +2381,43 @@ public function test_edit_image_crop() { ); } + /** + * @ticket 61514 + * @requires function imagejpeg + */ + public function test_edit_image_crop_one_axis() { + wp_set_current_user( self::$superadmin_id ); + $attachment = self::factory()->attachment->create_upload_object( self::$test_file ); + + $this->setup_mock_editor(); + WP_Image_Editor_Mock::$size_return = array( + 'width' => 640, + 'height' => 480, + ); + + WP_Image_Editor_Mock::$edit_return['crop'] = new WP_Error(); + + $request = new WP_REST_Request( 'POST', "/wp/v2/media/{$attachment}/edit" ); + $request->set_body_params( + array( + 'x' => 50, + 'y' => 0, + 'width' => 10, + 'height' => 100, + 'src' => wp_get_attachment_image_url( $attachment, 'full' ), + + ) + ); + $response = rest_do_request( $request ); + $this->assertErrorResponse( 'rest_image_crop_failed', $response, 500 ); + + $this->assertCount( 1, WP_Image_Editor_Mock::$spy['crop'] ); + $this->assertSame( + array( 320, 0, 64, 480 ), + WP_Image_Editor_Mock::$spy['crop'][0] + ); + } + /** * @ticket 44405 * @requires function imagejpeg