Build/Test Tools: Remove redundant teardown functionality from individual tests which is already covered in the base teardown method.

See #52625


git-svn-id: https://develop.svn.wordpress.org/trunk@50463 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2021-03-01 18:42:49 +00:00
parent 51548e1bf8
commit 2ef42cb78c
39 changed files with 2 additions and 210 deletions

View File

@@ -18,8 +18,6 @@ class Tests_Comment_GetCommentAuthorEmailLink extends WP_UnitTestCase {
public function tearDown() {
unset( $GLOBALS['comment'] );
parent::tearDown();
add_filter( 'comment_email', 'antispambot' );
}
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {

View File

@@ -35,14 +35,6 @@ class Tests_DB extends WP_UnitTestCase {
add_filter( 'query', array( $this, 'query_filter' ) );
}
/**
* Tear down the test fixture
*/
public function tearDown() {
remove_filter( 'query', array( $this, 'query_filter' ) );
parent::tearDown();
}
/**
* Log each query
*

View File

@@ -83,7 +83,6 @@ class Tests_Formatting_ExcerptRemoveBlocks extends WP_UnitTestCase {
function tearDown() {
$registry = WP_Block_Type_Registry::get_instance();
$registry->unregister( 'core/fake' );
wp_delete_post( self::$post_id, true );
parent::tearDown();
}

View File

@@ -11,11 +11,6 @@ class Tests_Formatting_Redirect extends WP_UnitTestCase {
add_filter( 'home_url', array( $this, 'home_url' ) );
}
function tearDown() {
remove_filter( 'home_url', array( $this, 'home_url' ) );
parent::tearDown();
}
function home_url() {
return 'http://example.com/';
}

View File

@@ -28,16 +28,6 @@ class Tests_Functions_DoEnclose extends WP_UnitTestCase {
add_filter( 'pre_http_request', array( $this, 'fake_http_request' ), 10, 3 );
}
/**
* Cleanup after each test method.
*
* @since 5.3.0
*/
public function tearDown() {
parent::tearDown();
remove_filter( 'pre_http_request', array( $this, 'fake_http_request' ) );
}
/**
* Test the function with an explicit content input.
*

View File

@@ -53,11 +53,6 @@ class Tests_General_wpGetDocumentTitle extends WP_UnitTestCase {
setup_postdata( get_post( self::$post_id ) );
}
function tearDown() {
wp_reset_postdata();
parent::tearDown();
}
function _add_title_tag_support() {
add_theme_support( 'title-tag' );
}

View File

@@ -27,8 +27,6 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
function tearDown() {
$GLOBALS['wp_scripts'] = $this->old_wp_scripts;
$GLOBALS['wp_styles'] = $this->old_wp_styles;
add_action( 'wp_default_scripts', 'wp_default_scripts' );
add_action( 'wp_default_styles', 'wp_default_styles' );
parent::tearDown();
}

View File

@@ -39,13 +39,6 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
}
}
function tearDown() {
foreach ( array( 'curl', 'streams', 'fsockopen' ) as $t ) {
remove_filter( "use_{$t}_transport", '__return_false' );
}
parent::tearDown();
}
function filter_http_request_args( array $args ) {
$this->http_request_args = $args;
return $args;

View File

@@ -16,16 +16,6 @@ class Tests_HTTP_wpGetHttpHeaders extends WP_UnitTestCase {
add_filter( 'pre_http_request', array( $this, 'fake_http_request' ), 10, 3 );
}
/**
* Clean up environment
*/
public function tearDown() {
parent::tearDown();
// Clear the hook for the fake HTTP request response.
remove_filter( 'pre_http_request', array( $this, 'fake_http_request' ) );
}
/**
* Test with a valid URL
*/

View File

@@ -18,14 +18,6 @@ abstract class WP_Image_UnitTestCase extends WP_UnitTestCase {
add_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 );
}
/**
* Undo the image editor override
*/
public function tearDown() {
remove_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 );
parent::tearDown();
}
/**
* Override the image editor engine
*

View File

@@ -16,12 +16,6 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase
add_filter( 'wp_image_editors', array( $this, 'wp_image_editors' ) );
}
public function tearDown() {
remove_filter( 'wp_image_editors', array( $this, 'wp_image_editors' ) );
parent::tearDown();
}
public function wp_image_editors() {
return array( $this->editor_engine );
}

View File

@@ -33,12 +33,6 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
}
}
function tearDown() {
remove_filter( 'import_allow_create_users', '__return_true' );
parent::tearDown();
}
function test_small_import() {
global $wpdb;

View File

@@ -21,7 +21,6 @@ class Tests_L10n_GetUserLocale extends WP_UnitTestCase {
}
public function tearDown() {
delete_user_meta( $this->user_id, 'locale' );
set_current_screen( 'front' );
parent::tearDown();

View File

@@ -26,13 +26,6 @@ class Tests_L10n_LoadTextdomain extends WP_UnitTestCase {
add_filter( 'theme_locale', array( $this, 'store_locale' ) );
}
public function tearDown() {
remove_filter( 'plugin_locale', array( $this, 'store_locale' ) );
remove_filter( 'theme_locale', array( $this, 'store_locale' ) );
parent::tearDown();
}
public function store_locale( $locale ) {
$this->locale = $locale;

View File

@@ -40,9 +40,6 @@ class Tests_L10n_LoadTextdomainJustInTime extends WP_UnitTestCase {
public function tearDown() {
$GLOBALS['wp_theme_directories'] = $this->orig_theme_dir;
remove_filter( 'theme_root', array( $this, 'filter_theme_root' ) );
remove_filter( 'stylesheet_root', array( $this, 'filter_theme_root' ) );
remove_filter( 'template_root', array( $this, 'filter_theme_root' ) );
wp_clean_themes_cache();
unset( $GLOBALS['wp_themes'] );
unset( $GLOBALS['l10n'] );

View File

@@ -10,16 +10,6 @@ if ( is_multisite() ) :
class Tests_Multisite_Get_Space_Allowed extends WP_UnitTestCase {
protected $suppress = false;
protected static $original_site_blog_upload_space;
protected static $original_blog_upload_space;
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
self::$original_site_blog_upload_space = get_site_option( 'blog_upload_space' );
self::$original_blog_upload_space = get_option( 'blog_upload_space' );
}
public function setUp() {
global $wpdb;
parent::setUp();
@@ -29,13 +19,6 @@ if ( is_multisite() ) :
public function tearDown() {
global $wpdb;
/**
* Reset the two `blog_upload_space` options to their original values so
* they can be relied on in other test classes.
*/
update_site_option( 'blog_upload_space', self::$original_site_blog_upload_space );
update_option( 'blog_upload_space', self::$original_blog_upload_space );
$wpdb->suppress_errors( $this->suppress );
parent::tearDown();
}

