-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathability.feature
More file actions
560 lines (497 loc) · 19.6 KB
/
Copy pathability.feature
File metadata and controls
560 lines (497 loc) · 19.6 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
Feature: Manage abilities registered via the WordPress Abilities API.
Background:
Given a WP install
@less-than-wp-6.9
Scenario: Require WordPress 6.9 or greater.
When I try `wp ability list`
Then STDERR should contain:
"""
Error: Requires WordPress 6.9 or greater.
"""
@require-wp-6.9
Scenario: Register and list abilities.
Given a wp-content/mu-plugins/test-ability.php file:
"""
<?php
add_action( 'wp_abilities_api_categories_init', function() {
wp_register_ability_category( 'test-category', array(
'label' => 'Test Category',
'description' => 'A test category for abilities.',
) );
} );
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'test-plugin/get-site-title', array(
'label' => 'Get Site Title',
'description' => 'Returns the site title.',
'category' => 'test-category',
'execute_callback' => function( $input ) {
return array( 'title' => get_bloginfo( 'name' ) );
},
'permission_callback' => '__return_true',
'meta' => array( 'show_in_rest' => true ),
) );
wp_register_ability( 'test-plugin/echo-input', array(
'label' => 'Echo Input',
'description' => 'Echoes back the input.',
'category' => 'test-category',
'execute_callback' => function( $input ) {
return $input;
},
'permission_callback' => '__return_true',
) );
} );
"""
When I run `wp ability list`
Then STDOUT should be a table containing rows:
| name | label | category | description |
| test-plugin/get-site-title | Get Site Title | test-category | Returns the site title. |
| test-plugin/echo-input | Echo Input | test-category | Echoes back the input. |
When I run `wp ability list --field=name`
Then STDOUT should contain:
"""
test-plugin/get-site-title
"""
And STDOUT should contain:
"""
test-plugin/echo-input
"""
When I run `wp ability list --category=test-category`
Then STDOUT should be a table containing rows:
| name | label | category | description |
| test-plugin/get-site-title | Get Site Title | test-category | Returns the site title. |
When I run `wp ability list --category=nonexistent --format=count`
Then STDOUT should be:
"""
0
"""
When I run `wp ability list --format=json`
Then STDOUT should contain:
"""
"name":"test-plugin\/get-site-title"
"""
@require-wp-6.9
Scenario: Get ability details.
Given a wp-content/mu-plugins/test-ability.php file:
"""
<?php
add_action( 'wp_abilities_api_categories_init', function() {
wp_register_ability_category( 'test-category', array(
'label' => 'Test Category',
'description' => 'A test category.',
) );
} );
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'test-plugin/get-site-title', array(
'label' => 'Get Site Title',
'description' => 'Returns the site title.',
'category' => 'test-category',
'execute_callback' => function( $input ) {
return array( 'title' => get_bloginfo( 'name' ) );
},
'permission_callback' => '__return_true',
'meta' => array( 'show_in_rest' => true ),
) );
} );
"""
When I run `wp ability get test-plugin/get-site-title`
Then STDOUT should be a table containing rows:
| Field | Value |
| name | test-plugin/get-site-title |
| label | Get Site Title |
| category | test-category |
| description | Returns the site title. |
When I run `wp ability get test-plugin/get-site-title --field=label`
Then STDOUT should be:
"""
Get Site Title
"""
When I run `wp ability get test-plugin/get-site-title --format=json`
Then STDOUT should be JSON containing:
"""
{"name":"test-plugin/get-site-title"}
"""
When I try `wp ability get nonexistent/ability`
Then STDERR should be:
"""
Error: Ability 'nonexistent/ability' not found.
"""
@require-wp-6.9
Scenario: Execute an ability.
Given a wp-content/mu-plugins/test-ability.php file:
"""
<?php
add_action( 'wp_abilities_api_categories_init', function() {
wp_register_ability_category( 'test-category', array(
'label' => 'Test Category',
'description' => 'A test category.',
) );
} );
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'test-plugin/get-site-title', array(
'label' => 'Get Site Title',
'description' => 'Returns the site title.',
'category' => 'test-category',
'input_schema' => array(
'type' => 'object',
'properties' => array(),
),
'execute_callback' => function( $input ) {
return array( 'title' => get_bloginfo( 'name' ) );
},
'permission_callback' => '__return_true',
) );
wp_register_ability( 'test-plugin/echo-input', array(
'label' => 'Echo Input',
'description' => 'Echoes back the input.',
'category' => 'test-category',
'input_schema' => array(
'type' => 'object',
'additionalProperties' => true,
),
'execute_callback' => function( $input ) {
return $input;
},
'permission_callback' => '__return_true',
) );
wp_register_ability( 'test-plugin/add-numbers', array(
'label' => 'Add Numbers',
'description' => 'Adds two numbers.',
'category' => 'test-category',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'a' => array( 'type' => 'integer' ),
'b' => array( 'type' => 'integer' ),
),
),
'execute_callback' => function( $input ) {
$a = isset( $input['a'] ) ? (int) $input['a'] : 0;
$b = isset( $input['b'] ) ? (int) $input['b'] : 0;
return array( 'sum' => $a + $b );
},
'permission_callback' => '__return_true',
) );
wp_register_ability( 'test-plugin/simple-no-input', array(
'label' => 'Simple No Input',
'description' => 'Returns an empty array.',
'category' => 'test-category',
'output_schema' => array(
'type' => 'array',
),
'execute_callback' => function() {
return array();
},
'permission_callback' => '__return_true',
) );
} );
"""
When I run `wp ability run test-plugin/get-site-title`
Then STDOUT should contain:
"""
"title":
"""
When I run `wp ability run test-plugin/echo-input --message=hello`
Then STDOUT should be JSON containing:
"""
{"message":"hello"}
"""
When I run `wp ability run test-plugin/echo-input --input='{"foo":"bar"}'`
Then STDOUT should be JSON containing:
"""
{"foo":"bar"}
"""
When I run `wp ability run test-plugin/add-numbers --a=5 --b=3`
Then STDOUT should be JSON containing:
"""
{"sum":8}
"""
When I run `wp ability run test-plugin/add-numbers --input='{"a":10,"b":20}'`
Then STDOUT should be JSON containing:
"""
{"sum":30}
"""
When I run `wp ability run test-plugin/simple-no-input`
Then STDOUT should be:
"""
[]
"""
When I run `wp ability run test-plugin/get-site-title --format=yaml`
Then STDOUT should contain:
"""
title:
"""
When I try `wp ability run nonexistent/ability`
Then STDERR should be:
"""
Error: Ability 'nonexistent/ability' not found.
"""
When I try `wp ability run test-plugin/echo-input --input='invalid json'`
Then STDERR should be:
"""
Error: Invalid JSON provided for --input.
"""
@require-wp-6.9
Scenario: Check if ability exists.
Given a wp-content/mu-plugins/test-ability.php file:
"""
<?php
add_action( 'wp_abilities_api_categories_init', function() {
wp_register_ability_category( 'test-category', array(
'label' => 'Test Category',
'description' => 'A test category.',
) );
} );
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'test-plugin/get-site-title', array(
'label' => 'Get Site Title',
'description' => 'Returns the site title.',
'category' => 'test-category',
'execute_callback' => function( $input ) {
return array( 'title' => get_bloginfo( 'name' ) );
},
'permission_callback' => '__return_true',
) );
} );
"""
When I run `wp ability exists test-plugin/get-site-title`
Then the return code should be 0
When I try `wp ability exists nonexistent/ability`
Then the return code should be 1
@require-wp-6.9
Scenario: Filter abilities by namespace.
Given a wp-content/mu-plugins/test-ability.php file:
"""
<?php
add_action( 'wp_abilities_api_categories_init', function() {
wp_register_ability_category( 'test-category', array(
'label' => 'Test Category',
'description' => 'A test category.',
) );
} );
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'test-plugin/get-site-title', array(
'label' => 'Get Site Title',
'description' => 'Returns the site title.',
'category' => 'test-category',
'execute_callback' => function( $input ) {
return array( 'title' => get_bloginfo( 'name' ) );
},
'permission_callback' => '__return_true',
'meta' => array( 'show_in_rest' => true ),
) );
wp_register_ability( 'other-plugin/do-something', array(
'label' => 'Do Something',
'description' => 'Does something.',
'category' => 'test-category',
'execute_callback' => function( $input ) {
return array( 'result' => 'done' );
},
'permission_callback' => '__return_true',
'meta' => array( 'show_in_rest' => false ),
) );
} );
"""
When I run `wp ability list --namespace=test-plugin --format=count`
Then STDOUT should contain:
"""
1
"""
When I run `wp ability list --namespace=other-plugin --field=name`
Then STDOUT should contain:
"""
other-plugin/do-something
"""
When I run `wp ability list --namespace=nonexistent --format=count`
Then STDOUT should be:
"""
0
"""
@require-wp-6.9
Scenario: Filter abilities by show_in_rest.
Given a wp-content/mu-plugins/test-ability.php file:
"""
<?php
add_action( 'wp_abilities_api_categories_init', function() {
wp_register_ability_category( 'test-category', array(
'label' => 'Test Category',
'description' => 'A test category.',
) );
} );
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'test-plugin/public-ability', array(
'label' => 'Public Ability',
'description' => 'A public ability.',
'category' => 'test-category',
'execute_callback' => function( $input ) {
return array( 'public' => true );
},
'permission_callback' => '__return_true',
'meta' => array( 'show_in_rest' => true ),
) );
wp_register_ability( 'test-plugin/private-ability', array(
'label' => 'Private Ability',
'description' => 'A private ability.',
'category' => 'test-category',
'execute_callback' => function( $input ) {
return array( 'private' => true );
},
'permission_callback' => '__return_true',
'meta' => array( 'show_in_rest' => false ),
) );
} );
"""
When I run `wp ability list --namespace=test-plugin --show-in-rest=true --field=name`
Then STDOUT should be:
"""
test-plugin/public-ability
"""
When I run `wp ability list --namespace=test-plugin --show-in-rest=false --field=name`
Then STDOUT should be:
"""
test-plugin/private-ability
"""
@require-wp-6.9
Scenario: Display ability annotations.
Given a wp-content/mu-plugins/test-ability.php file:
"""
<?php
add_action( 'wp_abilities_api_categories_init', function() {
wp_register_ability_category( 'test-category', array(
'label' => 'Test Category',
'description' => 'A test category.',
) );
} );
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'test-plugin/annotated-ability', array(
'label' => 'Annotated Ability',
'description' => 'An ability with annotations.',
'category' => 'test-category',
'execute_callback' => function( $input ) {
return array( 'result' => 'done' );
},
'permission_callback' => '__return_true',
'meta' => array(
'annotations' => array(
'readonly' => true,
'destructive' => false,
'idempotent' => true,
),
),
) );
} );
"""
When I run `wp ability get test-plugin/annotated-ability --format=json`
Then STDOUT should be JSON containing:
"""
{"readonly":"1","destructive":"0","idempotent":"1"}
"""
When I run `wp ability list --namespace=test-plugin --fields=name,readonly,destructive,idempotent`
Then STDOUT should be a table containing rows:
| name | readonly | destructive | idempotent |
| test-plugin/annotated-ability | 1 | 0 | 1 |
@require-wp-6.9
Scenario: Check permission to run an ability.
Given a wp-content/mu-plugins/test-ability.php file:
"""
<?php
add_action( 'wp_abilities_api_categories_init', function() {
wp_register_ability_category( 'test-category', array(
'label' => 'Test Category',
'description' => 'A test category.',
) );
} );
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'test-plugin/allowed-ability', array(
'label' => 'Allowed Ability',
'description' => 'An ability anyone can run.',
'category' => 'test-category',
'execute_callback' => function( $input ) {
return array( 'allowed' => true );
},
'permission_callback' => '__return_true',
) );
wp_register_ability( 'test-plugin/denied-ability', array(
'label' => 'Denied Ability',
'description' => 'An ability no one can run.',
'category' => 'test-category',
'execute_callback' => function( $input ) {
return array( 'denied' => true );
},
'permission_callback' => '__return_false',
) );
} );
"""
When I run `wp ability can-run test-plugin/allowed-ability`
Then the return code should be 0
When I try `wp ability can-run test-plugin/denied-ability`
Then the return code should be 1
When I try `wp ability can-run nonexistent/ability`
Then STDERR should be:
"""
Error: Ability 'nonexistent/ability' not found.
"""
@require-wp-6.9
Scenario: Validate ability input.
Given a wp-content/mu-plugins/test-ability.php file:
"""
<?php
add_action( 'wp_abilities_api_categories_init', function() {
wp_register_ability_category( 'test-category', array(
'label' => 'Test Category',
'description' => 'A test category.',
) );
} );
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'test-plugin/typed-ability', array(
'label' => 'Typed Ability',
'description' => 'An ability with typed input.',
'category' => 'test-category',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'count' => array( 'type' => 'integer' ),
'name' => array( 'type' => 'string' ),
),
'required' => array( 'count' ),
),
'execute_callback' => function( $input ) {
return $input;
},
'permission_callback' => '__return_true',
) );
wp_register_ability( 'test-plugin/no-input-ability', array(
'label' => 'No Input Ability',
'description' => 'An ability with no input schema.',
'category' => 'test-category',
'execute_callback' => function( $input ) {
return array( 'no_input' => true );
},
'permission_callback' => '__return_true',
) );
} );
"""
When I run `wp ability validate test-plugin/typed-ability --count=5 --name=test`
Then STDOUT should be:
"""
Success: Input is valid.
"""
When I run `wp ability validate test-plugin/typed-ability --input='{"count":10,"name":"hello"}'`
Then STDOUT should be:
"""
Success: Input is valid.
"""
When I try `wp ability validate test-plugin/typed-ability --name=test`
Then STDERR should contain:
"""
Error:
"""
When I run `wp ability validate test-plugin/no-input-ability`
Then STDOUT should be:
"""
Success: Input is valid.
"""
When I try `wp ability validate nonexistent/ability`
Then STDERR should be:
"""
Error: Ability 'nonexistent/ability' not found.
"""