Skip to content

Commit bac8b0f

Browse files
committed
Fix tests
1 parent 8473bbb commit bac8b0f

File tree

4 files changed

+97
-158
lines changed

4 files changed

+97
-158
lines changed

features/ability-category.feature

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,50 @@ Feature: Manage WordPress ability categories
1414

1515
@require-wp-6.9
1616
Scenario: List ability categories
17+
When I run `wp ability category list --format=count`
18+
Then save STDOUT as {COUNT}
19+
1720
Given a wp-content/mu-plugins/test-ability-categories.php file:
1821
"""
1922
<?php
20-
add_action( 'init', function() {
21-
if ( ! function_exists( 'wp_register_ability_category' ) ) {
22-
return;
23-
}
24-
25-
wp_register_ability_category( 'test_category_1', array(
23+
add_action( 'wp_abilities_api_categories_init', function() {
24+
wp_register_ability_category( 'test-category-1', array(
25+
'label' => 'First test category',
2626
'description' => 'First test category',
2727
) );
28-
29-
wp_register_ability_category( 'test_category_2', array(
28+
29+
wp_register_ability_category( 'test-category-2', array(
30+
'label' => 'Second test category',
3031
'description' => 'Second test category',
3132
) );
3233
} );
3334
"""
3435

3536
When I run `wp ability category list --format=count`
36-
Then STDOUT should contain:
37+
Then STDOUT should not contain:
3738
"""
38-
2
39+
{COUNT}
3940
"""
4041

41-
When I run `wp ability category list --fields=name,description --format=csv`
42+
When I run `wp ability category list --fields=slug,description --format=csv`
4243
Then STDOUT should contain:
4344
"""
44-
test_category_1,"First test category"
45+
test-category-1,"First test category"
4546
"""
4647
And STDOUT should contain:
4748
"""
48-
test_category_2,"Second test category"
49+
test-category-2,"Second test category"
4950
"""
5051

5152
@require-wp-6.9
5253
Scenario: Get a specific ability category
5354
Given a wp-content/mu-plugins/test-ability-categories.php file:
5455
"""
5556
<?php
56-
add_action( 'init', function() {
57-
if ( ! function_exists( 'wp_register_ability_category' ) ) {
58-
return;
59-
}
60-
61-
wp_register_ability_category( 'content_ops', array(
62-
'description' => 'Content operations category',
57+
add_action( 'wp_abilities_api_categories_init', function() {
58+
wp_register_ability_category( 'content', array(
59+
'label' => 'Content category',
60+
'description' => 'Content category',
6361
) );
6462
} );
6563
"""
@@ -71,35 +69,32 @@ Feature: Manage WordPress ability categories
7169
"""
7270
And the return code should be 1
7371

74-
When I run `wp ability category get content_ops --field=description`
72+
When I run `wp ability category get content --field=description`
7573
Then STDOUT should be:
7674
"""
77-
Content operations category
75+
Content category
7876
"""
7977

80-
When I run `wp ability category get content_ops --field=name`
78+
When I run `wp ability category get content --field=slug`
8179
Then STDOUT should be:
8280
"""
83-
content_ops
81+
content
8482
"""
8583

8684
@require-wp-6.9
8785
Scenario: Check if an ability category exists
8886
Given a wp-content/mu-plugins/test-ability-categories.php file:
8987
"""
9088
<?php
91-
add_action( 'init', function() {
92-
if ( ! function_exists( 'wp_register_ability_category' ) ) {
93-
return;
94-
}
95-
96-
wp_register_ability_category( 'existing_category', array(
89+
add_action( 'wp_abilities_api_categories_init', function() {
90+
wp_register_ability_category( 'existing-category', array(
91+
'label' => 'This category exists',
9792
'description' => 'This category exists',
9893
) );
9994
} );
10095
"""
10196

102-
When I try `wp ability category exists existing_category`
97+
When I try `wp ability category exists existing-category`
10398
Then the return code should be 0
10499

105100
When I try `wp ability category exists non_existent_category`

features/ability.feature

Lines changed: 52 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)