| 1370 | /** |
| 1371 | * @ticket 43751 |
| 1372 | * @group multisite |
| 1373 | * @group ms-required |
| 1374 | */ |
| 1375 | public function test_create_item_with_file_exceeds_multisite_max_filesize() { |
| 1376 | wp_set_current_user( self::$author_id ); |
| 1377 | add_filter( 'wp_handle_mock_upload_prefilter', 'check_upload_size' ); |
| 1378 | update_site_option( 'fileupload_maxk', 1 ); |
| 1379 | update_site_option( 'upload_space_check_disabled', false ); |
| 1380 | |
| 1381 | $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); |
| 1382 | $request->set_file_params( |
| 1383 | array( |
| 1384 | 'file' => array( |
| 1385 | 'error' => '0', |
| 1386 | 'file' => file_get_contents( $this->test_file ), |
| 1387 | 'name' => 'canola.jpg', |
| 1388 | 'size' => filesize( $this->test_file ), |
| 1389 | 'tmp_name' => $this->test_file, |
| 1390 | ), |
| 1391 | ) |
| 1392 | ); |
| 1393 | $request->set_param( 'title', 'My title is very cool' ); |
| 1394 | $request->set_param( 'caption', 'This is a better caption.' ); |
| 1395 | $request->set_header( 'Content-MD5', md5_file( $this->test_file ) ); |
| 1396 | |
| 1397 | $response = rest_get_server()->dispatch( $request ); |
| 1398 | $this->assertErrorResponse( 'rest_upload_unknown_error', $response, 500 ); |
| 1399 | } |
| 1400 | |
| 1401 | /** |
| 1402 | * @ticket 43751 |
| 1403 | * @group multisite |
| 1404 | * @group ms-required |
| 1405 | */ |
| 1406 | public function test_create_item_with_data_exceeds_multisite_max_filesize() { |
| 1407 | wp_set_current_user( self::$author_id ); |
| 1408 | update_site_option( 'fileupload_maxk', 1 ); |
| 1409 | update_site_option( 'upload_space_check_disabled', false ); |
| 1410 | |
| 1411 | $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); |
| 1412 | $request->set_header( 'Content-Type', 'image/jpeg' ); |
| 1413 | $request->set_header( 'Content-Disposition', 'attachment; filename=canola.jpg' ); |
| 1414 | $request->set_body( file_get_contents( $this->test_file ) ); |
| 1415 | $request->set_param( 'title', 'My title is very cool' ); |
| 1416 | $request->set_param( 'caption', 'This is a better caption.' ); |
| 1417 | |
| 1418 | $response = rest_get_server()->dispatch( $request ); |
| 1419 | $this->assertErrorResponse( 'rest_upload_sideload_error', $response, 500 ); |
| 1420 | } |
| 1421 | |
| 1422 | /** |
| 1423 | * @ticket 43751 |
| 1424 | * @group multisite |
| 1425 | * @group ms-required |
| 1426 | */ |
| 1427 | public function test_create_item_with_file_exceeds_multisite_site_upload_space() { |
| 1428 | wp_set_current_user( self::$author_id ); |
| 1429 | add_filter( 'wp_handle_mock_upload_prefilter', 'check_upload_size' ); |
| 1430 | add_filter( 'get_space_allowed', '__return_zero' ); |
| 1431 | update_site_option( 'upload_space_check_disabled', false ); |
| 1432 | |
| 1433 | $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); |
| 1434 | $request->set_file_params( |
| 1435 | array( |
| 1436 | 'file' => array( |
| 1437 | 'error' => '0', |
| 1438 | 'file' => file_get_contents( $this->test_file ), |
| 1439 | 'name' => 'canola.jpg', |
| 1440 | 'size' => filesize( $this->test_file ), |
| 1441 | 'tmp_name' => $this->test_file, |
| 1442 | ), |
| 1443 | ) |
| 1444 | ); |
| 1445 | $request->set_param( 'title', 'My title is very cool' ); |
| 1446 | $request->set_param( 'caption', 'This is a better caption.' ); |
| 1447 | $request->set_header( 'Content-MD5', md5_file( $this->test_file ) ); |
| 1448 | |
| 1449 | $response = rest_get_server()->dispatch( $request ); |
| 1450 | $this->assertErrorResponse( 'rest_upload_unknown_error', $response, 500 ); |
| 1451 | } |
| 1452 | |
| 1453 | /** |
| 1454 | * @ticket 43751 |
| 1455 | * @group multisite |
| 1456 | * @group ms-required |
| 1457 | */ |
| 1458 | public function test_create_item_with_data_exceeds_multisite_site_upload_space() { |
| 1459 | wp_set_current_user( self::$author_id ); |
| 1460 | add_filter( 'get_space_allowed', '__return_zero' ); |
| 1461 | update_site_option( 'upload_space_check_disabled', false ); |
| 1462 | |
| 1463 | $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); |
| 1464 | $request->set_header( 'Content-Type', 'image/jpeg' ); |
| 1465 | $request->set_header( 'Content-Disposition', 'attachment; filename=canola.jpg' ); |
| 1466 | $request->set_body( file_get_contents( $this->test_file ) ); |
| 1467 | $request->set_param( 'title', 'My title is very cool' ); |
| 1468 | $request->set_param( 'caption', 'This is a better caption.' ); |
| 1469 | |
| 1470 | $response = rest_get_server()->dispatch( $request ); |
| 1471 | $this->assertErrorResponse( 'rest_upload_sideload_error', $response, 500 ); |
| 1472 | } |
| 1473 | |