mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-07 01:39:04 +00:00
Tests: Clean up test images before performing assertions in image resize tests.
This makes sure there are no leftover images in case of a test failure. Follow-up to [161/tests], [1255/tests]. See #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@53463 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -23,13 +23,14 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase
|
||||
public function test_resize_jpg() {
|
||||
$image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.jpg', 25, 25 );
|
||||
|
||||
list( $w, $h, $type ) = getimagesize( $image );
|
||||
|
||||
unlink( $image );
|
||||
|
||||
$this->assertSame( 'test-image-25x25.jpg', wp_basename( $image ) );
|
||||
list($w, $h, $type) = getimagesize( $image );
|
||||
$this->assertSame( 25, $w );
|
||||
$this->assertSame( 25, $h );
|
||||
$this->assertSame( IMAGETYPE_JPEG, $type );
|
||||
|
||||
unlink( $image );
|
||||
}
|
||||
|
||||
public function test_resize_png() {
|
||||
@@ -39,13 +40,14 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase
|
||||
$this->fail( sprintf( 'No PNG support in the editor engine %s on this system.', $this->editor_engine ) );
|
||||
}
|
||||
|
||||
list( $w, $h, $type ) = getimagesize( $image );
|
||||
|
||||
unlink( $image );
|
||||
|
||||
$this->assertSame( 'test-image-25x25.png', wp_basename( $image ) );
|
||||
list($w, $h, $type) = getimagesize( $image );
|
||||
$this->assertSame( 25, $w );
|
||||
$this->assertSame( 25, $h );
|
||||
$this->assertSame( IMAGETYPE_PNG, $type );
|
||||
|
||||
unlink( $image );
|
||||
}
|
||||
|
||||
public function test_resize_gif() {
|
||||
@@ -55,13 +57,14 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase
|
||||
$this->fail( sprintf( 'No GIF support in the editor engine %s on this system.', $this->editor_engine ) );
|
||||
}
|
||||
|
||||
list( $w, $h, $type ) = getimagesize( $image );
|
||||
|
||||
unlink( $image );
|
||||
|
||||
$this->assertSame( 'test-image-25x25.gif', wp_basename( $image ) );
|
||||
list($w, $h, $type) = getimagesize( $image );
|
||||
$this->assertSame( 25, $w );
|
||||
$this->assertSame( 25, $h );
|
||||
$this->assertSame( IMAGETYPE_GIF, $type );
|
||||
|
||||
unlink( $image );
|
||||
}
|
||||
|
||||
public function test_resize_webp() {
|
||||
@@ -74,12 +77,15 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase
|
||||
}
|
||||
|
||||
$image = $this->resize_helper( $file, 25, 25 );
|
||||
|
||||
list( $w, $h, $type ) = wp_getimagesize( $image );
|
||||
|
||||
unlink( $image );
|
||||
|
||||
$this->assertSame( 'test-image-25x25.webp', wp_basename( $image ) );
|
||||
list($w, $h, $type) = wp_getimagesize( $image );
|
||||
$this->assertSame( 25, $w );
|
||||
$this->assertSame( 25, $h );
|
||||
$this->assertSame( IMAGETYPE_WEBP, $type );
|
||||
unlink( $image );
|
||||
}
|
||||
|
||||
public function test_resize_larger() {
|
||||
@@ -93,73 +99,79 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase
|
||||
public function test_resize_thumb_128x96() {
|
||||
$image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 96 );
|
||||
|
||||
list( $w, $h, $type ) = getimagesize( $image );
|
||||
|
||||
unlink( $image );
|
||||
|
||||
$this->assertSame( '2007-06-17DSC_4173-64x96.jpg', wp_basename( $image ) );
|
||||
list($w, $h, $type) = getimagesize( $image );
|
||||
$this->assertSame( 64, $w );
|
||||
$this->assertSame( 96, $h );
|
||||
$this->assertSame( IMAGETYPE_JPEG, $type );
|
||||
|
||||
unlink( $image );
|
||||
}
|
||||
|
||||
public function test_resize_thumb_128x0() {
|
||||
$image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 0 );
|
||||
|
||||
list( $w, $h, $type ) = getimagesize( $image );
|
||||
|
||||
unlink( $image );
|
||||
|
||||
$this->assertSame( '2007-06-17DSC_4173-128x193.jpg', wp_basename( $image ) );
|
||||
list($w, $h, $type) = getimagesize( $image );
|
||||
$this->assertSame( 128, $w );
|
||||
$this->assertSame( 193, $h );
|
||||
$this->assertSame( IMAGETYPE_JPEG, $type );
|
||||
|
||||
unlink( $image );
|
||||
}
|
||||
|
||||
public function test_resize_thumb_0x96() {
|
||||
$image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 0, 96 );
|
||||
|
||||
list( $w, $h, $type ) = getimagesize( $image );
|
||||
|
||||
unlink( $image );
|
||||
|
||||
$this->assertSame( '2007-06-17DSC_4173-64x96.jpg', wp_basename( $image ) );
|
||||
list($w, $h, $type) = getimagesize( $image );
|
||||
$this->assertSame( 64, $w );
|
||||
$this->assertSame( 96, $h );
|
||||
$this->assertSame( IMAGETYPE_JPEG, $type );
|
||||
|
||||
unlink( $image );
|
||||
}
|
||||
|
||||
public function test_resize_thumb_150x150_crop() {
|
||||
$image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 150, 150, true );
|
||||
|
||||
list( $w, $h, $type ) = getimagesize( $image );
|
||||
|
||||
unlink( $image );
|
||||
|
||||
$this->assertSame( '2007-06-17DSC_4173-150x150.jpg', wp_basename( $image ) );
|
||||
list($w, $h, $type) = getimagesize( $image );
|
||||
$this->assertSame( 150, $w );
|
||||
$this->assertSame( 150, $h );
|
||||
$this->assertSame( IMAGETYPE_JPEG, $type );
|
||||
|
||||
unlink( $image );
|
||||
}
|
||||
|
||||
public function test_resize_thumb_150x100_crop() {
|
||||
$image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 150, 100, true );
|
||||
|
||||
list( $w, $h, $type ) = getimagesize( $image );
|
||||
|
||||
unlink( $image );
|
||||
|
||||
$this->assertSame( '2007-06-17DSC_4173-150x100.jpg', wp_basename( $image ) );
|
||||
list($w, $h, $type) = getimagesize( $image );
|
||||
$this->assertSame( 150, $w );
|
||||
$this->assertSame( 100, $h );
|
||||
$this->assertSame( IMAGETYPE_JPEG, $type );
|
||||
|
||||
unlink( $image );
|
||||
}
|
||||
|
||||
public function test_resize_thumb_50x150_crop() {
|
||||
$image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 50, 150, true );
|
||||
|
||||
list( $w, $h, $type ) = getimagesize( $image );
|
||||
|
||||
unlink( $image );
|
||||
|
||||
$this->assertSame( '2007-06-17DSC_4173-50x150.jpg', wp_basename( $image ) );
|
||||
list($w, $h, $type) = getimagesize( $image );
|
||||
$this->assertSame( 50, $w );
|
||||
$this->assertSame( 150, $h );
|
||||
$this->assertSame( IMAGETYPE_JPEG, $type );
|
||||
|
||||
unlink( $image );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,6 +197,7 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase
|
||||
}
|
||||
|
||||
$resized = $editor->resize( $width, $height, $crop );
|
||||
|
||||
if ( is_wp_error( $resized ) ) {
|
||||
return $resized;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user