Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Jun 27, 2024
1 parent 429d9a6 commit 44e7429
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/phpunit/tests/rest-api/rest-attachments-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 44e7429

Please sign in to comment.