@@ -54,7 +54,9 @@ public function set_up(): void {
5454 parent ::set_up ();
5555
5656 global $ wp_rest_server ;
57- $ this ->server = $ wp_rest_server = new WP_REST_Server ();
57+ $ wp_rest_server = new WP_REST_Server ();
58+ $ this ->server = $ wp_rest_server ;
59+
5860 do_action ( 'rest_api_init ' );
5961
6062 do_action ( 'abilities_api_init ' );
@@ -526,16 +528,18 @@ public function test_invalid_json_in_post_body(): void {
526528 */
527529 public function test_get_request_with_nested_input_array (): void {
528530 $ request = new WP_REST_Request ( 'GET ' , '/wp/v2/abilities/test/query-params/run ' );
529- $ request ->set_query_params ( array (
530- 'input ' => array (
531- 'level1 ' => array (
532- 'level2 ' => array (
533- 'value ' => 'nested ' ,
531+ $ request ->set_query_params (
532+ array (
533+ 'input ' => array (
534+ 'level1 ' => array (
535+ 'level2 ' => array (
536+ 'value ' => 'nested ' ,
537+ ),
534538 ),
539+ 'array ' => array ( 1 , 2 , 3 ),
535540 ),
536- 'array ' => array ( 1 , 2 , 3 ),
537- ),
538- ) );
541+ )
542+ );
539543
540544 $ response = $ this ->server ->dispatch ( $ request );
541545 $ this ->assertEquals ( 200 , $ response ->get_status () );
@@ -550,9 +554,11 @@ public function test_get_request_with_nested_input_array(): void {
550554 */
551555 public function test_get_request_with_non_array_input (): void {
552556 $ request = new WP_REST_Request ( 'GET ' , '/wp/v2/abilities/test/query-params/run ' );
553- $ request ->set_query_params ( array (
554- 'input ' => 'not-an-array ' , // String instead of array
555- ) );
557+ $ request ->set_query_params (
558+ array (
559+ 'input ' => 'not-an-array ' , // String instead of array
560+ )
561+ );
556562
557563 $ response = $ this ->server ->dispatch ( $ request );
558564 // When input is not an array, WordPress returns 400 Bad Request
@@ -565,9 +571,13 @@ public function test_get_request_with_non_array_input(): void {
565571 public function test_post_request_with_non_array_input (): void {
566572 $ request = new WP_REST_Request ( 'POST ' , '/wp/v2/abilities/test/calculator/run ' );
567573 $ request ->set_header ( 'Content-Type ' , 'application/json ' );
568- $ request ->set_body ( wp_json_encode ( array (
569- 'input ' => 'string-value ' , // String instead of array
570- ) ) );
574+ $ request ->set_body (
575+ wp_json_encode (
576+ array (
577+ 'input ' => 'string-value ' , // String instead of array
578+ )
579+ )
580+ );
571581
572582 $ response = $ this ->server ->dispatch ( $ request );
573583 // When input is not an array, WordPress returns 400 Bad Request
@@ -583,9 +593,9 @@ public function test_output_validation_failure_returns_error(): void {
583593 wp_register_ability (
584594 'test/strict-output ' ,
585595 array (
586- 'label ' => 'Strict Output ' ,
587- 'description ' => 'Ability with strict output schema ' ,
588- 'output_schema ' => array (
596+ 'label ' => 'Strict Output ' ,
597+ 'description ' => 'Ability with strict output schema ' ,
598+ 'output_schema ' => array (
589599 'type ' => 'object ' ,
590600 'properties ' => array (
591601 'status ' => array (
@@ -595,12 +605,12 @@ public function test_output_validation_failure_returns_error(): void {
595605 ),
596606 'required ' => array ( 'status ' ),
597607 ),
598- 'execute_callback ' => function ( $ input ) {
608+ 'execute_callback ' => function ( $ input ) {
599609 // Return invalid output that doesn't match schema
600610 return array ( 'wrong_field ' => 'value ' );
601611 },
602612 'permission_callback ' => '__return_true ' ,
603- 'meta ' => array ( 'type ' => 'tool ' ),
613+ 'meta ' => array ( 'type ' => 'tool ' ),
604614 )
605615 );
606616
@@ -625,9 +635,9 @@ public function test_input_validation_failure_returns_error(): void {
625635 wp_register_ability (
626636 'test/strict-input ' ,
627637 array (
628- 'label ' => 'Strict Input ' ,
629- 'description ' => 'Ability with strict input schema ' ,
630- 'input_schema ' => array (
638+ 'label ' => 'Strict Input ' ,
639+ 'description ' => 'Ability with strict input schema ' ,
640+ 'input_schema ' => array (
631641 'type ' => 'object ' ,
632642 'properties ' => array (
633643 'required_field ' => array (
@@ -636,11 +646,11 @@ public function test_input_validation_failure_returns_error(): void {
636646 ),
637647 'required ' => array ( 'required_field ' ),
638648 ),
639- 'execute_callback ' => function ( $ input ) {
649+ 'execute_callback ' => function ( $ input ) {
640650 return array ( 'status ' => 'success ' );
641651 },
642652 'permission_callback ' => '__return_true ' ,
643- 'meta ' => array ( 'type ' => 'tool ' ),
653+ 'meta ' => array ( 'type ' => 'tool ' ),
644654 )
645655 );
646656
@@ -665,18 +675,18 @@ public function test_ability_without_type_defaults_to_tool(): void {
665675 wp_register_ability (
666676 'test/no-type ' ,
667677 array (
668- 'label ' => 'No Type ' ,
669- 'description ' => 'Ability without type ' ,
670- 'execute_callback ' => function ( $ input ) {
678+ 'label ' => 'No Type ' ,
679+ 'description ' => 'Ability without type ' ,
680+ 'execute_callback ' => function ( $ input ) {
671681 return array ( 'executed ' => true );
672682 },
673683 'permission_callback ' => '__return_true ' ,
674- 'meta ' => array (), // No type specified
684+ 'meta ' => array (), // No type specified
675685 )
676686 );
677687
678688 // Should require POST (default tool behavior)
679- $ get_request = new WP_REST_Request ( 'GET ' , '/wp/v2/abilities/test/no-type/run ' );
689+ $ get_request = new WP_REST_Request ( 'GET ' , '/wp/v2/abilities/test/no-type/run ' );
680690 $ get_response = $ this ->server ->dispatch ( $ get_request );
681691 $ this ->assertEquals ( 405 , $ get_response ->get_status () );
682692
@@ -699,7 +709,7 @@ public function test_permission_check_passes_when_callback_not_set(): void {
699709 array (
700710 'label ' => 'No Permission Callback ' ,
701711 'description ' => 'Ability without permission callback ' ,
702- 'execute_callback ' => function ( $ input ) {
712+ 'execute_callback ' => function ( $ input ) {
703713 return array ( 'executed ' => true );
704714 },
705715 'meta ' => array ( 'type ' => 'tool ' ),
@@ -730,31 +740,31 @@ public function test_empty_input_handling(): void {
730740 wp_register_ability (
731741 'test/resource-empty ' ,
732742 array (
733- 'label ' => 'Resource Empty ' ,
734- 'description ' => 'Resource with empty input ' ,
735- 'execute_callback ' => function ( $ input ) {
743+ 'label ' => 'Resource Empty ' ,
744+ 'description ' => 'Resource with empty input ' ,
745+ 'execute_callback ' => function ( $ input ) {
736746 return array ( 'input_was_empty ' => empty ( $ input ) );
737747 },
738748 'permission_callback ' => '__return_true ' ,
739- 'meta ' => array ( 'type ' => 'resource ' ),
749+ 'meta ' => array ( 'type ' => 'resource ' ),
740750 )
741751 );
742752
743753 wp_register_ability (
744754 'test/tool-empty ' ,
745755 array (
746- 'label ' => 'Tool Empty ' ,
747- 'description ' => 'Tool with empty input ' ,
748- 'execute_callback ' => function ( $ input ) {
756+ 'label ' => 'Tool Empty ' ,
757+ 'description ' => 'Tool with empty input ' ,
758+ 'execute_callback ' => function ( $ input ) {
749759 return array ( 'input_was_empty ' => empty ( $ input ) );
750760 },
751761 'permission_callback ' => '__return_true ' ,
752- 'meta ' => array ( 'type ' => 'tool ' ),
762+ 'meta ' => array ( 'type ' => 'tool ' ),
753763 )
754764 );
755765
756766 // Test GET with no input parameter
757- $ get_request = new WP_REST_Request ( 'GET ' , '/wp/v2/abilities/test/resource-empty/run ' );
767+ $ get_request = new WP_REST_Request ( 'GET ' , '/wp/v2/abilities/test/resource-empty/run ' );
758768 $ get_response = $ this ->server ->dispatch ( $ get_request );
759769 $ this ->assertEquals ( 200 , $ get_response ->get_status () );
760770 $ this ->assertTrue ( $ get_response ->get_data ()['input_was_empty ' ] );
@@ -813,13 +823,13 @@ public function test_php_type_strings_in_input(): void {
813823 wp_register_ability (
814824 'test/echo ' ,
815825 array (
816- 'label ' => 'Echo ' ,
817- 'description ' => 'Echoes input ' ,
818- 'execute_callback ' => function ( $ input ) {
826+ 'label ' => 'Echo ' ,
827+ 'description ' => 'Echoes input ' ,
828+ 'execute_callback ' => function ( $ input ) {
819829 return array ( 'echo ' => $ input );
820830 },
821831 'permission_callback ' => '__return_true ' ,
822- 'meta ' => array ( 'type ' => 'tool ' ),
832+ 'meta ' => array ( 'type ' => 'tool ' ),
823833 )
824834 );
825835
@@ -854,13 +864,13 @@ public function test_mixed_encoding_in_input(): void {
854864 wp_register_ability (
855865 'test/echo-encoding ' ,
856866 array (
857- 'label ' => 'Echo Encoding ' ,
858- 'description ' => 'Echoes input with encoding ' ,
859- 'execute_callback ' => function ( $ input ) {
867+ 'label ' => 'Echo Encoding ' ,
868+ 'description ' => 'Echoes input with encoding ' ,
869+ 'execute_callback ' => function ( $ input ) {
860870 return array ( 'echo ' => $ input );
861871 },
862872 'permission_callback ' => '__return_true ' ,
863- 'meta ' => array ( 'type ' => 'tool ' ),
873+ 'meta ' => array ( 'type ' => 'tool ' ),
864874 )
865875 );
866876
@@ -916,15 +926,15 @@ public function test_invalid_http_methods( string $method ): void {
916926 array (
917927 'label ' => 'Method Test ' ,
918928 'description ' => 'Test ability for HTTP method validation ' ,
919- 'execute_callback ' => function () {
929+ 'execute_callback ' => function () {
920930 return array ( 'success ' => true );
921931 },
922932 'permission_callback ' => '__return_true ' , // No permission requirements
923933 'meta ' => array ( 'type ' => 'tool ' ),
924934 )
925935 );
926936
927- $ request = new WP_REST_Request ( $ method , '/wp/v2/abilities/test/method-test/run ' );
937+ $ request = new WP_REST_Request ( $ method , '/wp/v2/abilities/test/method-test/run ' );
928938 $ response = $ this ->server ->dispatch ( $ request );
929939
930940 // Tool abilities should only accept POST, so these should return 405
@@ -937,10 +947,9 @@ public function test_invalid_http_methods( string $method ): void {
937947 * Test OPTIONS method handling.
938948 */
939949 public function test_options_method_handling (): void {
940- $ request = new WP_REST_Request ( 'OPTIONS ' , '/wp/v2/abilities/test/calculator/run ' );
950+ $ request = new WP_REST_Request ( 'OPTIONS ' , '/wp/v2/abilities/test/calculator/run ' );
941951 $ response = $ this ->server ->dispatch ( $ request );
942952 // OPTIONS requests return 200 with allowed methods
943953 $ this ->assertEquals ( 200 , $ response ->get_status () );
944954 }
945-
946955}
0 commit comments