Make WordPress Core

Changeset 25402


Ignore:
Timestamp:
09/12/2013 02:47:58 PM (11 years ago)
Author:
wonderboymusic
Message:

There was way too much duplicated code in my notice cleanup, it built up over time, and there's definitely a need to standardize.

  • Remove duplicated code for deprecated function notice suppression
  • Add support in WP_UnitTestCase setUp/tearDown methods for $deprecated_functions fixture if the extending class has added it
  • Add a $deprecated_functions fixture to each extending class that needs it

To use this fixture, add something to your Test Case class like so:
protected $deprecated_functions = array( 'get_theme', 'get_themes', 'get_theme_data', 'get_current_theme' );

See #25282.

Location:
trunk/tests/phpunit
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r25017 r25402  
    77
    88    protected static $forced_tickets = array();
     9    protected $deprecated_functions = array();
    910
    1011    /**
     
    2526        $this->start_transaction();
    2627        add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
     28
     29        if ( ! empty( $this->deprecated_functions ) )
     30            add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    2731    }
    2832
     
    3337        remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
    3438        remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
     39        if ( ! empty( $this->deprecated_functions ) )
     40            remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
     41    }
     42
     43    function deprecated_function_run( $function ) {
     44        if ( in_array( $function, $this->deprecated_functions ) )
     45            add_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
     46    }
     47
     48    function deprecated_function_trigger_error() {
     49        remove_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
     50        return false;
    3551    }
    3652
  • trunk/tests/phpunit/tests/admin/includesTheme.php

    r25362 r25402  
    44 */
    55class Tests_Admin_includesTheme extends WP_UnitTestCase {
     6    protected $deprecated_functions = array( 'get_theme', 'get_themes', 'get_theme_data', 'get_current_theme' );
     7
    68    function setUp() {
    79        parent::setUp();
     
    1820        wp_clean_themes_cache();
    1921        unset( $GLOBALS['wp_themes'] );
    20        
    21         add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run_check' ) );
    22     }
    23 
    24     function deprecated_function_run_check( $function ) {
    25         if ( in_array( $function, array( 'get_theme', 'get_themes', 'get_theme_data', 'get_current_theme' ) ) )
    26             add_filter( 'deprecated_function_trigger_error', array( $this, 'filter_deprecated_function_trigger_error' ) );
    27     }
    28 
    29     function filter_deprecated_function_trigger_error() {
    30         remove_filter( 'deprecated_function_trigger_error', array( $this, 'filter_deprecated_function_trigger_error' ) );
    31         return false;
    3222    }
    3323
  • trunk/tests/phpunit/tests/formatting/CleanPre.php

    r25378 r25402  
    88 */
    99class Tests_Formatting_CleanPre extends WP_UnitTestCase {
    10     function setUp() {
    11         parent::setUp();
    12         add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run_check' ) );
    13     }
    14 
    15     function tearDown() {
    16         parent::tearDown();
    17         remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run_check' ) );
    18     }
    19 
    20     function deprecated_function_run_check( $function ) {
    21         if ( in_array( $function, array( 'clean_pre' ) ) )
    22             add_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
    23     }
    24 
    25     function deprecated_function_trigger_error() {
    26         remove_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
    27         return false;
    28     }
     10    protected $deprecated_functions = array( 'clean_pre' );
    2911
    3012    function test_removes_self_closing_br_with_space() {
  • trunk/tests/phpunit/tests/image/functions.php

    r25380 r25402  
    77 */
    88class Tests_Image_Functions extends WP_UnitTestCase {
     9    protected $deprecated_functions = array( 'wp_load_image' );
     10
    911    /**
    1012     * Setup test fixture
     
    1820
    1921        include_once( DIR_TESTDATA . '/../includes/mock-image-editor.php' );
    20         add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    21     }
    22 
    23     function tearDown() {
    24         parent::tearDown();
    25         remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    26     }
    27 
    28     function deprecated_function_run( $function ) {
    29         if ( in_array( $function, array( 'wp_load_image' ) ) )
    30             add_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
    31     }
    32 
    33     function deprecated_function_trigger_error() {
    34         remove_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
    35         return false;
    3622    }
    3723
  • trunk/tests/phpunit/tests/image/size.php

    r25367 r25402  
    77 */
    88class Tests_Image_Size extends WP_UnitTestCase {
    9     function setUp() {
    10         parent::setUp();
    11 
    12         add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run_check' ) );
    13     }
    14 
    15     function tearDown() {
    16         parent::tearDown();
    17 
    18         remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run_check' ) );
    19     }
    20 
    21     function deprecated_function_run_check( $function ) {
    22         if ( in_array( $function, array( 'wp_shrink_dimensions' ) ) )
    23             add_filter( 'deprecated_function_trigger_error', array( $this, 'filter_deprecated_function_trigger_error' ) );
    24     }
    25 
    26     function filter_deprecated_function_trigger_error() {
    27         remove_filter( 'deprecated_function_trigger_error', array( $this, 'filter_deprecated_function_trigger_error' ) );
    28         return false;
    29     }
    30 
     9    protected $deprecated_functions = array( 'wp_shrink_dimensions' );
     10   
    3111    function test_constrain_dims_zero() {
    3212        if (!is_callable('wp_constrain_dimensions'))
  • trunk/tests/phpunit/tests/media.php

    r25382 r25402  
    66 */
    77class Tests_Media extends WP_UnitTestCase {
     8    protected $deprecated_functions = array( 'wp_convert_bytes_to_hr' );
    89
    910    function setUp() {
     
    2021        $this->img_html = '<img src="' . $this->img_url . '"/>';
    2122        $this->img_dimensions = array( 'width' => 100, 'height' => 100 );
    22         add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    23     }
    24 
    25     function tearDown() {
    26         parent::tearDown();
    27         remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    28     }
    29 
    30     function deprecated_function_run( $function ) {
    31         if ( in_array( $function, array( 'wp_convert_bytes_to_hr' ) ) )
    32             add_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
    33     }
    34 
    35     function deprecated_function_trigger_error() {
    36         remove_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
    37         return false;
    3823    }
    3924
  • trunk/tests/phpunit/tests/ms.php

    r25397 r25402  
    99 */
    1010class Tests_MS extends WP_UnitTestCase {
    11 
     11    protected $deprecated_functions = array( 'is_blog_user', 'get_dashboard_blog' );
    1212    protected $plugin_hook_count = 0;
    1313
     
    1616
    1717        $_SERVER['REMOTE_ADDR'] = '';
    18         add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run_check' ) );
    19     }
    20 
    21     function tearDown() {
    22         parent::tearDown();
    23         remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run_check' ) );
    24     }
    25 
    26     function deprecated_function_run_check( $function ) {
    27         if ( in_array( $function, array( 'is_blog_user', 'get_dashboard_blog' ) ) )
    28             add_filter( 'deprecated_function_trigger_error', array( $this, 'filter_deprecated_function_trigger_error' ) );
    29     }
    30 
    31     function filter_deprecated_function_trigger_error() {
    32         remove_filter( 'deprecated_function_trigger_error', array( $this, 'filter_deprecated_function_trigger_error' ) );
    33         return false;
    3418    }
    3519
  • trunk/tests/phpunit/tests/theme.php

    r25388 r25402  
    77 */
    88class Tests_Theme extends WP_UnitTestCase {
    9 
    10     var $theme_slug = 'twentyeleven';
    11     var $theme_name = 'Twenty Eleven';
     9    protected $deprecated_functions = array( 'get_theme', 'get_themes', 'get_theme_data', 'get_current_theme' );
     10    protected $theme_slug = 'twentyeleven';
     11    protected $theme_name = 'Twenty Eleven';
    1212
    1313    function setUp() {
     
    1616        wp_clean_themes_cache();
    1717        unset( $GLOBALS['wp_themes'] );
    18 
    19         add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    2018    }
    2119
     
    2523        unset( $GLOBALS['wp_themes'] );
    2624        parent::tearDown();
    27 
    28         remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    29     }
    30 
    31     function deprecated_function_run( $function ) {
    32         if ( in_array( $function, array( 'get_theme', 'get_themes', 'get_theme_data', 'get_current_theme' ) ) )
    33             add_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
    34     }
    35 
    36     function deprecated_function_trigger_error() {
    37         remove_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
    38         return false;
    3925    }
    4026
  • trunk/tests/phpunit/tests/theme/themeDir.php

    r25388 r25402  
    77 */
    88class Tests_Theme_ThemeDir extends WP_UnitTestCase {
     9    protected $deprecated_functions = array( 'get_theme', 'get_themes', 'get_theme_data', 'get_current_theme', 'get_broken_themes' );
     10
    911    function setUp() {
    1012        parent::setUp();
     
    2224        wp_clean_themes_cache();
    2325        unset( $GLOBALS['wp_themes'] );
    24         add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    2526    }
    2627
     
    3334        unset( $GLOBALS['wp_themes'] );
    3435        parent::tearDown();
    35         remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    36     }
    37 
    38     function deprecated_function_run( $function ) {
    39         if ( in_array( $function, array( 'get_theme', 'get_themes', 'get_theme_data', 'get_current_theme', 'get_broken_themes' ) ) )
    40             add_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
    41     }
    42 
    43     function deprecated_function_trigger_error() {
    44         remove_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
    45         return false;
    4636    }
    4737
  • trunk/tests/phpunit/tests/user/capabilities.php

    r25391 r25402  
    88 */
    99class Tests_User_Capabilities extends WP_UnitTestCase {
    10     var $user_ids = array();
     10    protected $user_ids = array();
     11    protected $deprecated_functions = array( 'set_current_user' );
    1112
    1213    function setUp() {
     
    1617
    1718        $this->orig_users = get_users();
    18         add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    19     }
    20 
    21     function tearDown() {
    22         parent::tearDown();
    23         remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    24     }
    25 
    26     function deprecated_function_run( $function ) {
    27         if ( in_array( $function, array( 'set_current_user' ) ) )
    28             add_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
    29     }
    30 
    31     function deprecated_function_trigger_error() {
    32         remove_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
    33         return false;
    3419    }
    3520
Note: See TracChangeset for help on using the changeset viewer.