|
5 | 5 | * @package webp-uploads
|
6 | 6 | */
|
7 | 7 |
|
| 8 | +use PHP_CodeSniffer\Tokenizers\PHP; |
8 | 9 | use WebP_Uploads\Tests\TestCase;
|
9 | 10 |
|
10 | 11 | class Test_WebP_Uploads_Load extends TestCase {
|
@@ -1154,8 +1155,9 @@ static function () {
|
1154 | 1155 | 'error' => UPLOAD_ERR_OK,
|
1155 | 1156 | );
|
1156 | 1157 |
|
1157 |
| - // Store the original file hash to compare later. |
| 1158 | + // Store the original file hash and the original file size for later comparison. |
1158 | 1159 | $original_file_hash = isset( $file['tmp_name'] ) ? md5_file( $file['tmp_name'] ) : '';
|
| 1160 | + $original_file_size = (int) filesize( $file['tmp_name'] ); |
1159 | 1161 |
|
1160 | 1162 | // This will trigger the `wp_handle_sideload_prefilter` filter.
|
1161 | 1163 | $attachment_id = media_handle_sideload( $file );
|
@@ -1191,7 +1193,11 @@ static function () {
|
1191 | 1193 | $modern_image_format_path = get_attached_file( $attachment_id );
|
1192 | 1194 | $this->assertNotFalse( $modern_image_format_path );
|
1193 | 1195 | $this->assertFileExists( $modern_image_format_path );
|
1194 |
| - $this->assertGreaterThan( 0, (int) filesize( $modern_image_format_path ) ); |
| 1196 | + $modern_image_format_filesize = (int) filesize( $modern_image_format_path ); |
| 1197 | + $this->assertGreaterThan( 0, $modern_image_format_filesize ); |
| 1198 | + |
| 1199 | + // Ensure the file size of the converted image is less than or equal to the original indexed PNG file size. |
| 1200 | + $this->assertLessThanOrEqual( $original_file_size, $modern_image_format_filesize ); |
1195 | 1201 | }
|
1196 | 1202 | } finally {
|
1197 | 1203 | wp_delete_attachment( $attachment_id );
|
|
0 commit comments