diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index 0d502d7ded..66f472a859 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -8,6 +8,8 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { protected static $forced_tickets = array(); protected $expected_deprecated = array(); protected $caught_deprecated = array(); + protected $expected_doing_it_wrong = array(); + protected $caught_doing_it_wrong = array(); /** * @var WP_UnitTest_Factory @@ -89,11 +91,15 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { foreach ( array( 'class', 'method' ) as $depth ) { if ( ! empty( $annotations[ $depth ]['expectedDeprecated'] ) ) $this->expected_deprecated = array_merge( $this->expected_deprecated, $annotations[ $depth ]['expectedDeprecated'] ); + if ( ! empty( $annotations[ $depth ]['expectedIncorrectUsage'] ) ) + $this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, $annotations[ $depth ]['expectedIncorrectUsage'] ); } add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) ); add_action( 'deprecated_argument_run', array( $this, 'deprecated_function_run' ) ); + add_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) ); add_action( 'deprecated_function_trigger_error', '__return_false' ); add_action( 'deprecated_argument_trigger_error', '__return_false' ); + add_action( 'doing_it_wrong_trigger_error', '__return_false' ); } function expectedDeprecated() { @@ -106,6 +112,16 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { foreach ( $unexpected_deprecated as $unexpected ) { $this->fail( "Unexpected deprecated notice for $unexpected" ); } + + $not_caught_doing_it_wrong = array_diff( $this->expected_doing_it_wrong, $this->caught_doing_it_wrong ); + foreach ( $not_caught_doing_it_wrong as $not_caught ) { + $this->fail( "Failed to assert that $not_caught triggered an incorrect usage notice" ); + } + + $unexpected_doing_it_wrong = array_diff( $this->caught_doing_it_wrong, $this->expected_doing_it_wrong ); + foreach ( $unexpected_doing_it_wrong as $unexpected ) { + $this->fail( "Unexpected incorrect usage notice for $unexpected" ); + } } function deprecated_function_run( $function ) { @@ -113,6 +129,11 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { $this->caught_deprecated[] = $function; } + function doing_it_wrong_run( $function ) { + if ( ! in_array( $function, $this->caught_doing_it_wrong ) ) + $this->caught_doing_it_wrong[] = $function; + } + function assertWPError( $actual, $message = '' ) { $this->assertInstanceOf( 'WP_Error', $actual, $message ); } diff --git a/tests/phpunit/tests/dependencies/jquery.php b/tests/phpunit/tests/dependencies/jquery.php index aaacab67dc..df06104714 100644 --- a/tests/phpunit/tests/dependencies/jquery.php +++ b/tests/phpunit/tests/dependencies/jquery.php @@ -38,6 +38,8 @@ class Tests_Dependencies_jQuery extends WP_UnitTestCase { /** * @ticket 22896 + * + * @expectedIncorrectUsage wp_deregister_script */ function test_dont_allow_deregister_core_scripts_in_admin() { set_current_screen( 'edit.php' ); @@ -51,28 +53,15 @@ class Tests_Dependencies_jQuery extends WP_UnitTestCase { 'jquery-ui-tooltip', 'jquery-ui-widget', 'backbone', 'underscore', ); - add_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) ); - foreach ( $libraries as $library ) { // Try to deregister the script, which should fail. wp_deregister_script( $library ); $this->assertTrue( wp_script_is( $library, 'registered' ) ); } - remove_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) ); - set_current_screen( 'front' ); } - function doing_it_wrong_run() { - add_filter( 'doing_it_wrong_trigger_error', array( $this, 'doing_it_wrong_trigger_error' ) ); - } - - function doing_it_wrong_trigger_error() { - remove_filter( 'doing_it_wrong_trigger_error', array( $this, 'doing_it_wrong_trigger_error' ) ); - return false; - } - /** * @ticket 24994 */ diff --git a/tests/phpunit/tests/theme/support.php b/tests/phpunit/tests/theme/support.php index 779231183a..4c64a9db60 100644 --- a/tests/phpunit/tests/theme/support.php +++ b/tests/phpunit/tests/theme/support.php @@ -5,26 +5,6 @@ */ class Tests_Theme_Support extends WP_UnitTestCase { - function setUp() { - parent::setUp(); - add_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) ); - } - - function tearDown() { - parent::tearDown(); - remove_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) ); - } - - function doing_it_wrong_run( $function ) { - if ( in_array( $function, array( "add_theme_support( 'html5' )" ) ) ) - add_filter( 'doing_it_wrong_trigger_error', array( $this, 'doing_it_wrong_trigger_error' ) ); - } - - function doing_it_wrong_trigger_error() { - remove_filter( 'doing_it_wrong_trigger_error', array( $this, 'doing_it_wrong_trigger_error' ) ); - return false; - } - function test_the_basics() { add_theme_support( 'automatic-feed-links' ); $this->assertTrue( current_theme_supports( 'automatic-feed-links' ) ); @@ -115,6 +95,8 @@ class Tests_Theme_Support extends WP_UnitTestCase { /** * @ticket 24932 + * + * @expectedIncorrectUsage add_theme_support( 'html5' ) */ function test_supports_html5_subset() { remove_theme_support( 'html5' ); @@ -144,6 +126,8 @@ class Tests_Theme_Support extends WP_UnitTestCase { /** * @ticket 24932 + * + * @expectedIncorrectUsage add_theme_support( 'html5' ) */ function test_supports_html5_invalid() { remove_theme_support( 'html5' );