Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions tests/phpunit/tests/image/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,10 @@ public function test_wp_crop_image_with_file() {
/**
* @covers ::wp_crop_image
* @requires function imagejpeg
* @requires extension openssl
*/
public function test_wp_crop_image_with_url() {
$file = wp_crop_image(
'https://s.w.org/screenshots/3.9/dashboard.png',
'file://' . DIR_TESTDATA . '/images/test-image.png',
0,
0,
100,
Expand Down
6 changes: 5 additions & 1 deletion tests/phpunit/tests/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public function set_up(): void {
self::$original_wp_styles = $wp_styles;
$wp_styles = null;
parent::set_up();

$this->reset_content_media_count();
$this->reset_omit_loading_attr_filter();
$this->reset_high_priority_element_flag();
}

public static function wpTearDownAfterClass() {
Expand Down Expand Up @@ -269,7 +273,7 @@ public function test_img_caption_shortcode_with_old_format_id_and_align() {
)
);
$this->assertSame( 1, substr_count( $result, 'wp-caption &myAlignment' ) );
$this->assertSame( 1, preg_match( '/id="myId(?:[0-9]+)?"/', $result ) );
$this->assertSame( 1, preg_match( '/id="myId(?:-[0-9]+)?"/', $result ) );
$this->assertSame( 1, substr_count( $result, self::CAPTION ) );
}

Expand Down
50 changes: 36 additions & 14 deletions tests/phpunit/tests/post/attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,29 @@
*/
class Tests_Post_Attachments extends WP_UnitTestCase {

/**
* Original HTTPS value.
*
* @var string|null
*/
private $original_https;

public function set_up() {
parent::set_up();

$this->original_https = $_SERVER['HTTPS'] ?? null;
}

public function tear_down() {
// Remove all uploads.
$this->remove_added_uploads();

if ( null === $this->original_https ) {
unset( $_SERVER['HTTPS'] );
} else {
$_SERVER['HTTPS'] = $this->original_https;
}

parent::tear_down();
}

Expand Down Expand Up @@ -121,43 +141,44 @@ public function test_insert_image_medium_sizes() {
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
$this->assertEmpty( $upload['error'] );

$id = $this->_make_attachment( $upload );
$uploads = wp_upload_dir();
$id = $this->_make_attachment( $upload );
$uploads = wp_upload_dir();
$filename_base = wp_basename( $upload['file'], '.jpg' );

// Intermediate copies should exist: thumbnail and medium.
$thumb = image_get_intermediate_size( $id, 'thumbnail' );
$this->assertSame( '2007-06-17DSC_4173-150x150.jpg', $thumb['file'] );
$this->assertSame( $filename_base . '-150x150.jpg', $thumb['file'] );
$this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path'] ) );

$medium = image_get_intermediate_size( $id, 'medium' );
$this->assertSame( '2007-06-17DSC_4173-400x602.jpg', $medium['file'] );
$this->assertSame( $filename_base . '-400x602.jpg', $medium['file'] );
$this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path'] ) );

$medium_large = image_get_intermediate_size( $id, 'medium_large' );
$this->assertSame( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] );
$this->assertSame( $filename_base . '-600x904.jpg', $medium_large['file'] );
$this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path'] ) );

// The thumb url should point to the thumbnail intermediate.
$this->assertSame( $thumb['url'], wp_get_attachment_thumb_url( $id ) );

// image_downsize() should return the correct images and sizes.
$downsize = image_downsize( $id, 'thumbnail' );
$this->assertSame( '2007-06-17DSC_4173-150x150.jpg', wp_basename( $downsize[0] ) );
$this->assertSame( $filename_base . '-150x150.jpg', wp_basename( $downsize[0] ) );
$this->assertSame( 150, $downsize[1] );
$this->assertSame( 150, $downsize[2] );

$downsize = image_downsize( $id, 'medium' );
$this->assertSame( '2007-06-17DSC_4173-400x602.jpg', wp_basename( $downsize[0] ) );
$this->assertSame( $filename_base . '-400x602.jpg', wp_basename( $downsize[0] ) );
$this->assertSame( 400, $downsize[1] );
$this->assertSame( 602, $downsize[2] );

$downsize = image_downsize( $id, 'medium_large' );
$this->assertSame( '2007-06-17DSC_4173-600x904.jpg', wp_basename( $downsize[0] ) );
$this->assertSame( $filename_base . '-600x904.jpg', wp_basename( $downsize[0] ) );
$this->assertSame( 600, $downsize[1] );
$this->assertSame( 904, $downsize[2] );

$downsize = image_downsize( $id, 'full' );
$this->assertSame( '2007-06-17DSC_4173.jpg', wp_basename( $downsize[0] ) );
$this->assertSame( $filename_base . '.jpg', wp_basename( $downsize[0] ) );
$this->assertSame( 680, $downsize[1] );
$this->assertSame( 1024, $downsize[2] );
}
Expand All @@ -178,20 +199,21 @@ public function test_insert_image_delete() {
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
$this->assertEmpty( $upload['error'] );

$id = $this->_make_attachment( $upload );
$uploads = wp_upload_dir();
$id = $this->_make_attachment( $upload );
$uploads = wp_upload_dir();
$filename_base = wp_basename( $upload['file'], '.jpg' );

// Check that the file and intermediates exist.
$thumb = image_get_intermediate_size( $id, 'thumbnail' );
$this->assertSame( '2007-06-17DSC_4173-150x150.jpg', $thumb['file'] );
$this->assertSame( $filename_base . '-150x150.jpg', $thumb['file'] );
$this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path'] ) );

$medium = image_get_intermediate_size( $id, 'medium' );
$this->assertSame( '2007-06-17DSC_4173-400x602.jpg', $medium['file'] );
$this->assertSame( $filename_base . '-400x602.jpg', $medium['file'] );
$this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path'] ) );

$medium_large = image_get_intermediate_size( $id, 'medium_large' );
$this->assertSame( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] );
$this->assertSame( $filename_base . '-600x904.jpg', $medium_large['file'] );
$this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path'] ) );

$meta = wp_get_attachment_metadata( $id );
Expand Down
Loading