Tests: Convert a few more function_exists() and extension_loaded() checks to @requires annotations.

This better utilizes the PHPUnit native functionality.

Follow-up to [49024].

See #50639, #50640.

git-svn-id: https://develop.svn.wordpress.org/trunk@49025 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-09-21 13:25:38 +00:00
parent b984a64c98
commit 6242c634ee
9 changed files with 27 additions and 82 deletions

View File

@ -54,13 +54,11 @@ class Tests_Ajax_CompressionTest extends WP_Ajax_UnitTestCase {
/**
* Fetch the test text (gzdeflate)
*
* @requires function gzdeflate
*/
public function test_gzdeflate() {
if ( ! function_exists( 'gzdeflate' ) ) {
$this->fail( 'gzdeflate function not available' );
}
// Become an administrator.
$this->_setRole( 'administrator' );
@ -81,13 +79,11 @@ class Tests_Ajax_CompressionTest extends WP_Ajax_UnitTestCase {
/**
* Fetch the test text (gzencode)
*
* @requires function gzencode
*/
public function test_gzencode() {
if ( ! function_exists( 'gzencode' ) ) {
$this->fail( 'gzencode function not available' );
}
// Become an administrator.
$this->_setRole( 'administrator' );

View File

@ -70,13 +70,10 @@ class Tests_Ajax_Response extends WP_UnitTestCase {
* @runInSeparateProcess
* @preserveGlobalState disabled
* @group xdebug
* @requires function xdebug_get_headers
*/
public function test_response_charset_in_header() {
if ( ! function_exists( 'xdebug_get_headers' ) ) {
$this->markTestSkipped( 'xdebug is required for this test' );
}
// Generate an Ajax response.
ob_start();
$ajax_response = new WP_Ajax_Response();

View File

@ -942,12 +942,9 @@ class Tests_Functions extends WP_UnitTestCase {
/**
* @ticket 28786
* @requires function mb_detect_order
*/
function test_wp_json_encode_non_utf8() {
if ( ! function_exists( 'mb_detect_order' ) ) {
$this->markTestSkipped( 'mbstring extension not available.' );
}
$charsets = mb_detect_order();
$old_charsets = $charsets;
if ( ! in_array( 'EUC-JP', $charsets, true ) ) {
@ -967,12 +964,9 @@ class Tests_Functions extends WP_UnitTestCase {
/**
* @ticket 28786
* @requires function mb_detect_order
*/
function test_wp_json_encode_non_utf8_in_array() {
if ( ! function_exists( 'mb_detect_order' ) ) {
$this->markTestSkipped( 'mbstring extension not available.' );
}
$charsets = mb_detect_order();
$old_charsets = $charsets;
if ( ! in_array( 'EUC-JP', $charsets, true ) ) {
@ -1210,24 +1204,18 @@ class Tests_Functions extends WP_UnitTestCase {
/**
* @ticket 39550
* @dataProvider _wp_check_filetype_and_ext_data
* @requires extension fileinfo
*/
function test_wp_check_filetype_and_ext( $file, $filename, $expected ) {
if ( ! extension_loaded( 'fileinfo' ) ) {
$this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
}
$this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) );
}
/**
* @ticket 39550
* @group ms-excluded
* @requires extension fileinfo
*/
function test_wp_check_filetype_and_ext_with_filtered_svg() {
if ( ! extension_loaded( 'fileinfo' ) ) {
$this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
}
$file = DIR_TESTDATA . '/uploads/video-play.svg';
$filename = 'video-play.svg';
@ -1247,12 +1235,9 @@ class Tests_Functions extends WP_UnitTestCase {
/**
* @ticket 39550
* @group ms-excluded
* @requires extension fileinfo
*/
function test_wp_check_filetype_and_ext_with_filtered_woff() {
if ( ! extension_loaded( 'fileinfo' ) ) {
$this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
}
$file = DIR_TESTDATA . '/uploads/dashicons.woff';
$filename = 'dashicons.woff';

View File

@ -25,15 +25,13 @@ class Tests_Functions_Anonymization extends WP_UnitTestCase {
*
* @ticket 41083
* @ticket 43545
* @requires function inet_ntop
* @requires function inet_pton
*
* @param string $raw_ip Raw IP address.
* @param string $expected_result Expected result.
*/
public function test_wp_privacy_anonymize_ip( $raw_ip, $expected_result ) {
if ( ! function_exists( 'inet_ntop' ) || ! function_exists( 'inet_pton' ) ) {
$this->markTestSkipped( 'This test requires both the inet_ntop() and inet_pton() functions.' );
}
$actual_result = wp_privacy_anonymize_data( 'ip', $raw_ip );
/* Todo test ipv6_fallback mode if keeping it.*/

View File

@ -3,17 +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 gives a direct 200 response.
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';

View File

@ -548,12 +548,9 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase {
* Test resetting Exif orientation data on rotate
*
* @ticket 37140
* @requires function exif_read_data
*/
public function test_remove_orientation_data_on_rotate() {
if ( ! function_exists( 'exif_read_data' ) ) {
$this->markTestSkipped( 'This test requires the exif_read_data function.' );
}
$file = DIR_TESTDATA . '/images/test-image-upside-down.jpg';
$data = wp_read_image_metadata( $file );

View File

@ -149,12 +149,9 @@ 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.' );
}
$classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
foreach ( $classes as $key => $class ) {
@ -208,12 +205,9 @@ 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.' );
}
$classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
foreach ( $classes as $key => $class ) {
@ -253,12 +247,9 @@ 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.' );
}
$classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
foreach ( $classes as $key => $class ) {
@ -373,12 +364,9 @@ class Tests_Image_Functions extends WP_UnitTestCase {
/**
* @requires function imagejpeg
* @requires extension openssl
*/
public function test_wp_crop_image_url() {
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,
@ -418,11 +406,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,

View File

@ -4,18 +4,10 @@
* @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.' );
}
parent::setUp();
}
function test_exif_d70() {
// Exif from a Nikon D70.

View File

@ -8,11 +8,11 @@
* @group xdebug
*/
class Tests_oEmbed_HTTP_Headers extends WP_UnitTestCase {
function test_rest_pre_serve_request_headers() {
if ( ! function_exists( 'xdebug_get_headers' ) ) {
$this->markTestSkipped( 'xdebug is required for this test' );
}
/**
* @requires function xdebug_get_headers
*/
function test_rest_pre_serve_request_headers() {
$post = $this->factory()->post->create_and_get(
array(
'post_title' => 'Hello World',