-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathability.feature
More file actions
214 lines (195 loc) · 6.34 KB
/
ability.feature
File metadata and controls
214 lines (195 loc) · 6.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
Feature: Manage WordPress abilities
Background:
Given a WP install
@less-than-wp-6.9
Scenario: Ability commands require WordPress 6.9+
When I try `wp ability list`
Then STDERR should contain:
"""
Error: Requires WordPress 6.9 or greater.
"""
And the return code should be 1
@require-wp-6.9
Scenario: List abilities
When I run `wp ability list --format=count`
Then save STDOUT as {ABILITIES_COUNT}
Given a wp-content/mu-plugins/test-abilities.php file:
"""
<?php
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'my-plugin/test-ability-1', array(
'label' => 'Test Ability 1',
'category' => 'site',
'description' => 'Test ability one',
'permission_callback' => '__return_true',
'execute_callback' => function( $input ) {
return array( 'result' => 'success', 'input' => $input );
},
'input_schema' => array(
'type' => 'object',
'properties' => array(
'id' => array( 'type' => 'integer' ),
),
),
'output_schema' => array(
'type' => 'object',
),
) );
wp_register_ability( 'my-plugin/test-ability-2', array(
'label' => 'Test Ability 2',
'category' => 'user',
'description' => 'Test ability two',
'permission_callback' => '__return_true',
'execute_callback' => function( $input ) {
return array( 'result' => 'done' );
},
'input_schema' => array( 'type' => 'object' ),
'output_schema' => array( 'type' => 'object' ),
) );
} );
"""
When I run `wp ability list --format=count`
Then STDOUT should not contain:
"""
{ABILITIES_COUNT}
"""
When I run `wp ability list --fields=name,category,description --format=csv`
Then STDOUT should contain:
"""
my-plugin/test-ability-1,site,"Test ability one"
"""
And STDOUT should contain:
"""
my-plugin/test-ability-2,user,"Test ability two"
"""
@require-wp-6.9
Scenario: Get a specific ability
Given a wp-content/mu-plugins/test-abilities.php file:
"""
<?php
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'my-plugin/get-test-post', array(
'label' => 'Get Test Post',
'category' => 'site',
'description' => 'Gets a test post',
'permission_callback' => '__return_true',
'execute_callback' => function( $input ) {
return array( 'id' => $input['id'], 'title' => 'Test Post' );
},
'input_schema' => array(
'type' => 'object',
'properties' => array(
'id' => array( 'type' => 'integer' ),
),
),
'output_schema' => array(
'type' => 'object',
),
) );
} );
"""
When I try `wp ability get invalid_ability`
Then STDERR should contain:
"""
Error: Ability invalid_ability doesn't exist.
"""
And the return code should be 1
When I run `wp ability get my-plugin/get-test-post --field=category`
Then STDOUT should be:
"""
site
"""
When I run `wp ability get my-plugin/get-test-post --field=description`
Then STDOUT should be:
"""
Gets a test post
"""
@require-wp-6.9
Scenario: Check if an ability exists
Given a wp-content/mu-plugins/test-abilities.php file:
"""
<?php
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'my-plugin/test-exists', array(
'label' => 'Test Exists',
'category' => 'site',
'description' => 'Test exists',
'permission_callback' => '__return_true',
'execute_callback' => function( $input ) {
return array( 'result' => 'ok' );
},
'input_schema' => array( 'type' => 'object' ),
'output_schema' => array( 'type' => 'object' ),
) );
} );
"""
When I try `wp ability exists my-plugin/test-exists`
Then the return code should be 0
When I try `wp ability exists non-existent-ability`
Then the return code should be 1
@require-wp-6.9
Scenario: Execute an ability with JSON input
Given a wp-content/mu-plugins/test-abilities.php file:
"""
<?php
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'my-plugin/echo-input', array(
'label' => 'Echo Input',
'category' => 'site',
'description' => 'Echoes input',
'permission_callback' => '__return_true',
'execute_callback' => function( $input ) {
return array( 'echoed' => $input );
},
'input_schema' => array( 'type' => 'object' ),
'output_schema' => array( 'type' => 'object' ),
) );
} );
"""
When I try `wp ability execute non-existent-ability '{"test": "data"}'`
Then STDERR should contain:
"""
Error: Ability non-existent-ability doesn't exist.
"""
And the return code should be 1
When I run `wp ability execute my-plugin/echo-input '{"message": "hello"}'`
Then STDOUT should contain:
"""
"echoed"
"""
And STDOUT should contain:
"""
"message"
"""
And STDOUT should contain:
"""
"hello"
"""
@require-wp-6.9
Scenario: Execute an ability with input from STDIN
Given a wp-content/mu-plugins/test-abilities.php file:
"""
<?php
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'my-plugin/process-input', array(
'label' => 'Process Input',
'category' => 'site',
'description' => 'Processes input',
'permission_callback' => '__return_true',
'execute_callback' => function( $input ) {
return array( 'processed' => true, 'data' => $input );
},
'input_schema' => array( 'type' => 'object' ),
'output_schema' => array( 'type' => 'object' ),
) );
} );
"""
When I run `echo '{"value": 42}' | wp ability execute my-plugin/process-input`
Then STDOUT should contain:
"""
"processed": true
"""
And STDOUT should contain:
"""
"value": 42
"""