- Timestamp:
- 03/25/2025 02:04:47 PM (13 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r60068 r60084 29 29 30 30 /** 31 * @var string The path to the AVIF test image. 32 */ 33 private static $test_avif_file; 34 35 /** 31 36 * @var array The recorded posts query clauses. 32 37 */ … … 73 78 unlink( self::$test_file2 ); 74 79 } 80 if ( file_exists( self::$test_avif_file ) ) { 81 unlink( self::$test_avif_file ); 82 } 75 83 76 84 self::delete_user( self::$editor_id ); … … 100 108 if ( ! file_exists( self::$test_file2 ) ) { 101 109 copy( $orig_file2, self::$test_file2 ); 110 } 111 112 $orig_avif_file = DIR_TESTDATA . '/images/avif-lossy.avif'; 113 self::$test_avif_file = get_temp_dir() . 'avif-lossy.avif'; 114 if ( ! file_exists( self::$test_avif_file ) ) { 115 copy( $orig_avif_file, self::$test_avif_file ); 102 116 } 103 117 … … 2542 2556 ); 2543 2557 } 2558 2559 /** 2560 * Test that uploading unsupported image types throws a `rest_upload_image_type_not_supported` error. 2561 * 2562 * @ticket 61167 2563 */ 2564 public function test_upload_unsupported_image_type() { 2565 2566 // Only run this test when the editor doesn't support AVIF. 2567 if ( wp_image_editor_supports( array( 'AVIF' ) ) ) { 2568 $this->markTestSkipped( 'The image editor suppports AVIF.' ); 2569 } 2570 2571 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 2572 2573 wp_set_current_user( self::$author_id ); 2574 $request->set_header( 'Content-Type', 'image/avif' ); 2575 $request->set_header( 'Content-Disposition', 'attachment; filename=avif-lossy.avif' ); 2576 $request->set_body( file_get_contents( self::$test_avif_file ) ); 2577 $response = rest_get_server()->dispatch( $request ); 2578 2579 $this->assertErrorResponse( 'rest_upload_image_type_not_supported', $response, 400 ); 2580 } 2581 2582 /** 2583 * Test that the `wp_prevent_unsupported_image_uploads` filter enables uploading of unsupported image types. 2584 * 2585 * @ticket 61167 2586 */ 2587 public function test_upload_unsupported_image_type_with_filter() { 2588 2589 // Only run this test when the editor doesn't support AVIF. 2590 if ( wp_image_editor_supports( array( 'AVIF' ) ) ) { 2591 $this->markTestSkipped( 'The image editor suppports AVIF.' ); 2592 } 2593 2594 add_filter( 'wp_prevent_unsupported_image_uploads', '__return_false' ); 2595 2596 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 2597 2598 wp_set_current_user( self::$author_id ); 2599 $request->set_header( 'Content-Type', 'image/avif' ); 2600 $request->set_header( 'Content-Disposition', 'attachment; filename=avif-lossy.avif' ); 2601 $request->set_body( file_get_contents( self::$test_avif_file ) ); 2602 $response = rest_get_server()->dispatch( $request ); 2603 2604 $this->assertSame( 201, $response->get_status() ); 2605 } 2544 2606 }
Note: See TracChangeset
for help on using the changeset viewer.