Skip to content

Commit 454a749

Browse files
committed
Abilities API: Refactor registration for core abilities
Renames the files and adds a test cleanup so it doesn't accidentaly influence the rest of other tests. Developed in #10423. Follow-up [61063]. See #64146. git-svn-id: https://develop.svn.wordpress.org/trunk@61068 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f4a36c7 commit 454a749

File tree

3 files changed

+58
-45
lines changed

3 files changed

+58
-45
lines changed

src/wp-includes/abilities/wp-core-abilities.php

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
declare( strict_types = 1 );
11+
1112
/**
1213
* Registers the core ability categories.
1314
*
@@ -44,16 +45,41 @@ function wp_register_core_abilities(): void {
4445
$category_site = 'site';
4546
$category_user = 'user';
4647

47-
$site_info_fields = array(
48-
'name',
49-
'description',
50-
'url',
51-
'wpurl',
52-
'admin_email',
53-
'charset',
54-
'language',
55-
'version',
48+
$site_info_properties = array(
49+
'name' => array(
50+
'type' => 'string',
51+
'description' => __( 'The site title.' ),
52+
),
53+
'description' => array(
54+
'type' => 'string',
55+
'description' => __( 'The site tagline.' ),
56+
),
57+
'url' => array(
58+
'type' => 'string',
59+
'description' => __( 'The site home URL.' ),
60+
),
61+
'wpurl' => array(
62+
'type' => 'string',
63+
'description' => __( 'The WordPress installation URL.' ),
64+
),
65+
'admin_email' => array(
66+
'type' => 'string',
67+
'description' => __( 'The site administrator email address.' ),
68+
),
69+
'charset' => array(
70+
'type' => 'string',
71+
'description' => __( 'The site character encoding.' ),
72+
),
73+
'language' => array(
74+
'type' => 'string',
75+
'description' => __( 'The site language locale code.' ),
76+
),
77+
'version' => array(
78+
'type' => 'string',
79+
'description' => __( 'The WordPress version.' ),
80+
),
5681
);
82+
$site_info_fields = array_keys( $site_info_properties );
5783

5884
wp_register_ability(
5985
'core/get-site-info',
@@ -78,40 +104,7 @@ function wp_register_core_abilities(): void {
78104
),
79105
'output_schema' => array(
80106
'type' => 'object',
81-
'properties' => array(
82-
'name' => array(
83-
'type' => 'string',
84-
'description' => __( 'The site title.' ),
85-
),
86-
'description' => array(
87-
'type' => 'string',
88-
'description' => __( 'The site tagline.' ),
89-
),
90-
'url' => array(
91-
'type' => 'string',
92-
'description' => __( 'The site home URL.' ),
93-
),
94-
'wpurl' => array(
95-
'type' => 'string',
96-
'description' => __( 'The WordPress installation URL.' ),
97-
),
98-
'admin_email' => array(
99-
'type' => 'string',
100-
'description' => __( 'The site administrator email address.' ),
101-
),
102-
'charset' => array(
103-
'type' => 'string',
104-
'description' => __( 'The site character encoding.' ),
105-
),
106-
'language' => array(
107-
'type' => 'string',
108-
'description' => __( 'The site language locale code.' ),
109-
),
110-
'version' => array(
111-
'type' => 'string',
112-
'description' => __( 'The WordPress version.' ),
113-
),
114-
),
107+
'properties' => $site_info_properties,
115108
'additionalProperties' => false,
116109
),
117110
'execute_callback' => static function ( $input = array() ) use ( $site_info_fields ): array {

src/wp-settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@
290290
require ABSPATH . WPINC . '/abilities-api/class-wp-ability.php';
291291
require ABSPATH . WPINC . '/abilities-api/class-wp-abilities-registry.php';
292292
require ABSPATH . WPINC . '/abilities-api.php';
293-
require ABSPATH . WPINC . '/abilities/wp-core-abilities.php';
293+
require ABSPATH . WPINC . '/abilities.php';
294294
require ABSPATH . WPINC . '/rest-api.php';
295295
require ABSPATH . WPINC . '/rest-api/class-wp-rest-server.php';
296296
require ABSPATH . WPINC . '/rest-api/class-wp-rest-response.php';

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
/**
66
* Tests for the core abilities shipped with the Abilities API.
77
*
8+
* @covers wp_register_core_ability_categories
9+
* @covers wp_register_core_abilities
10+
*
811
* @group abilities-api
912
*/
10-
class Tests_Abilities_API_WpCoreAbilities extends WP_UnitTestCase {
13+
class Tests_Abilities_API_WpRegisterCoreAbilities extends WP_UnitTestCase {
1114

1215
/**
1316
* Set up before the class.
@@ -27,10 +30,27 @@ public static function set_up_before_class(): void {
2730
add_action( 'wp_abilities_api_init', 'wp_register_core_abilities' );
2831
do_action( 'wp_abilities_api_categories_init' );
2932
do_action( 'wp_abilities_api_init' );
33+
}
3034

35+
/**
36+
* Tear down after the class.
37+
*
38+
* @since 6.9.0
39+
*/
40+
public static function tear_down_after_class(): void {
3141
// Re-add the unhook functions for subsequent tests.
3242
add_action( 'wp_abilities_api_categories_init', '_unhook_core_ability_categories_registration', 1 );
3343
add_action( 'wp_abilities_api_init', '_unhook_core_abilities_registration', 1 );
44+
45+
// Remove the core abilities and their categories.
46+
foreach ( wp_get_abilities() as $ability ) {
47+
wp_unregister_ability( $ability->get_name() );
48+
}
49+
foreach ( wp_get_ability_categories() as $ability_category ) {
50+
wp_unregister_ability_category( $ability_category->get_slug() );
51+
}
52+
53+
parent::tear_down_after_class();
3454
}
3555

3656
/**

0 commit comments

Comments
 (0)