From 4564772543b914f847accc551083f8c2f40be924 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 11 Mar 2024 11:05:39 +0100 Subject: [PATCH 1/2] Block Hooks: Remove filter global reset from test teardown --- tests/phpunit/tests/block-template-utils.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/phpunit/tests/block-template-utils.php b/tests/phpunit/tests/block-template-utils.php index 8d972c004d52e..4c73ddc097ca0 100644 --- a/tests/phpunit/tests/block-template-utils.php +++ b/tests/phpunit/tests/block-template-utils.php @@ -92,15 +92,6 @@ public function set_up() { * @since 6.5.0 */ public function tear_down() { - global $wp_current_filter; - - if ( - 'rest_pre_insert_wp_template' === current_filter() || - 'rest_pre_insert_wp_template_part' === current_filter() - ) { - array_pop( $wp_current_filter ); - } - if ( WP_Block_Type_Registry::get_instance()->is_registered( 'tests/hooked-block' ) ) { unregister_block_type( 'tests/hooked-block' ); } @@ -420,7 +411,8 @@ public function test_wp_generate_block_templates_export_file() { */ public function test_inject_ignored_hooked_blocks_metadata_attributes_into_template() { global $wp_current_filter; - // Mock currently set filter. + // Mock currently set filter. The $wp_current_filter global is reset during teardown by + // WP_UnitTestCase_Base::_restore_hooks() in tests/phpunit/includes/abstract-testcase.php. $wp_current_filter[] = 'rest_pre_insert_wp_template'; register_block_type( From 17687be012d3714689ab5ba37cf46022762652ea Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 11 Mar 2024 11:11:01 +0100 Subject: [PATCH 2/2] Add another comment --- tests/phpunit/tests/block-template-utils.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/block-template-utils.php b/tests/phpunit/tests/block-template-utils.php index 4c73ddc097ca0..4d92c277a9730 100644 --- a/tests/phpunit/tests/block-template-utils.php +++ b/tests/phpunit/tests/block-template-utils.php @@ -445,7 +445,8 @@ public function test_inject_ignored_hooked_blocks_metadata_attributes_into_templ */ public function test_inject_ignored_hooked_blocks_metadata_attributes_into_template_part() { global $wp_current_filter; - // Mock currently set filter. + // Mock currently set filter. The $wp_current_filter global is reset during teardown by + // WP_UnitTestCase_Base::_restore_hooks() in tests/phpunit/includes/abstract-testcase.php. $wp_current_filter[] = 'rest_pre_insert_wp_template_part'; register_block_type(