Build/Test Tools: Fix and standardise calls to the tearDown() method in the test suite.

The parent method should be called after any test-specific teardown.

See #52625


git-svn-id: https://develop.svn.wordpress.org/trunk@50450 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2021-02-27 17:08:26 +00:00
parent 3542c3b4c0
commit 055deeabff
29 changed files with 43 additions and 47 deletions

View File

@ -157,7 +157,6 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
* Resets $_POST, removes the wp_die() override, restores error reporting.
*/
public function tearDown() {
parent::tearDown();
$_POST = array();
$_GET = array();
unset( $GLOBALS['post'] );
@ -166,6 +165,7 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
remove_action( 'clear_auth_cookie', array( $this, 'logout' ) );
error_reporting( $this->_error_level );
set_current_screen( 'front' );
parent::tearDown();
}
/**

View File

@ -19,12 +19,12 @@ class Block_Supported_Styles_Test extends WP_UnitTestCase {
* Tear down each test method.
*/
public function tearDown() {
parent::tearDown();
while ( ! empty( $this->registered_block_names ) ) {
$block_name = array_pop( $this->registered_block_names );
unregister_block_type( $block_name );
}
parent::tearDown();
}
/**

View File

@ -14,11 +14,11 @@ abstract class WP_Test_REST_Controller_Testcase extends WP_Test_REST_TestCase {
}
public function tearDown() {
parent::tearDown();
remove_filter( 'rest_url', array( $this, 'test_rest_url_for_leading_slash' ), 10, 2 );
/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
$wp_rest_server = null;
parent::tearDown();
}
abstract public function test_register_routes();

View File

@ -59,8 +59,8 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase {
* Tear down.
*/
public function tearDown() {
parent::tearDown();
$_REQUEST = array();
parent::tearDown();
}
/**

View File

@ -43,10 +43,10 @@ class Tests_Auth extends WP_UnitTestCase {
}
public function tearDown() {
parent::tearDown();
// Cleanup all the global state.
unset( $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $GLOBALS['wp_rest_application_password_status'], $GLOBALS['wp_rest_application_password_uuid'] );
parent::tearDown();
}
function test_auth_cookie_valid() {

View File

@ -44,12 +44,12 @@ class WP_Block_Context_Test extends WP_UnitTestCase {
* Tear down each test method.
*/
public function tearDown() {
parent::tearDown();
while ( ! empty( $this->registered_block_names ) ) {
$block_name = array_pop( $this->registered_block_names );
unregister_block_type( $block_name );
}
parent::tearDown();
}
/**

View File

@ -37,9 +37,9 @@ class WP_Block_List_Test extends WP_UnitTestCase {
* Tear down each test method.
*/
public function tearDown() {
parent::tearDown();
$this->registry = null;
parent::tearDown();
}
/**

View File

@ -41,9 +41,9 @@ class WP_Test_Block_Type_Registry extends WP_UnitTestCase {
* @since 5.0.0
*/
public function tearDown() {
parent::tearDown();
$this->registry = null;
parent::tearDown();
}
/**

View File

@ -36,9 +36,9 @@ class WP_Block_Test extends WP_UnitTestCase {
* Tear down each test method.
*/
public function tearDown() {
parent::tearDown();
$this->registry = null;
parent::tearDown();
}
function filter_render_block( $content, $parsed_block ) {

View File

@ -58,8 +58,6 @@ class WP_Test_Block_Register extends WP_UnitTestCase {
* @since 5.0.0
*/
function tearDown() {
parent::tearDown();
$registry = WP_Block_Type_Registry::get_instance();
foreach ( array( 'core/test-static', 'core/test-dynamic', 'tests/notice' ) as $block_name ) {
@ -67,6 +65,8 @@ class WP_Test_Block_Register extends WP_UnitTestCase {
$registry->unregister( $block_name );
}
}
parent::tearDown();
}
/**

View File

@ -38,8 +38,6 @@ class WP_Test_Block_Render extends WP_UnitTestCase {
* @since 5.0.0
*/
public function tearDown() {
parent::tearDown();
$this->test_block_instance_number = 0;
$registry = WP_Block_Type_Registry::get_instance();
@ -49,6 +47,8 @@ class WP_Test_Block_Render extends WP_UnitTestCase {
if ( $registry->is_registered( 'core/dynamic' ) ) {
$registry->unregister( 'core/dynamic' );
}
parent::tearDown();
}
/**

View File

@ -55,8 +55,8 @@ class Test_WP_Customize_Custom_CSS_Setting extends WP_UnitTestCase {
* Tear down the test case.
*/
function tearDown() {
parent::tearDown();
$this->setting = null;
parent::tearDown();
}
/**

View File

@ -93,6 +93,7 @@ class Tests_dbDelta extends WP_UnitTestCase {
parent::tearDown();
// This has to be called after the parent `tearDown()` method.
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}dbdelta_test" );
}

View File

@ -81,10 +81,11 @@ class Tests_Formatting_ExcerptRemoveBlocks extends WP_UnitTestCase {
* @since 5.2.0
*/
function tearDown() {
parent::tearDown();
$registry = WP_Block_Type_Registry::get_instance();
$registry->unregister( 'core/fake' );
wp_delete_post( self::$post_id, true );
parent::tearDown();
}
/**

View File

@ -53,7 +53,7 @@ class Tests_Functions_Deprecated extends WP_UnitTestCase {
/**
* Tears down the test fixture.
*/
public function teardown() {
public function tearDown() {
remove_action( 'deprecated_function_run', array( $this, 'deprecated_function' ), 10, 3 );
remove_action( 'deprecated_function_trigger_error', '__return_false' );
remove_action( 'deprecated_argument_run', array( $this, 'deprecated_argument' ), 10, 3 );

View File

@ -18,11 +18,11 @@ class Tests_Functions_Referer extends WP_UnitTestCase {
}
public function tearDown() {
parent::tearDown();
$_SERVER['HTTP_REFERER'] = '';
$_SERVER['REQUEST_URI'] = '';
$_REQUEST['_wp_http_referer'] = '';
parent::tearDown();
}
public function _fake_subfolder_install() {

View File

@ -27,8 +27,8 @@ class Tests_Menu_WpAjaxMenuQuickSeach extends WP_UnitTestCase {
*/
function tearDown() {
global $current_screen;
parent::tearDown();
$current_screen = $this->current_screen;
parent::tearDown();
}
/**

View File

@ -18,8 +18,8 @@ if ( is_multisite() ) :
function tearDown() {
global $wpdb;
parent::tearDown();
$wpdb->suppress_errors( $this->suppress );
parent::tearDown();
}
function test_wpmu_log_new_registrations() {

View File

@ -60,13 +60,13 @@ class Test_oEmbed_Controller extends WP_UnitTestCase {
}
public function tearDown() {
parent::tearDown();
/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
$wp_rest_server = null;
remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10 );
remove_filter( 'oembed_result', array( $this, 'filter_oembed_result' ), 10 );
parent::tearDown();
}
/**

View File

@ -14,8 +14,8 @@ class Tests_Query_CommentCount extends WP_UnitTestCase {
}
public function tearDown() {
parent::tearDown();
unset( $this->q );
parent::tearDown();
}
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {

View File

@ -70,8 +70,8 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
}
public function tearDown() {
parent::tearDown();
unset( $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $GLOBALS['wp_rest_application_password_status'], $GLOBALS['wp_rest_application_password_uuid'] );
parent::tearDown();
}
/**

View File

@ -88,8 +88,6 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function tearDown() {
parent::tearDown();
if ( file_exists( $this->test_file ) ) {
unlink( $this->test_file );
}
@ -107,6 +105,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
WP_Image_Editor_Mock::$edit_return = array();
WP_Image_Editor_Mock::$size_return = null;
}
parent::tearDown();
}
public function test_register_routes() {

View File

@ -53,10 +53,10 @@ class WP_Test_REST_Controller extends WP_Test_REST_TestCase {
}
public function tearDown() {
parent::tearDown();
global $wp_rest_additional_fields;
$wp_rest_additional_fields = array();
parent::tearDown();
}
public function test_validate_schema_type_integer() {

View File

@ -83,11 +83,11 @@ class WP_REST_Plugins_Controller_Test extends WP_Test_REST_Controller_Testcase {
}
public function tearDown() {
parent::tearDown();
if ( file_exists( WP_PLUGIN_DIR . '/test-plugin/test-plugin.php' ) ) {
$this->rmdir( WP_PLUGIN_DIR . '/test-plugin' );
}
parent::tearDown();
}
/**

View File

@ -27,13 +27,12 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase {
}
public function tearDown() {
parent::tearDown();
/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
$wp_rest_server = null;
remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 );
parent::tearDown();
}
public function mock_embed_request( $preempt, $r, $url ) {

View File

@ -39,8 +39,6 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase
}
public function tearDown() {
parent::tearDown();
$settings_to_unregister = array(
'mycustomsetting',
'mycustomsetting1',
@ -55,6 +53,8 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase
unregister_setting( 'somegroup', $setting );
}
}
parent::tearDown();
}
public function test_register_routes() {

View File

@ -232,10 +232,6 @@ class WP_Test_REST_Taxonomies_Controller extends WP_Test_REST_Controller_Testcas
$this->assertArrayHasKey( 'rest_base', $properties );
}
public function tearDown() {
parent::tearDown();
}
/**
* Utility function for use in get_public_taxonomies
*/

View File

@ -42,9 +42,9 @@ class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase {
}
public function tearDown() {
parent::tearDown();
$this->old_date_redirect_url = null;
parent::tearDown();
}
public function test_old_date_redirect() {

View File

@ -30,11 +30,10 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase {
}
public function tearDown() {
parent::tearDown();
$this->old_slug_redirect_url = null;
remove_filter( 'old_slug_redirect_url', array( $this, 'filter_old_slug_redirect_url' ), 10 );
parent::tearDown();
}
public function test_old_slug_redirect() {