@@ -14,18 +14,19 @@ Feature: Manage WordPress abilities
1414
1515 @require-wp-6.9
1616 Scenario : List abilities
17+ When I run `wp ability list --format=count`
18+ Then save STDOUT as {ABILITIES_COUNT}
19+
1720 Given a wp-content/mu-plugins/test-abilities.php file:
1821 """
1922 <?php
20- add_action( 'init', function() {
21- if ( ! function_exists( 'wp_register_ability' ) ) {
22- return;
23- }
24-
25- wp_register_ability( 'test_ability_1', array(
26- 'category' => 'content',
23+ add_action( 'wp_abilities_api_init', function() {
24+ wp_register_ability( 'my-plugin/test-ability-1', array(
25+ 'label' => 'Test Ability 1',
26+ 'category' => 'site',
2727 'description' => 'Test ability one',
28- 'callback' => function( $input ) {
28+ 'permission_callback' => '__return_true',
29+ 'execute_callback' => function( $input ) {
2930 return array( 'result' => 'success', 'input' => $input );
3031 },
3132 'input_schema' => array(
@@ -38,11 +39,13 @@ Feature: Manage WordPress abilities
3839 'type' => 'object',
3940 ),
4041 ) );
41-
42- wp_register_ability( 'test_ability_2', array(
43- 'category' => 'users',
42+
43+ wp_register_ability( 'my-plugin/test-ability-2', array(
44+ 'label' => 'Test Ability 2',
45+ 'category' => 'user',
4446 'description' => 'Test ability two',
45- 'callback' => function( $input ) {
47+ 'permission_callback' => '__return_true',
48+ 'execute_callback' => function( $input ) {
4649 return array( 'result' => 'done' );
4750 },
4851 'input_schema' => array( 'type' => 'object' ),
@@ -52,41 +55,33 @@ Feature: Manage WordPress abilities
5255 """
5356
5457 When I run `wp ability list --format=count`
55- Then STDOUT should contain:
58+ Then STDOUT should not contain:
5659 """
57- 2
60+ {ABILITIES_COUNT}
5861 """
5962
6063 When I run `wp ability list --fields=name,category,description --format=csv`
6164 Then STDOUT should contain:
6265 """
63- test_ability_1,content ,"Test ability one"
66+ my-plugin/test-ability-1,site ,"Test ability one"
6467 """
6568 And STDOUT should contain:
6669 """
67- test_ability_2,users,"Test ability two"
68- """
69-
70- When I run `wp ability list --category=content --format=count`
71- Then STDOUT should contain:
72- """
73- 1
70+ my-plugin/test-ability-2,user,"Test ability two"
7471 """
7572
7673 @require-wp-6.9
7774 Scenario : Get a specific ability
7875 Given a wp-content/mu-plugins/test-abilities.php file:
7976 """
8077 <?php
81- add_action( 'init', function() {
82- if ( ! function_exists( 'wp_register_ability' ) ) {
83- return;
84- }
85-
86- wp_register_ability( 'get_test_post', array(
87- 'category' => 'content',
78+ add_action( 'wp_abilities_api_init', function() {
79+ wp_register_ability( 'my-plugin/get-test-post', array(
80+ 'label' => 'Get Test Post',
81+ 'category' => 'site',
8882 'description' => 'Gets a test post',
89- 'callback' => function( $input ) {
83+ 'permission_callback' => '__return_true',
84+ 'execute_callback' => function( $input ) {
9085 return array( 'id' => $input['id'], 'title' => 'Test Post' );
9186 },
9287 'input_schema' => array(
@@ -109,13 +104,13 @@ Feature: Manage WordPress abilities
109104 """
110105 And the return code should be 1
111106
112- When I run `wp ability get get_test_post --field=category`
107+ When I run `wp ability get my-plugin/get-test-post --field=category`
113108 Then STDOUT should be:
114109 """
115- content
110+ site
116111 """
117112
118- When I run `wp ability get get_test_post --field=description`
113+ When I run `wp ability get my-plugin/get-test-post --field=description`
119114 Then STDOUT should be:
120115 """
121116 Gets a test post
@@ -126,15 +121,13 @@ Feature: Manage WordPress abilities
126121 Given a wp-content/mu-plugins/test-abilities.php file:
127122 """
128123 <?php
129- add_action( 'init', function() {
130- if ( ! function_exists( 'wp_register_ability' ) ) {
131- return;
132- }
133-
134- wp_register_ability( 'test_exists', array(
135- 'category' => 'content',
124+ add_action( 'wp_abilities_api_init', function() {
125+ wp_register_ability( 'my-plugin/test-exists', array(
126+ 'label' => 'Test Exists',
127+ 'category' => 'site',
136128 'description' => 'Test exists',
137- 'callback' => function( $input ) {
129+ 'permission_callback' => '__return_true',
130+ 'execute_callback' => function( $input ) {
138131 return array( 'result' => 'ok' );
139132 },
140133 'input_schema' => array( 'type' => 'object' ),
@@ -143,26 +136,24 @@ Feature: Manage WordPress abilities
143136 } );
144137 """
145138
146- When I try `wp ability exists test_exists `
139+ When I try `wp ability exists my-plugin/test-exists `
147140 Then the return code should be 0
148141
149- When I try `wp ability exists non_existent_ability `
142+ When I try `wp ability exists non-existent-ability `
150143 Then the return code should be 1
151144
152145 @require-wp-6.9
153146 Scenario : Execute an ability with JSON input
154147 Given a wp-content/mu-plugins/test-abilities.php file:
155148 """
156149 <?php
157- add_action( 'init', function() {
158- if ( ! function_exists( 'wp_register_ability' ) ) {
159- return;
160- }
161-
162- wp_register_ability( 'echo_input', array(
163- 'category' => 'testing',
150+ add_action( 'wp_abilities_api_init', function() {
151+ wp_register_ability( 'my-plugin/echo-input', array(
152+ 'label' => 'Echo Input',
153+ 'category' => 'site',
164154 'description' => 'Echoes input',
165- 'callback' => function( $input ) {
155+ 'permission_callback' => '__return_true',
156+ 'execute_callback' => function( $input ) {
166157 return array( 'echoed' => $input );
167158 },
168159 'input_schema' => array( 'type' => 'object' ),
@@ -171,14 +162,14 @@ Feature: Manage WordPress abilities
171162 } );
172163 """
173164
174- When I try `wp ability execute non_existent_ability '{"test": "data"}' `
165+ When I try `wp ability execute non-existent-ability '{"test": "data"}' `
175166 Then STDERR should contain:
176167 """
177- Error: Ability non_existent_ability doesn't exist.
168+ Error: Ability non-existent-ability doesn't exist.
178169 """
179170 And the return code should be 1
180171
181- When I run `wp ability execute echo_input '{"message": "hello"}' `
172+ When I run `wp ability execute my-plugin/echo-input '{"message": "hello"}' `
182173 Then STDOUT should contain:
183174 """
184175 "echoed"
@@ -191,25 +182,19 @@ Feature: Manage WordPress abilities
191182 """
192183 "hello"
193184 """
194- And STDOUT should contain:
195- """
196- Success: Ability executed successfully.
197- """
198185
199186 @require-wp-6.9
200187 Scenario : Execute an ability with input from STDIN
201188 Given a wp-content/mu-plugins/test-abilities.php file:
202189 """
203190 <?php
204- add_action( 'init', function() {
205- if ( ! function_exists( 'wp_register_ability' ) ) {
206- return;
207- }
208-
209- wp_register_ability( 'process_input', array(
210- 'category' => 'testing',
191+ add_action( 'wp_abilities_api_init', function() {
192+ wp_register_ability( 'my-plugin/process-input', array(
193+ 'label' => 'Process Input',
194+ 'category' => 'site',
211195 'description' => 'Processes input',
212- 'callback' => function( $input ) {
196+ 'permission_callback' => '__return_true',
197+ 'execute_callback' => function( $input ) {
213198 return array( 'processed' => true, 'data' => $input );
214199 },
215200 'input_schema' => array( 'type' => 'object' ),
@@ -218,7 +203,7 @@ Feature: Manage WordPress abilities
218203 } );
219204 """
220205
221- When I run `echo '{"value": 42}' | wp ability execute process_input `
206+ When I run `echo '{"value": 42}' | wp ability execute my-plugin/process-input `
222207 Then STDOUT should contain:
223208 """
224209 "processed": true
@@ -227,7 +212,3 @@ Feature: Manage WordPress abilities
227212 """
228213 "value": 42
229214 """
230- And STDOUT should contain:
231- """
232- Success: Ability executed successfully.
233- """
0 commit comments