| 1391 | /** |
| 1392 | * @ticket 43751 |
| 1393 | * @group multisite |
| 1394 | * @group ms-required |
| 1395 | */ |
| 1396 | public function test_create_item_with_file_exceeds_multisite_max_filesize() { |
| 1397 | wp_set_current_user( self::$author_id ); |
| 1398 | update_site_option( 'fileupload_maxk', 1 ); |
| 1399 | update_site_option( 'upload_space_check_disabled', false ); |
| 1400 | |
| 1401 | $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); |
| 1402 | $request->set_file_params( |
| 1403 | array( |
| 1404 | 'file' => array( |
| 1405 | 'error' => '0', |
| 1406 | 'file' => file_get_contents( $this->test_file ), |
| 1407 | 'name' => 'canola.jpg', |
| 1408 | 'size' => filesize( $this->test_file ), |
| 1409 | 'tmp_name' => $this->test_file, |
| 1410 | ), |
| 1411 | ) |
| 1412 | ); |
| 1413 | $request->set_param( 'title', 'My title is very cool' ); |
| 1414 | $request->set_param( 'caption', 'This is a better caption.' ); |
| 1415 | $request->set_header( 'Content-MD5', md5_file( $this->test_file ) ); |
| 1416 | |
| 1417 | $response = rest_get_server()->dispatch( $request ); |
| 1418 | $this->assertErrorResponse( 'rest_upload_file_too_big', $response, 400 ); |
| 1419 | } |
| 1420 | |
| 1421 | /** |
| 1422 | * @ticket 43751 |
| 1423 | * @group multisite |
| 1424 | * @group ms-required |
| 1425 | */ |
| 1426 | public function test_create_item_with_data_exceeds_multisite_max_filesize() { |
| 1427 | wp_set_current_user( self::$author_id ); |
| 1428 | update_site_option( 'fileupload_maxk', 1 ); |
| 1429 | update_site_option( 'upload_space_check_disabled', false ); |
| 1430 | |
| 1431 | $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); |
| 1432 | $request->set_header( 'Content-Type', 'image/jpeg' ); |
| 1433 | $request->set_header( 'Content-Disposition', 'attachment; filename=canola.jpg' ); |
| 1434 | $request->set_body( file_get_contents( $this->test_file ) ); |
| 1435 | $request->set_param( 'title', 'My title is very cool' ); |
| 1436 | $request->set_param( 'caption', 'This is a better caption.' ); |
| 1437 | |
| 1438 | $response = rest_get_server()->dispatch( $request ); |
| 1439 | $this->assertErrorResponse( 'rest_upload_file_too_big', $response, 400 ); |
| 1440 | } |
| 1441 | |
| 1442 | /** |
| 1443 | * @ticket 43751 |
| 1444 | * @group multisite |
| 1445 | * @group ms-required |
| 1446 | */ |
| 1447 | public function test_create_item_with_file_exceeds_multisite_site_upload_space() { |
| 1448 | wp_set_current_user( self::$author_id ); |
| 1449 | add_filter( 'get_space_allowed', '__return_zero' ); |
| 1450 | update_site_option( 'upload_space_check_disabled', false ); |
| 1451 | |
| 1452 | $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); |
| 1453 | $request->set_file_params( |
| 1454 | array( |
| 1455 | 'file' => array( |
| 1456 | 'error' => '0', |
| 1457 | 'file' => file_get_contents( $this->test_file ), |
| 1458 | 'name' => 'canola.jpg', |
| 1459 | 'size' => filesize( $this->test_file ), |
| 1460 | 'tmp_name' => $this->test_file, |
| 1461 | ), |
| 1462 | ) |
| 1463 | ); |
| 1464 | $request->set_param( 'title', 'My title is very cool' ); |
| 1465 | $request->set_param( 'caption', 'This is a better caption.' ); |
| 1466 | $request->set_header( 'Content-MD5', md5_file( $this->test_file ) ); |
| 1467 | |
| 1468 | $response = rest_get_server()->dispatch( $request ); |
| 1469 | $this->assertErrorResponse( 'rest_upload_limited_space', $response, 400 ); |
| 1470 | } |
| 1471 | |
| 1472 | /** |
| 1473 | * @ticket 43751 |
| 1474 | * @group multisite |
| 1475 | * @group ms-required |
| 1476 | */ |
| 1477 | public function test_create_item_with_data_exceeds_multisite_site_upload_space() { |
| 1478 | wp_set_current_user( self::$author_id ); |
| 1479 | add_filter( 'get_space_allowed', '__return_zero' ); |
| 1480 | update_site_option( 'upload_space_check_disabled', false ); |
| 1481 | |
| 1482 | $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); |
| 1483 | $request->set_header( 'Content-Type', 'image/jpeg' ); |
| 1484 | $request->set_header( 'Content-Disposition', 'attachment; filename=canola.jpg' ); |
| 1485 | $request->set_body( file_get_contents( $this->test_file ) ); |
| 1486 | $request->set_param( 'title', 'My title is very cool' ); |
| 1487 | $request->set_param( 'caption', 'This is a better caption.' ); |
| 1488 | |
| 1489 | $response = rest_get_server()->dispatch( $request ); |
| 1490 | $this->assertErrorResponse( 'rest_upload_limited_space', $response, 400 ); |
| 1491 | } |
| 1492 | |