WordPress.org

Make WordPress Core

Changeset 49025


Ignore:
Timestamp:
09/21/2020 01:25:38 PM (2 months ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk/tests/phpunit/tests
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/Compression.php

    r48997 r49025  
    5555    /**
    5656     * Fetch the test text (gzdeflate)
     57     *
     58     * @requires function gzdeflate
    5759     */
    5860    public function test_gzdeflate() {
    59 
    60         if ( ! function_exists( 'gzdeflate' ) ) {
    61             $this->fail( 'gzdeflate function not available' );
    62         }
    6361
    6462        // Become an administrator.
     
    8280    /**
    8381     * Fetch the test text (gzencode)
     82     *
     83     * @requires function gzencode
    8484     */
    8585    public function test_gzencode() {
    86 
    87         if ( ! function_exists( 'gzencode' ) ) {
    88             $this->fail( 'gzencode function not available' );
    89         }
    9086
    9187        // Become an administrator.
  • trunk/tests/phpunit/tests/ajax/Response.php

    r47122 r49025  
    7171     * @preserveGlobalState disabled
    7272     * @group xdebug
     73     * @requires function xdebug_get_headers
    7374     */
    7475    public function test_response_charset_in_header() {
    75 
    76         if ( ! function_exists( 'xdebug_get_headers' ) ) {
    77             $this->markTestSkipped( 'xdebug is required for this test' );
    78         }
    7976
    8077        // Generate an Ajax response.
  • trunk/tests/phpunit/tests/functions.php

    r48937 r49025  
    943943    /**
    944944     * @ticket 28786
     945     * @requires function mb_detect_order
    945946     */
    946947    function test_wp_json_encode_non_utf8() {
    947         if ( ! function_exists( 'mb_detect_order' ) ) {
    948             $this->markTestSkipped( 'mbstring extension not available.' );
    949         }
    950 
    951948        $charsets     = mb_detect_order();
    952949        $old_charsets = $charsets;
     
    968965    /**
    969966     * @ticket 28786
     967     * @requires function mb_detect_order
    970968     */
    971969    function test_wp_json_encode_non_utf8_in_array() {
    972         if ( ! function_exists( 'mb_detect_order' ) ) {
    973             $this->markTestSkipped( 'mbstring extension not available.' );
    974         }
    975 
    976970        $charsets     = mb_detect_order();
    977971        $old_charsets = $charsets;
     
    12111205     * @ticket 39550
    12121206     * @dataProvider _wp_check_filetype_and_ext_data
     1207     * @requires extension fileinfo
    12131208     */
    12141209    function test_wp_check_filetype_and_ext( $file, $filename, $expected ) {
    1215         if ( ! extension_loaded( 'fileinfo' ) ) {
    1216             $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
    1217         }
    1218 
    12191210        $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) );
    12201211    }
     
    12231214     * @ticket 39550
    12241215     * @group ms-excluded
     1216     * @requires extension fileinfo
    12251217     */
    12261218    function test_wp_check_filetype_and_ext_with_filtered_svg() {
    1227         if ( ! extension_loaded( 'fileinfo' ) ) {
    1228             $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
    1229         }
    1230 
    12311219        $file     = DIR_TESTDATA . '/uploads/video-play.svg';
    12321220        $filename = 'video-play.svg';
     
    12481236     * @ticket 39550
    12491237     * @group ms-excluded
     1238     * @requires extension fileinfo
    12501239     */
    12511240    function test_wp_check_filetype_and_ext_with_filtered_woff() {
    1252         if ( ! extension_loaded( 'fileinfo' ) ) {
    1253             $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
    1254         }
    1255 
    12561241        $file     = DIR_TESTDATA . '/uploads/dashicons.woff';
    12571242        $filename = 'dashicons.woff';
  • trunk/tests/phpunit/tests/functions/anonymization.php

    r49006 r49025  
    2626     * @ticket 41083
    2727     * @ticket 43545
     28     * @requires function inet_ntop
     29     * @requires function inet_pton
    2830     *
    2931     * @param string $raw_ip          Raw IP address.
     
    3133     */
    3234    public function test_wp_privacy_anonymize_ip( $raw_ip, $expected_result ) {
    33         if ( ! function_exists( 'inet_ntop' ) || ! function_exists( 'inet_pton' ) ) {
    34             $this->markTestSkipped( 'This test requires both the inet_ntop() and inet_pton() functions.' );
    35         }
    36 
    3735        $actual_result = wp_privacy_anonymize_data( 'ip', $raw_ip );
    3836
  • trunk/tests/phpunit/tests/http/functions.php

    r48937 r49025  
    44 * @group http
    55 * @group external-http
     6 * @requires extension openssl
    67 */
    78class Tests_HTTP_Functions extends WP_UnitTestCase {
    8 
    9     public function setUp() {
    10         if ( ! extension_loaded( 'openssl' ) ) {
    11             $this->markTestSkipped( 'Tests_HTTP_Functions requires openssl.' );
    12         }
    13 
    14         parent::setUp();
    15     }
    169
    1710    function test_head_request() {
  • trunk/tests/phpunit/tests/image/editorImagick.php

    r48937 r49025  
    549549     *
    550550     * @ticket 37140
     551     * @requires function exif_read_data
    551552     */
    552553    public function test_remove_orientation_data_on_rotate() {
    553         if ( ! function_exists( 'exif_read_data' ) ) {
    554             $this->markTestSkipped( 'This test requires the exif_read_data function.' );
    555         }
    556 
    557554        $file = DIR_TESTDATA . '/images/test-image-upside-down.jpg';
    558555        $data = wp_read_image_metadata( $file );
  • trunk/tests/phpunit/tests/image/functions.php

    r49024 r49025  
    150150     *
    151151     * @ticket 6821
     152     * @requires extension fileinfo
    152153     */
    153154    public function test_wp_save_image_file() {
    154         if ( ! extension_loaded( 'fileinfo' ) ) {
    155             $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
    156         }
    157 
    158155        $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
    159156
     
    209206     *
    210207     * @ticket 6821
     208     * @requires extension fileinfo
    211209     */
    212210    public function test_mime_overrides_filename() {
    213         if ( ! extension_loaded( 'fileinfo' ) ) {
    214             $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
    215         }
    216 
    217211        $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
    218212
     
    254248     *
    255249     * @ticket 6821
     250     * @requires extension fileinfo
    256251     */
    257252    public function test_inferred_mime_types() {
    258         if ( ! extension_loaded( 'fileinfo' ) ) {
    259             $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
    260         }
    261 
    262253        $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
    263254
     
    374365    /**
    375366     * @requires function imagejpeg
     367     * @requires extension openssl
    376368     */
    377369    public function test_wp_crop_image_url() {
    378         if ( ! extension_loaded( 'openssl' ) ) {
    379             $this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url() requires openssl.' );
    380         }
    381 
    382370        $file = wp_crop_image(
    383371            'https://asdftestblog1.files.wordpress.com/2008/04/canola.jpg',
     
    419407    }
    420408
     409    /**
     410     * @requires extension openssl
     411     */
    421412    public function test_wp_crop_image_url_not_exist() {
    422         if ( ! extension_loaded( 'openssl' ) ) {
    423             $this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url_not_exist() requires openssl.' );
    424         }
    425 
    426413        $file = wp_crop_image(
    427414            'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg',
  • trunk/tests/phpunit/tests/image/meta.php

    r48937 r49025  
    55 * @group media
    66 * @group upload
     7 * @requires extension gd
     8 * @requires extension exif
    79 */
    810class Tests_Image_Meta extends WP_UnitTestCase {
    9     function setUp() {
    10         if ( ! extension_loaded( 'gd' ) ) {
    11             $this->markTestSkipped( 'The gd PHP extension is not loaded.' );
    12         }
    13         if ( ! extension_loaded( 'exif' ) ) {
    14             $this->markTestSkipped( 'The exif PHP extension is not loaded.' );
    15         }
    16 
    17         parent::setUp();
    18     }
    1911
    2012    function test_exif_d70() {
  • trunk/tests/phpunit/tests/oembed/headers.php

    r46586 r49025  
    99 */
    1010class Tests_oEmbed_HTTP_Headers extends WP_UnitTestCase {
     11
     12    /**
     13     * @requires function xdebug_get_headers
     14     */
    1115    function test_rest_pre_serve_request_headers() {
    12         if ( ! function_exists( 'xdebug_get_headers' ) ) {
    13             $this->markTestSkipped( 'xdebug is required for this test' );
    14         }
    15 
    1616        $post = $this->factory()->post->create_and_get(
    1717            array(
Note: See TracChangeset for help on using the changeset viewer.