From b3d15125a6a761fedf21953edfeb410ca50591b3 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 8 Oct 2016 01:19:11 +0000 Subject: [PATCH] Build/Test Tools: Make use of PHPUnit's `@requires` notation. Fixes #38256 git-svn-id: https://develop.svn.wordpress.org/trunk@38759 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/http/functions.php | 9 ++----- tests/phpunit/tests/image/functions.php | 36 +++++++++---------------- tests/phpunit/tests/image/meta.php | 12 +++------ 3 files changed, 18 insertions(+), 39 deletions(-) diff --git a/tests/phpunit/tests/http/functions.php b/tests/phpunit/tests/http/functions.php index 79e0727460..9a2b1ba172 100644 --- a/tests/phpunit/tests/http/functions.php +++ b/tests/phpunit/tests/http/functions.php @@ -3,15 +3,10 @@ /** * @group http * @group external-http + * + * @requires extension openssl */ class Tests_HTTP_Functions extends WP_UnitTestCase { - public function setUp() { - if ( ! extension_loaded( 'openssl' ) ) { - $this->markTestSkipped( 'Tests_HTTP_Functions requires openssl.' ); - } - - parent::setUp(); - } function test_head_request() { // this url give a direct 200 response diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php index 9cc3f09d2a..0f2ae01e1c 100644 --- a/tests/phpunit/tests/image/functions.php +++ b/tests/phpunit/tests/image/functions.php @@ -108,12 +108,10 @@ class Tests_Image_Functions extends WP_UnitTestCase { /** * Test save image file and mime_types * @ticket 6821 + * + * @requires extension fileinfo */ public function test_wp_save_image_file() { - if ( ! extension_loaded( 'fileinfo' ) ) { - $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' ); - } - include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); // Mime types @@ -160,12 +158,10 @@ class Tests_Image_Functions extends WP_UnitTestCase { /** * Test that a passed mime type overrides the extension in the filename * @ticket 6821 + * + * @requires extension fileinfo */ public function test_mime_overrides_filename() { - if ( ! extension_loaded( 'fileinfo' ) ) { - $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' ); - } - // Test each image editor engine $classes = array('WP_Image_Editor_GD', 'WP_Image_Editor_Imagick'); foreach ( $classes as $class ) { @@ -198,12 +194,10 @@ class Tests_Image_Functions extends WP_UnitTestCase { /** * Test that mime types are correctly inferred from file extensions * @ticket 6821 + * + * @requires extension fileinfo */ public function test_inferred_mime_types() { - if ( ! extension_loaded( 'fileinfo' ) ) { - $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' ); - } - // Mime types $mime_types = array( 'jpg' => 'image/jpeg', @@ -296,14 +290,11 @@ class Tests_Image_Functions extends WP_UnitTestCase { unlink( $file ); } + /** + * @requires extension openssl + * @requires function imagejpeg + */ public function test_wp_crop_image_url() { - if ( !function_exists( 'imagejpeg' ) ) - $this->markTestSkipped( 'jpeg support unavailable' ); - - if ( ! extension_loaded( 'openssl' ) ) { - $this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url() requires openssl.' ); - } - $file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canola.jpg', 0, 0, 100, 100, 100, 100, false, DIR_TESTDATA . '/images/' . rand_str() . '.jpg' ); @@ -323,11 +314,10 @@ class Tests_Image_Functions extends WP_UnitTestCase { $this->assertInstanceOf( 'WP_Error', $file ); } + /** + * @requires extension openssl + */ public function test_wp_crop_image_url_not_exist() { - if ( ! extension_loaded( 'openssl' ) ) { - $this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url_not_exist() requires openssl.' ); - } - $file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg', 0, 0, 100, 100, 100, 100 ); $this->assertInstanceOf( 'WP_Error', $file ); diff --git a/tests/phpunit/tests/image/meta.php b/tests/phpunit/tests/image/meta.php index 30613d48a8..a29c4a3e35 100644 --- a/tests/phpunit/tests/image/meta.php +++ b/tests/phpunit/tests/image/meta.php @@ -4,17 +4,11 @@ * @group image * @group media * @group upload + * + * @requires extension gd + * @requires extension exif */ class Tests_Image_Meta extends WP_UnitTestCase { - function setUp() { - if ( ! extension_loaded( 'gd' ) ) - $this->markTestSkipped( 'The gd PHP extension is not loaded.' ); - if ( ! extension_loaded( 'exif' ) ) - $this->markTestSkipped( 'The exif PHP extension is not loaded.' ); - if ( ! is_callable( 'wp_read_image_metadata' ) ) - $this->markTestSkipped( 'wp_read_image_metadata() is not callable.' ); - parent::setUp(); - } function test_exif_d70() { // exif from a Nikon D70