Make WordPress Core

Changeset 25785


Ignore:
Timestamp:
10/15/2013 02:30:02 PM (11 years ago)
Author:
nacin
Message:

Test runner: Add @expectedIncorrectUsage to trap _doing_it_wrong() calls.

see #24813, #25282.

Location:
trunk/tests/phpunit
Files:
3 edited

Legend:

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

    r25408 r25785  
    99    protected $expected_deprecated = array();
    1010    protected $caught_deprecated = array();
     11    protected $expected_doing_it_wrong = array();
     12    protected $caught_doing_it_wrong = array();
    1113
    1214    /**
     
    9092            if ( ! empty( $annotations[ $depth ]['expectedDeprecated'] ) )
    9193                $this->expected_deprecated = array_merge( $this->expected_deprecated, $annotations[ $depth ]['expectedDeprecated'] );
     94            if ( ! empty( $annotations[ $depth ]['expectedIncorrectUsage'] ) )
     95                $this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, $annotations[ $depth ]['expectedIncorrectUsage'] );
    9296        }
    9397        add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    9498        add_action( 'deprecated_argument_run', array( $this, 'deprecated_function_run' ) );
     99        add_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) );
    95100        add_action( 'deprecated_function_trigger_error', '__return_false' );
    96101        add_action( 'deprecated_argument_trigger_error', '__return_false' );
     102        add_action( 'doing_it_wrong_trigger_error',      '__return_false' );
    97103    }
    98104
     
    107113            $this->fail( "Unexpected deprecated notice for $unexpected" );
    108114        }
     115
     116        $not_caught_doing_it_wrong = array_diff( $this->expected_doing_it_wrong, $this->caught_doing_it_wrong );
     117        foreach ( $not_caught_doing_it_wrong as $not_caught ) {
     118            $this->fail( "Failed to assert that $not_caught triggered an incorrect usage notice" );
     119        }
     120
     121        $unexpected_doing_it_wrong = array_diff( $this->caught_doing_it_wrong, $this->expected_doing_it_wrong );
     122        foreach ( $unexpected_doing_it_wrong as $unexpected ) {
     123            $this->fail( "Unexpected incorrect usage notice for $unexpected" );
     124        }
    109125    }
    110126
     
    112128        if ( ! in_array( $function, $this->caught_deprecated ) )
    113129            $this->caught_deprecated[] = $function;
     130    }
     131
     132    function doing_it_wrong_run( $function ) {
     133        if ( ! in_array( $function, $this->caught_doing_it_wrong ) )
     134            $this->caught_doing_it_wrong[] = $function;
    114135    }
    115136
  • trunk/tests/phpunit/tests/dependencies/jquery.php

    r25375 r25785  
    3939    /**
    4040     * @ticket 22896
     41     *
     42     * @expectedIncorrectUsage wp_deregister_script
    4143     */
    4244    function test_dont_allow_deregister_core_scripts_in_admin() {
     
    5254        );
    5355
    54         add_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) );
    55 
    5656        foreach ( $libraries as $library ) {
    5757            // Try to deregister the script, which should fail.
     
    6060        }
    6161
    62         remove_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) );
    63 
    6462        set_current_screen( 'front' );
    65     }
    66 
    67     function doing_it_wrong_run() {
    68         add_filter( 'doing_it_wrong_trigger_error', array( $this, 'doing_it_wrong_trigger_error' ) );
    69     }
    70 
    71     function doing_it_wrong_trigger_error() {
    72         remove_filter( 'doing_it_wrong_trigger_error', array( $this, 'doing_it_wrong_trigger_error' ) );
    73         return false;
    7463    }
    7564
  • trunk/tests/phpunit/tests/theme/support.php

    r25387 r25785  
    55 */
    66class Tests_Theme_Support extends WP_UnitTestCase {
    7 
    8     function setUp() {
    9         parent::setUp();
    10         add_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) );
    11     }
    12 
    13     function tearDown() {
    14         parent::tearDown();
    15         remove_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) );
    16     }
    17 
    18     function doing_it_wrong_run( $function ) {
    19         if ( in_array( $function, array( "add_theme_support( 'html5' )" ) ) )
    20             add_filter( 'doing_it_wrong_trigger_error', array( $this, 'doing_it_wrong_trigger_error' ) );
    21     }
    22 
    23     function doing_it_wrong_trigger_error() {
    24         remove_filter( 'doing_it_wrong_trigger_error', array( $this, 'doing_it_wrong_trigger_error' ) );
    25         return false;
    26     }
    277
    288    function test_the_basics() {
     
    11696    /**
    11797     * @ticket 24932
     98     *
     99     * @expectedIncorrectUsage add_theme_support( 'html5' )
    118100     */
    119101    function test_supports_html5_subset() {
     
    145127    /**
    146128     * @ticket 24932
     129     *
     130     * @expectedIncorrectUsage add_theme_support( 'html5' )
    147131     */
    148132    function test_supports_html5_invalid() {
Note: See TracChangeset for help on using the changeset viewer.