From eff3f6ae1db5b2307f358f1857846965d780a019 Mon Sep 17 00:00:00 2001 From: Mohammed Noumaan Ahamed Date: Thu, 21 May 2026 17:06:09 +0530 Subject: [PATCH] refactor: cleanup redundant test hooks on abilities api --- tests/phpunit/tests/abilities-api/wpAbility.php | 17 ----------------- .../tests/abilities-api/wpRegisterAbility.php | 2 -- .../abilities-api/wpRegisterAbilityCategory.php | 2 -- .../wpRestAbilitiesV1CategoriesController.php | 1 - .../wpRestAbilitiesV1ListController.php | 2 -- 5 files changed, 24 deletions(-) diff --git a/tests/phpunit/tests/abilities-api/wpAbility.php b/tests/phpunit/tests/abilities-api/wpAbility.php index aea2c09624929..bc5a58df94e81 100644 --- a/tests/phpunit/tests/abilities-api/wpAbility.php +++ b/tests/phpunit/tests/abilities-api/wpAbility.php @@ -578,8 +578,6 @@ public function test_before_execute_ability_action() { $ability = new WP_Ability( self::$test_ability_name, $args ); $result = $ability->execute( 5 ); - remove_action( 'wp_before_execute_ability', $callback ); - $this->assertSame( self::$test_ability_name, $action_ability_name, 'Action should receive correct ability name' ); $this->assertSame( 5, $action_input, 'Action should receive correct input' ); $this->assertSame( 10, $result, 'Ability should execute correctly' ); @@ -613,8 +611,6 @@ public function test_before_execute_ability_action_no_input() { $ability = new WP_Ability( self::$test_ability_name, $args ); $result = $ability->execute(); - remove_action( 'wp_before_execute_ability', $callback ); - $this->assertSame( self::$test_ability_name, $action_ability_name, 'Action should receive correct ability name' ); $this->assertNull( $action_input, 'Action should receive null input when no input provided' ); $this->assertSame( 42, $result, 'Ability should execute correctly' ); @@ -655,8 +651,6 @@ public function test_after_execute_ability_action() { $ability = new WP_Ability( self::$test_ability_name, $args ); $result = $ability->execute( 7 ); - remove_action( 'wp_after_execute_ability', $callback ); - $this->assertSame( self::$test_ability_name, $action_ability_name, 'Action should receive correct ability name' ); $this->assertSame( 7, $action_input, 'Action should receive correct input' ); $this->assertSame( 21, $action_result, 'Action should receive correct result' ); @@ -694,8 +688,6 @@ public function test_after_execute_ability_action_no_input() { $ability = new WP_Ability( self::$test_ability_name, $args ); $result = $ability->execute(); - remove_action( 'wp_after_execute_ability', $callback ); - $this->assertSame( self::$test_ability_name, $action_ability_name, 'Action should receive correct ability name' ); $this->assertNull( $action_input, 'Action should receive null input when no input provided' ); $this->assertSame( 'test-result', $action_result, 'Action should receive correct result' ); @@ -734,9 +726,6 @@ public function test_actions_not_fired_on_permission_failure() { $ability = new WP_Ability( self::$test_ability_name, $args ); $result = $ability->execute(); - remove_action( 'wp_before_execute_ability', $before_callback ); - remove_action( 'wp_after_execute_ability', $after_callback ); - $this->assertFalse( $before_action_fired, 'before_execute_ability action should not be fired on permission failure' ); $this->assertFalse( $after_action_fired, 'after_execute_ability action should not be fired on permission failure' ); $this->assertInstanceOf( WP_Error::class, $result, 'Should return WP_Error on permission failure' ); @@ -774,9 +763,6 @@ public function test_after_action_not_fired_on_execution_error() { $ability = new WP_Ability( self::$test_ability_name, $args ); $result = $ability->execute(); - remove_action( 'wp_before_execute_ability', $before_callback ); - remove_action( 'wp_after_execute_ability', $after_callback ); - $this->assertTrue( $before_action_fired, 'before_execute_ability action should be fired even if execution fails' ); $this->assertFalse( $after_action_fired, 'after_execute_ability action should not be fired when execution returns WP_Error' ); $this->assertInstanceOf( WP_Error::class, $result, 'Should return WP_Error from execution callback' ); @@ -819,9 +805,6 @@ public function test_after_action_not_fired_on_output_validation_error() { $ability = new WP_Ability( self::$test_ability_name, $args ); $result = $ability->execute(); - remove_action( 'wp_before_execute_ability', $before_callback ); - remove_action( 'wp_after_execute_ability', $after_callback ); - $this->assertTrue( $before_action_fired, 'before_execute_ability action should be fired even if output validation fails' ); $this->assertFalse( $after_action_fired, 'after_execute_ability action should not be fired when output validation fails' ); $this->assertInstanceOf( WP_Error::class, $result, 'Should return WP_Error for output validation failure' ); diff --git a/tests/phpunit/tests/abilities-api/wpRegisterAbility.php b/tests/phpunit/tests/abilities-api/wpRegisterAbility.php index 61bf8f59dba53..46d6bb6859926 100644 --- a/tests/phpunit/tests/abilities-api/wpRegisterAbility.php +++ b/tests/phpunit/tests/abilities-api/wpRegisterAbility.php @@ -539,8 +539,6 @@ public function test_get_existing_ability_using_callback() { $result = wp_get_ability( $name ); - remove_action( 'wp_abilities_api_init', $callback ); - $this->assertEquals( new WP_Ability( $name, $args ), $result, diff --git a/tests/phpunit/tests/abilities-api/wpRegisterAbilityCategory.php b/tests/phpunit/tests/abilities-api/wpRegisterAbilityCategory.php index 5a59b1050bf25..174ad4b0882b6 100644 --- a/tests/phpunit/tests/abilities-api/wpRegisterAbilityCategory.php +++ b/tests/phpunit/tests/abilities-api/wpRegisterAbilityCategory.php @@ -311,8 +311,6 @@ public function test_get_existing_category_using_callback(): void { $result = wp_get_ability_category( $name ); - remove_action( 'wp_abilities_api_categories_init', $callback ); - $this->assertInstanceOf( WP_Ability_Category::class, $result ); $this->assertSame( self::$test_ability_category_name, $result->get_slug() ); } diff --git a/tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesController.php b/tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesController.php index 43525263ac5ba..f52fa32543d47 100644 --- a/tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesController.php +++ b/tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesController.php @@ -206,7 +206,6 @@ public function test_get_item_with_selected_fields(): void { $response = $this->server->dispatch( $request ); add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); $response = apply_filters( 'rest_post_dispatch', $response, $this->server, $request ); - remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); $this->assertEquals( 200, $response->get_status() ); diff --git a/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php b/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php index d73a2c64177fc..1465319f234de 100644 --- a/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php +++ b/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php @@ -328,7 +328,6 @@ public function test_get_item_with_selected_fields(): void { $response = $this->server->dispatch( $request ); add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); $response = apply_filters( 'rest_post_dispatch', $response, $this->server, $request ); - remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); $this->assertEquals( 200, $response->get_status() ); @@ -349,7 +348,6 @@ public function test_get_item_with_embed_context(): void { $response = $this->server->dispatch( $request ); add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); $response = apply_filters( 'rest_post_dispatch', $response, $this->server, $request ); - remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); $this->assertEquals( 200, $response->get_status() );