mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-01 19:24:34 +00:00
REST API, Media: Add batch image editing endpoints.
Introduces new endpoints to allow for batch image editing using the REST API. The new endpoints can take an array of modifiers that will be applied in the order they appear. Props ajlende, TimothyBlynJacobs, hellofromTonya, Mista-Flo. Fixes #52192. git-svn-id: https://develop.svn.wordpress.org/trunk@50124 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2078,6 +2078,49 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$this->assertContains( 'canola', $item['media_details']['parent_image']['file'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 52192
|
||||
* @requires function imagejpeg
|
||||
*/
|
||||
public function test_batch_edit_image() {
|
||||
wp_set_current_user( self::$superadmin_id );
|
||||
$attachment = self::factory()->attachment->create_upload_object( $this->test_file );
|
||||
|
||||
$params = array(
|
||||
'modifiers' => array(
|
||||
array(
|
||||
'type' => 'rotate',
|
||||
'args' => array(
|
||||
'angle' => 60,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'crop',
|
||||
'args' => array(
|
||||
'left' => 50,
|
||||
'top' => 10,
|
||||
'width' => 10,
|
||||
'height' => 5,
|
||||
),
|
||||
),
|
||||
),
|
||||
'src' => wp_get_attachment_image_url( $attachment, 'full' ),
|
||||
);
|
||||
|
||||
$request = new WP_REST_Request( 'POST', "/wp/v2/media/{$attachment}/edit" );
|
||||
$request->set_body_params( $params );
|
||||
$response = rest_do_request( $request );
|
||||
$item = $response->get_data();
|
||||
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
$this->assertSame( rest_url( '/wp/v2/media/' . $item['id'] ), $response->get_headers()['Location'] );
|
||||
|
||||
$this->assertStringEndsWith( '-edited.jpg', $item['media_details']['file'] );
|
||||
$this->assertArrayHasKey( 'parent_image', $item['media_details'] );
|
||||
$this->assertEquals( $attachment, $item['media_details']['parent_image']['attachment_id'] );
|
||||
$this->assertContains( 'canola', $item['media_details']['parent_image']['file'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50565
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user