View File

@@ -13,16 +13,6 @@ if ( is_multisite() ) :
class Tests_Multisite_Is_Upload_Space_Available extends WP_UnitTestCase {
protected $suppress = false;
protected static $original_site_blog_upload_space;
protected static $original_blog_upload_space;
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
self::$original_site_blog_upload_space = get_site_option( 'blog_upload_space' );
self::$original_blog_upload_space = get_option( 'blog_upload_space' );
}
public function setUp() {
global $wpdb;
parent::setUp();
@@ -34,13 +24,6 @@ if ( is_multisite() ) :
public function tearDown() {
global $wpdb;
/**
* Reset the two `blog_upload_space` options to their original values so
* they can be relied on in other test classes.
*/
update_site_option( 'blog_upload_space', self::$original_site_blog_upload_space );
update_option( 'blog_upload_space', self::$original_blog_upload_space );
$wpdb->suppress_errors( $this->suppress );
parent::tearDown();
}

View File

@@ -26,7 +26,6 @@ if ( is_multisite() ) :
function tearDown() {
global $wpdb;
update_site_option( 'ms_files_rewriting', 0 );
$wpdb->suppress_errors( $this->suppress );
parent::tearDown();

View File

@@ -64,8 +64,6 @@ class Test_oEmbed_Controller extends WP_UnitTestCase {
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

@@ -20,11 +20,6 @@ class Tests_Post_Revisions extends WP_UnitTestCase {
$this->post_type = rand_str( 20 );
}
function tearDown() {
unset( $GLOBALS['wp_post_types'][ $this->post_type ] );
parent::tearDown();
}
/**
* Note: Test needs reviewing when #16215 is fixed because I'm not sure the test current tests the "correct" behavior
*

View File

@@ -65,17 +65,6 @@ class Tests_Query_IsTerm extends WP_UnitTestCase {
add_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
}
function tearDown() {
global $wp_rewrite;
_unregister_taxonomy( 'testtax' );
$wp_rewrite->init();
remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
parent::tearDown();
}
function test_tag_action_tax() {
// Tag with taxonomy added.
$this->go_to( home_url( '/tag/tag-slug/' ) );

View File

@@ -17,7 +17,6 @@ class Tests_Query_Search extends WP_UnitTestCase {
}
function tearDown() {
_unregister_post_type( $this->post_type );
unset( $this->q );
parent::tearDown();

View File

@@ -95,9 +95,6 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
unlink( $this->test_file2 );
}
remove_action( 'rest_insert_attachment', array( $this, 'filter_rest_insert_attachment' ) );
remove_action( 'rest_after_insert_attachment', array( $this, 'filter_rest_after_insert_attachment' ) );
$this->remove_added_uploads();
if ( class_exists( WP_Image_Editor_Mock::class ) ) {

View File

@@ -1182,12 +1182,6 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas
return 123;
}
public function tearDown() {
_unregister_taxonomy( 'batman' );
_unregister_taxonomy( 'robin' );
parent::tearDown();
}
protected function check_get_taxonomy_terms_response( $response ) {
$this->assertSame( 200, $response->get_status() );
$data = $response->get_data();

View File

@@ -764,11 +764,6 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te
$this->assertArrayHasKey( 'type', $properties );
}
public function tearDown() {
parent::tearDown();
remove_filter( 'theme_page_templates', array( $this, 'filter_theme_page_templates' ) );
}
public function filter_theme_page_templates( $page_templates ) {
return array(
'page-my-test-template.php' => 'My Test Template',

View File

@@ -5088,13 +5088,10 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
}
public function tearDown() {
_unregister_post_type( 'private-post' );
_unregister_post_type( 'youseeme' );
if ( isset( $this->attachment_id ) ) {
$this->remove_added_uploads();
}
remove_filter( 'rest_pre_dispatch', array( $this, 'wpSetUpBeforeRequest' ), 10, 3 );
remove_filter( 'posts_clauses', array( $this, 'save_posts_clauses' ), 10, 2 );
parent::tearDown();
}

View File

@@ -76,12 +76,6 @@ class WP_Test_REST_Revisions_Controller extends WP_Test_REST_Controller_Testcase
$this->revision_id3 = $this->revision_3->ID;
}
public function tearDown() {
parent::tearDown();
remove_filter( 'map_meta_cap', array( $this, '_filter_map_meta_cap_remove_no_allow_revisions' ) );
}
public function _filter_map_meta_cap_remove_no_allow_revisions( $caps, $cap, $user_id, $args ) {
if ( 'delete_post' !== $cap || empty( $args ) ) {
return $caps;

View File

@@ -31,7 +31,6 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase {
global $wp_rest_server;
$wp_rest_server = null;
remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 );
parent::tearDown();
}

View File

@@ -1400,12 +1400,6 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
}
}
public function tearDown() {
_unregister_taxonomy( 'batman' );
_unregister_taxonomy( 'robin' );
parent::tearDown();
}
protected function check_get_taxonomy_terms_response( $response ) {
$this->assertSame( 200, $response->get_status() );
$data = $response->get_data();

View File

@@ -15,11 +15,6 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase {
add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ), 10, 6 );
}
public function tearDown() {
parent::tearDown();
remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ), 10, 6 );
}
public function test_go_to_year_segment_collision_without_title() {
global $wpdb;
$this->set_permalink_structure( '/%postname%/' );

View File

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

View File

@@ -7,14 +7,12 @@ class Tests_Rewrite_Tags extends WP_UnitTestCase {
protected $rewritecode;
protected $rewritereplace;
protected $queryreplace;
protected $wp_rewrite;
public function setUp() {
global $wp_rewrite;
parent::setUp();
$this->wp_rewrite = $wp_rewrite;
$wp_rewrite = new WP_Rewrite();
$wp_rewrite = new WP_Rewrite();
$wp_rewrite->init();
$this->rewritecode = $wp_rewrite->rewritecode;
@@ -22,11 +20,6 @@ class Tests_Rewrite_Tags extends WP_UnitTestCase {
$this->queryreplace = $wp_rewrite->queryreplace;
}
public function tearDown() {
global $wp_rewrite;
$wp_rewrite = $this->wp_rewrite;
}
public function _invalid_rewrite_tags() {
return array(
array( 'foo', 'bar' ),

View File

@@ -20,9 +20,6 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase {
function tearDown() {
$GLOBALS['wp_theme_directories'] = $this->orig_theme_dir;
remove_filter( 'theme_root', array( $this, '_theme_root' ) );
remove_filter( 'stylesheet_root', array( $this, '_theme_root' ) );
remove_filter( 'template_root', array( $this, '_theme_root' ) );
wp_clean_themes_cache();
unset( $GLOBALS['wp_themes'] );
parent::tearDown();

View File

@@ -26,9 +26,6 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase {
function tearDown() {
$GLOBALS['wp_theme_directories'] = $this->orig_theme_dir;
remove_filter( 'theme_root', array( $this, '_theme_root' ) );
remove_filter( 'stylesheet_root', array( $this, '_theme_root' ) );
remove_filter( 'template_root', array( $this, '_theme_root' ) );
wp_clean_themes_cache();
unset( $GLOBALS['wp_themes'] );
parent::tearDown();

View File

@@ -39,11 +39,6 @@ class Tests_User_Author_Template extends WP_UnitTestCase {
setup_postdata( get_post( self::$post_id ) );
}
function tearDown() {
wp_reset_postdata();
parent::tearDown();
}
function test_get_the_author() {
$author_name = get_the_author();
$user = new WP_User( self::$author_id );

View File

@@ -58,11 +58,6 @@ class Tests_User_CountUserPosts extends WP_UnitTestCase {
register_post_type( 'wptests_pt' );
}
public function tearDown() {
_unregister_post_type( 'wptests_pt' );
parent::tearDown();
}
public function test_count_user_posts_post_type_should_default_to_post() {
$this->assertEquals( 4, count_user_posts( self::$user_id ) );
}

View File

@@ -76,7 +76,6 @@ class Tests_User_WpSendUserRequest extends WP_UnitTestCase {
* @since 4.9.9
*/
public function tearDown() {
delete_option( 'WPLANG' );
reset_phpmailer_instance();
unset( $GLOBALS['locale'] );

View File

@@ -23,12 +23,6 @@ class Tests_XMLRPC_wp_getPostType extends WP_XMLRPC_UnitTestCase {
register_post_type( $this->cpt_name, $this->cpt_args );
}
function tearDown() {
_unregister_post_type( $this->cpt_name );
parent::tearDown();
}
function test_invalid_username_password() {
$result = $this->myxmlrpcserver->wp_getPostType( array( 1, 'username', 'password', 'post' ) );
$this->assertIXRError( $result );

View File

@@ -17,13 +17,6 @@ class Tests_XMLRPC_wp_getUser extends WP_XMLRPC_UnitTestCase {
}
}
function tearDown() {
if ( is_multisite() ) {
revoke_super_admin( $this->administrator_id );
}
parent::tearDown();
}
function test_invalid_username_password() {
$result = $this->myxmlrpcserver->wp_getUser( array( 1, 'username', 'password', 1 ) );
$this->assertIXRError( $result );