Make WordPress Core


Ignore:
Timestamp:
09/12/2013 02:47:58 PM (13 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.