mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 21:00:21 +00:00
REST API: Attachments controller should respect upload limits.
When the REST API is in use on WordPress multisite, the `WP_REST_Attachments_Controller` should respect the "Max upload file size" and "Site upload space" site options. Props flixos90, danielbachhuber. Fixes #43751. git-svn-id: https://develop.svn.wordpress.org/trunk@43462 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1432,4 +1432,106 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 43751
|
||||
* @group multisite
|
||||
* @group ms-required
|
||||
*/
|
||||
public function test_create_item_with_file_exceeds_multisite_max_filesize() {
|
||||
wp_set_current_user( self::$author_id );
|
||||
update_site_option( 'fileupload_maxk', 1 );
|
||||
update_site_option( 'upload_space_check_disabled', false );
|
||||
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/media' );
|
||||
$request->set_file_params(
|
||||
array(
|
||||
'file' => array(
|
||||
'error' => '0',
|
||||
'file' => file_get_contents( $this->test_file ),
|
||||
'name' => 'canola.jpg',
|
||||
'size' => filesize( $this->test_file ),
|
||||
'tmp_name' => $this->test_file,
|
||||
),
|
||||
)
|
||||
);
|
||||
$request->set_param( 'title', 'My title is very cool' );
|
||||
$request->set_param( 'caption', 'This is a better caption.' );
|
||||
$request->set_header( 'Content-MD5', md5_file( $this->test_file ) );
|
||||
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_upload_file_too_big', $response, 400 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 43751
|
||||
* @group multisite
|
||||
* @group ms-required
|
||||
*/
|
||||
public function test_create_item_with_data_exceeds_multisite_max_filesize() {
|
||||
wp_set_current_user( self::$author_id );
|
||||
update_site_option( 'fileupload_maxk', 1 );
|
||||
update_site_option( 'upload_space_check_disabled', false );
|
||||
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/media' );
|
||||
$request->set_header( 'Content-Type', 'image/jpeg' );
|
||||
$request->set_header( 'Content-Disposition', 'attachment; filename=canola.jpg' );
|
||||
$request->set_body( file_get_contents( $this->test_file ) );
|
||||
$request->set_param( 'title', 'My title is very cool' );
|
||||
$request->set_param( 'caption', 'This is a better caption.' );
|
||||
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_upload_file_too_big', $response, 400 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 43751
|
||||
* @group multisite
|
||||
* @group ms-required
|
||||
*/
|
||||
public function test_create_item_with_file_exceeds_multisite_site_upload_space() {
|
||||
wp_set_current_user( self::$author_id );
|
||||
add_filter( 'get_space_allowed', '__return_zero' );
|
||||
update_site_option( 'upload_space_check_disabled', false );
|
||||
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/media' );
|
||||
$request->set_file_params(
|
||||
array(
|
||||
'file' => array(
|
||||
'error' => '0',
|
||||
'file' => file_get_contents( $this->test_file ),
|
||||
'name' => 'canola.jpg',
|
||||
'size' => filesize( $this->test_file ),
|
||||
'tmp_name' => $this->test_file,
|
||||
),
|
||||
)
|
||||
);
|
||||
$request->set_param( 'title', 'My title is very cool' );
|
||||
$request->set_param( 'caption', 'This is a better caption.' );
|
||||
$request->set_header( 'Content-MD5', md5_file( $this->test_file ) );
|
||||
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_upload_limited_space', $response, 400 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 43751
|
||||
* @group multisite
|
||||
* @group ms-required
|
||||
*/
|
||||
public function test_create_item_with_data_exceeds_multisite_site_upload_space() {
|
||||
wp_set_current_user( self::$author_id );
|
||||
add_filter( 'get_space_allowed', '__return_zero' );
|
||||
update_site_option( 'upload_space_check_disabled', false );
|
||||
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/media' );
|
||||
$request->set_header( 'Content-Type', 'image/jpeg' );
|
||||
$request->set_header( 'Content-Disposition', 'attachment; filename=canola.jpg' );
|
||||
$request->set_body( file_get_contents( $this->test_file ) );
|
||||
$request->set_param( 'title', 'My title is very cool' );
|
||||
$request->set_param( 'caption', 'This is a better caption.' );
|
||||
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_upload_limited_space', $response, 400 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user