11
11
class Tests_Abilities_API_Register extends WP_UnitTestCase {
12
12
13
13
public static $ test_ability_name = 'test/add-numbers ' ;
14
- public static $ test_ability_properties = [] ;
14
+ public static $ test_ability_properties = array () ;
15
15
16
16
/**
17
17
* Set up before each test.
18
18
*/
19
19
public function set_up (): void {
20
20
parent ::set_up ();
21
21
22
- self ::$ test_ability_properties = [
22
+ self ::$ test_ability_properties = array (
23
23
'label ' => 'Add numbers ' ,
24
24
'description ' => 'Calculates the result of adding two numbers. ' ,
25
- 'input_schema ' => [
25
+ 'input_schema ' => array (
26
26
'type ' => 'object ' ,
27
- 'properties ' => [
28
- 'a ' => [
27
+ 'properties ' => array (
28
+ 'a ' => array (
29
29
'type ' => 'number ' ,
30
30
'description ' => 'First number. ' ,
31
31
'required ' => true ,
32
- ] ,
33
- 'b ' => [
32
+ ) ,
33
+ 'b ' => array (
34
34
'type ' => 'number ' ,
35
35
'description ' => 'Second number. ' ,
36
36
'required ' => true ,
37
- ] ,
38
- ] ,
37
+ ) ,
38
+ ) ,
39
39
'additionalProperties ' => false ,
40
- ] ,
41
- 'output_schema ' => [
40
+ ) ,
41
+ 'output_schema ' => array (
42
42
'type ' => 'number ' ,
43
43
'description ' => 'The result of adding the two numbers. ' ,
44
44
'required ' => true ,
45
- ] ,
45
+ ) ,
46
46
'execute_callback ' => function ( array $ input ): int {
47
47
return $ input ['a ' ] + $ input ['b ' ];
48
48
},
49
49
'permission_callback ' => function (): bool {
50
50
return true ;
51
51
},
52
- 'meta ' => [
52
+ 'meta ' => array (
53
53
'category ' => 'math ' ,
54
- ] ,
55
- ] ;
54
+ ) ,
55
+ ) ;
56
56
}
57
57
58
58
/**
@@ -76,7 +76,7 @@ public function tear_down(): void {
76
76
public function test_register_ability_invalid_name (): void {
77
77
do_action ( 'abilities_api_init ' );
78
78
79
- $ result = wp_register_ability ( 'invalid_name ' , [] );
79
+ $ result = wp_register_ability ( 'invalid_name ' , array () );
80
80
81
81
$ this ->assertNull ( $ result );
82
82
}
@@ -107,8 +107,23 @@ public function test_register_valid_ability(): void {
107
107
$ this ->assertSame ( self ::$ test_ability_properties ['input_schema ' ], $ result ->get_input_schema () );
108
108
$ this ->assertSame ( self ::$ test_ability_properties ['output_schema ' ], $ result ->get_output_schema () );
109
109
$ this ->assertSame ( self ::$ test_ability_properties ['meta ' ], $ result ->get_meta () );
110
- $ this ->assertTrue ( $ result ->has_permission ( [ 'a ' => 2 , 'b ' => 3 ] ) );
111
- $ this ->assertSame ( 5 , $ result ->execute ( [ 'a ' => 2 , 'b ' => 3 ] ) );
110
+ $ this ->assertTrue (
111
+ $ result ->has_permission (
112
+ array (
113
+ 'a ' => 2 ,
114
+ 'b ' => 3 ,
115
+ )
116
+ )
117
+ );
118
+ $ this ->assertSame (
119
+ 5 ,
120
+ $ result ->execute (
121
+ array (
122
+ 'a ' => 2 ,
123
+ 'b ' => 3 ,
124
+ )
125
+ )
126
+ );
112
127
}
113
128
114
129
/**
@@ -124,8 +139,22 @@ public function test_register_ability_no_permissions(): void {
124
139
};
125
140
$ result = wp_register_ability ( self ::$ test_ability_name , self ::$ test_ability_properties );
126
141
127
- $ this ->assertFalse ( $ result ->has_permission ( [ 'a ' => 2 , 'b ' => 3 ] ) );
128
- $ this ->assertNull ( $ result ->execute ( [ 'a ' => 2 , 'b ' => 3 ] ) );
142
+ $ this ->assertFalse (
143
+ $ result ->has_permission (
144
+ array (
145
+ 'a ' => 2 ,
146
+ 'b ' => 3 ,
147
+ )
148
+ )
149
+ );
150
+ $ this ->assertNull (
151
+ $ result ->execute (
152
+ array (
153
+ 'a ' => 2 ,
154
+ 'b ' => 3 ,
155
+ )
156
+ )
157
+ );
129
158
}
130
159
131
160
/**
@@ -139,7 +168,15 @@ public function test_execute_ability_no_input_schema_match(): void {
139
168
140
169
$ result = wp_register_ability ( self ::$ test_ability_name , self ::$ test_ability_properties );
141
170
142
- $ this ->assertNull ( $ result ->execute ( [ 'a ' => 2 , 'b ' => 3 , 'unknown ' => 1 ] ) );
171
+ $ this ->assertNull (
172
+ $ result ->execute (
173
+ array (
174
+ 'a ' => 2 ,
175
+ 'b ' => 3 ,
176
+ 'unknown ' => 1 ,
177
+ )
178
+ )
179
+ );
143
180
}
144
181
145
182
/**
@@ -155,7 +192,14 @@ public function test_execute_ability_no_output_schema_match(): void {
155
192
};
156
193
$ result = wp_register_ability ( self ::$ test_ability_name , self ::$ test_ability_properties );
157
194
158
- $ this ->assertNull ( $ result ->execute ( [ 'a ' => 2 , 'b ' => 3 ] ) );
195
+ $ this ->assertNull (
196
+ $ result ->execute (
197
+ array (
198
+ 'a ' => 2 ,
199
+ 'b ' => 3 ,
200
+ )
201
+ )
202
+ );
159
203
}
160
204
161
205
/**
@@ -168,7 +212,15 @@ public function test_permission_callback_no_input_schema_match(): void {
168
212
169
213
$ result = wp_register_ability ( self ::$ test_ability_name , self ::$ test_ability_properties );
170
214
171
- $ this ->assertFalse ( $ result ->has_permission ( [ 'a ' => 2 , 'b ' => 3 , 'unknown ' => 1 ] ) );
215
+ $ this ->assertFalse (
216
+ $ result ->has_permission (
217
+ array (
218
+ 'a ' => 2 ,
219
+ 'b ' => 3 ,
220
+ 'unknown ' => 1 ,
221
+ )
222
+ )
223
+ );
172
224
}
173
225
174
226
/**
@@ -186,12 +238,38 @@ public function test_permission_callback_receives_input(): void {
186
238
$ result = wp_register_ability ( self ::$ test_ability_name , self ::$ test_ability_properties );
187
239
188
240
// Test with a > b (should be allowed)
189
- $ this ->assertTrue ( $ result ->has_permission ( [ 'a ' => 5 , 'b ' => 3 ] ) );
190
- $ this ->assertSame ( [ 'a ' => 5 , 'b ' => 3 ], $ received_input );
241
+ $ this ->assertTrue (
242
+ $ result ->has_permission (
243
+ array (
244
+ 'a ' => 5 ,
245
+ 'b ' => 3 ,
246
+ )
247
+ )
248
+ );
249
+ $ this ->assertSame (
250
+ array (
251
+ 'a ' => 5 ,
252
+ 'b ' => 3 ,
253
+ ),
254
+ $ received_input
255
+ );
191
256
192
257
// Test with a < b (should be denied)
193
- $ this ->assertFalse ( $ result ->has_permission ( [ 'a ' => 2 , 'b ' => 8 ] ) );
194
- $ this ->assertSame ( [ 'a ' => 2 , 'b ' => 8 ], $ received_input );
258
+ $ this ->assertFalse (
259
+ $ result ->has_permission (
260
+ array (
261
+ 'a ' => 2 ,
262
+ 'b ' => 8 ,
263
+ )
264
+ )
265
+ );
266
+ $ this ->assertSame (
267
+ array (
268
+ 'a ' => 2 ,
269
+ 'b ' => 8 ,
270
+ ),
271
+ $ received_input
272
+ );
195
273
}
196
274
197
275
/**
0 commit comments