mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
These tests ensure that `wp_generate_attachment_metadata()` stores the file size of all newly uploaded attachments under the `filesize` array key. The tests were initially supposed to be committed with [52837]. Follow-up to [52837], [52932], [54861]. Props spacedmonkey, johnwatkins0, mitogh, adamsilverstein, pbearne, SergeyBiryukov. Fixes #57171. git-svn-id: https://develop.svn.wordpress.org/trunk@54863 602fd350-edb4-49c9-b593-d223f7449a82
90 lines
2.6 KiB
PHP
90 lines
2.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Tests for the `wp_generate_attachment_metadata()` function.
|
|
*
|
|
* @group media
|
|
* @covers ::wp_generate_attachment_metadata
|
|
*/
|
|
class Tests_Media_wpGenerateAttachmentMetadata extends WP_UnitTestCase {
|
|
|
|
public function tear_down() {
|
|
$this->remove_added_uploads();
|
|
|
|
parent::tear_down();
|
|
}
|
|
|
|
/**
|
|
* Tests that filesize meta is generated for JPEGs.
|
|
*
|
|
* @ticket 49412
|
|
*
|
|
* @covers ::wp_create_image_subsizes
|
|
*/
|
|
public function test_wp_generate_attachment_metadata_includes_filesize_in_jpg_meta() {
|
|
$attachment = $this->factory->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' );
|
|
|
|
$metadata = wp_get_attachment_metadata( $attachment );
|
|
|
|
$this->assertSame( wp_filesize( get_attached_file( $attachment ) ), $metadata['filesize'] );
|
|
|
|
foreach ( $metadata['sizes'] as $intermediate_size ) {
|
|
$this->assertArrayHasKey( 'filesize', $intermediate_size );
|
|
$this->assertNotEmpty( $intermediate_size['filesize'] );
|
|
$this->assertIsNumeric( $intermediate_size['filesize'] );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Checks that filesize meta is generated for PNGs.
|
|
*
|
|
* @ticket 49412
|
|
*
|
|
* @covers ::wp_create_image_subsizes
|
|
*/
|
|
public function test_wp_generate_attachment_metadata_includes_filesize_in_png_meta() {
|
|
$attachment = $this->factory->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.png' );
|
|
|
|
$metadata = wp_get_attachment_metadata( $attachment );
|
|
|
|
$this->assertSame( wp_filesize( get_attached_file( $attachment ) ), $metadata['filesize'] );
|
|
}
|
|
|
|
/**
|
|
* Checks that filesize meta is generated for PDFs.
|
|
*
|
|
* @ticket 49412
|
|
*/
|
|
public function test_wp_generate_attachment_metadata_includes_filesize_in_pdf_meta() {
|
|
$attachment = $this->factory->attachment->create_upload_object( DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf' );
|
|
|
|
$metadata = wp_get_attachment_metadata( $attachment );
|
|
|
|
$this->assertSame( wp_filesize( get_attached_file( $attachment ) ), $metadata['filesize'] );
|
|
}
|
|
|
|
/**
|
|
* Checks that filesize meta is generated for PSDs.
|
|
*
|
|
* @ticket 49412
|
|
*/
|
|
public function test_wp_generate_attachment_metadata_includes_filesize_in_psd_meta() {
|
|
if ( is_multisite() ) {
|
|
// PSD mime type is not allowed by default on multisite.
|
|
add_filter(
|
|
'upload_mimes',
|
|
static function( $mimes ) {
|
|
$mimes['psd'] = 'application/octet-stream';
|
|
return $mimes;
|
|
}
|
|
);
|
|
}
|
|
|
|
$attachment = $this->factory->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.psd' );
|
|
|
|
$metadata = wp_get_attachment_metadata( $attachment );
|
|
|
|
$this->assertSame( wp_filesize( get_attached_file( $attachment ) ), $metadata['filesize'] );
|
|
}
|
|
}
|