1111class Tests_Abilities_API_Register extends WP_UnitTestCase {
1212
1313 public static $ test_ability_name = 'test/add-numbers ' ;
14- public static $ test_ability_properties = [] ;
14+ public static $ test_ability_properties = array () ;
1515
1616 /**
1717 * Set up before each test.
1818 */
1919 public function set_up (): void {
2020 parent ::set_up ();
2121
22- self ::$ test_ability_properties = [
22+ self ::$ test_ability_properties = array (
2323 'label ' => 'Add numbers ' ,
2424 'description ' => 'Calculates the result of adding two numbers. ' ,
25- 'input_schema ' => [
25+ 'input_schema ' => array (
2626 'type ' => 'object ' ,
27- 'properties ' => [
28- 'a ' => [
27+ 'properties ' => array (
28+ 'a ' => array (
2929 'type ' => 'number ' ,
3030 'description ' => 'First number. ' ,
3131 'required ' => true ,
32- ] ,
33- 'b ' => [
32+ ) ,
33+ 'b ' => array (
3434 'type ' => 'number ' ,
3535 'description ' => 'Second number. ' ,
3636 'required ' => true ,
37- ] ,
38- ] ,
37+ ) ,
38+ ) ,
3939 'additionalProperties ' => false ,
40- ] ,
41- 'output_schema ' => [
40+ ) ,
41+ 'output_schema ' => array (
4242 'type ' => 'number ' ,
4343 'description ' => 'The result of adding the two numbers. ' ,
4444 'required ' => true ,
45- ] ,
45+ ) ,
4646 'execute_callback ' => function ( array $ input ): int {
4747 return $ input ['a ' ] + $ input ['b ' ];
4848 },
4949 'permission_callback ' => function (): bool {
5050 return true ;
5151 },
52- 'meta ' => [
52+ 'meta ' => array (
5353 'category ' => 'math ' ,
54- ] ,
55- ] ;
54+ ) ,
55+ ) ;
5656 }
5757
5858 /**
@@ -76,7 +76,7 @@ public function tear_down(): void {
7676 public function test_register_ability_invalid_name (): void {
7777 do_action ( 'abilities_api_init ' );
7878
79- $ result = wp_register_ability ( 'invalid_name ' , [] );
79+ $ result = wp_register_ability ( 'invalid_name ' , array () );
8080
8181 $ this ->assertNull ( $ result );
8282 }
@@ -107,8 +107,23 @@ public function test_register_valid_ability(): void {
107107 $ this ->assertSame ( self ::$ test_ability_properties ['input_schema ' ], $ result ->get_input_schema () );
108108 $ this ->assertSame ( self ::$ test_ability_properties ['output_schema ' ], $ result ->get_output_schema () );
109109 $ 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+ );
112127 }
113128
114129 /**
@@ -124,8 +139,22 @@ public function test_register_ability_no_permissions(): void {
124139 };
125140 $ result = wp_register_ability ( self ::$ test_ability_name , self ::$ test_ability_properties );
126141
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+ );
129158 }
130159
131160 /**
@@ -139,7 +168,15 @@ public function test_execute_ability_no_input_schema_match(): void {
139168
140169 $ result = wp_register_ability ( self ::$ test_ability_name , self ::$ test_ability_properties );
141170
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+ );
143180 }
144181
145182 /**
@@ -155,7 +192,14 @@ public function test_execute_ability_no_output_schema_match(): void {
155192 };
156193 $ result = wp_register_ability ( self ::$ test_ability_name , self ::$ test_ability_properties );
157194
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+ );
159203 }
160204
161205 /**
@@ -168,7 +212,15 @@ public function test_permission_callback_no_input_schema_match(): void {
168212
169213 $ result = wp_register_ability ( self ::$ test_ability_name , self ::$ test_ability_properties );
170214
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+ );
172224 }
173225
174226 /**
@@ -186,12 +238,38 @@ public function test_permission_callback_receives_input(): void {
186238 $ result = wp_register_ability ( self ::$ test_ability_name , self ::$ test_ability_properties );
187239
188240 // 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+ );
191256
192257 // 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+ );
195273 }
196274
197275 /**
0 commit comments