Tests: Consistently require `imagejpeg()` function in `image_make_intermediate_size()` tests.

This outputs a proper message if the requirement is not met, instead of an obscure PHP error further in the test.

See #50639, #50640.

git-svn-id: https://develop.svn.wordpress.org/trunk@49010 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-09-20 03:31:46 +00:00
parent 58385f1402
commit 8493793928
1 changed files with 32 additions and 0 deletions

View File

@ -69,6 +69,10 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
* @ticket 17626
*/
function test_get_intermediate_sizes_by_name() {
if ( ! function_exists( 'imagejpeg' ) ) {
$this->fail( 'jpeg support unavailable' );
}
add_image_size( 'test-size', 330, 220, true );
$file = DIR_TESTDATA . '/images/waffles.jpg';
@ -89,6 +93,10 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
* @ticket 17626
*/
function test_get_intermediate_sizes_by_array_exact() {
if ( ! function_exists( 'imagejpeg' ) ) {
$this->fail( 'jpeg support unavailable' );
}
// Only one dimention match shouldn't return false positive (see: #17626).
add_image_size( 'test-size', 330, 220, true );
add_image_size( 'false-height', 330, 400, true );
@ -110,6 +118,10 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
* @ticket 17626
*/
function test_get_intermediate_sizes_by_array_nearest() {
if ( ! function_exists( 'imagejpeg' ) ) {
$this->fail( 'jpeg support unavailable' );
}
// If an exact size is not found, it should be returned.
// If not, find nearest size that is larger (see: #17626).
add_image_size( 'test-size', 450, 300, true );
@ -153,6 +165,10 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
* @ticket 17626
*/
function test_get_intermediate_sizes_by_array_zero_height() {
if ( ! function_exists( 'imagejpeg' ) ) {
$this->fail( 'jpeg support unavailable' );
}
// Generate random width.
$random_w = rand( 300, 400 );
@ -181,6 +197,10 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
* @ticket 34087
*/
function test_get_intermediate_sizes_by_array_zero_width() {
if ( ! function_exists( 'imagejpeg' ) ) {
$this->fail( 'jpeg support unavailable' );
}
// 202 is the smallest height that will trigger a miss for 'false-height'.
$height = 202;
@ -209,6 +229,10 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
* @ticket 34087
*/
public function test_get_intermediate_sizes_should_match_size_with_off_by_one_aspect_ratio() {
if ( ! function_exists( 'imagejpeg' ) ) {
$this->fail( 'jpeg support unavailable' );
}
// Original is 600x400. 300x201 is close enough to match.
$width = 300;
$height = 201;
@ -232,6 +256,10 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
* @ticket 34384
*/
public function test_get_intermediate_size_with_small_size_array() {
if ( ! function_exists( 'imagejpeg' ) ) {
$this->fail( 'jpeg support unavailable' );
}
// Add a hard cropped size that matches the aspect ratio we're going to test.
add_image_size( 'test-size', 200, 100, true );
@ -249,6 +277,10 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
* @ticket 34384
*/
public function test_get_intermediate_size_with_small_size_array_fallback() {
if ( ! function_exists( 'imagejpeg' ) ) {
$this->fail( 'jpeg support unavailable' );
}
$file = DIR_TESTDATA . '/images/waffles.jpg';
$id = $this->_make_attachment( $file, 0 );