WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#29 closed defect (fixed)

Update WPTestAttachments

Reported by: kurtpayne Owned by:
Milestone: Fix Existing Tests Priority: normal
Component: Capabilities Keywords: attachments
Cc:

Description

There are several problems with the WPTestUserCapabilities unit test. Let's update the test.

In test_insert_image_no_thumb

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

$thumb is never declared. This assertion will always fail.

Also in test_insert_image_no_thumb

// image_downsize() should return the correct images and sizes
$this->assertFalse( image_downsize($id, 'thumbnail') );
...

The comment and the assertion are out of sync. image_downsize should not return false unless the attachment id is not found, or the output is hijacked by the image_downsize filter, or $img_url var is empty because of another failure (which is not under test here).

In several places:

$filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
$upload = wp_upload_bits($filename, 'image/jpeg', $contents);
$this->assertEquals( 'a2-small-150x150.jpg', $thumb['file'] );

wp_upload_bits expects a file name, not a file path. The assertion fails because $thumb[file] contains wp-testdataimagesa2-small-150x150.jpg.

In several places:

$this->assertTrue( is_file($thumb['path']) );

The path here is relative to the WordPress upload location. is_file() should be passed the full file path.

In test_insert_image_medium:

$downsize = image_downsize($id, 'full');
$this->assertEquals( '2007-06-17dsc_4173.jpg', basename($downsize[0]) );
$this->assertEquals( 500, $downsize[1] );
$this->assertEquals( 752, $downsize[2] );

The file is 680 x 1024 and image_downsize will not constrain the size when asked for the full image.

In test_insert_image_delete:

$filename = ( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG' );
...
$this->assertEquals( '2007-06-17dsc_4173-150x150.jpg', $thumb['file'] );

The case difference between "DSC" and "dsc" causes the assertion to fail.

Attachments (1)

test_includes_post.php.patch (5.8 KB) - added by kurtpayne 2 years ago.

Download all attachments as: .zip

Change History (2)

comment:1 kurtpayne2 years ago

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in r590

Note: See TracTickets for help on using tickets.