Skip to content

Commit ca04081

Browse files
fix wpRegisterAbility tests
1 parent 9427ec6 commit ca04081

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/phpunit/tests/abilities-api/wpRegisterAbilityCategory.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public function set_up(): void {
2626
'label' => 'Math',
2727
'description' => 'Mathematical operations.',
2828
);
29+
30+
// Unregister all ability categories to ensure a clean slate for each test.
31+
foreach ( wp_get_ability_categories() as $ability_category ) {
32+
wp_unregister_ability_category( $ability_category->get_slug() );
33+
}
34+
remove_action( 'wp_abilities_api_categories_init', 'wp_register_core_ability_categories' );
2935
}
3036

3137
/**
@@ -52,6 +58,10 @@ public function tear_down(): void {
5258
* @expectedIncorrectUsage wp_register_ability_category
5359
*/
5460
public function test_register_category_before_init_hook(): void {
61+
// simulate that the 'wp_abilities_api_categories_init' action has not yet fired.
62+
global $wp_actions;
63+
$wp_actions[ 'wp_abilities_api_categories_init' ] = 0;
64+
5565
$result = wp_register_ability_category(
5666
self::$test_ability_category_name,
5767
self::$test_ability_category_args

0 commit comments

Comments
 (0)