@@ -526,16 +526,18 @@ public function test_invalid_json_in_post_body(): void {
526526 */
527527 public function test_get_request_with_nested_input_array (): void {
528528 $ 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 ' ,
529+ $ request ->set_query_params (
530+ array (
531+ 'input ' => array (
532+ 'level1 ' => array (
533+ 'level2 ' => array (
534+ 'value ' => 'nested ' ,
535+ ),
534536 ),
537+ 'array ' => array ( 1 , 2 , 3 ),
535538 ),
536- 'array ' => array ( 1 , 2 , 3 ),
537- ),
538- ) );
539+ )
540+ );
539541
540542 $ response = $ this ->server ->dispatch ( $ request );
541543 $ this ->assertEquals ( 200 , $ response ->get_status () );
@@ -550,9 +552,11 @@ public function test_get_request_with_nested_input_array(): void {
550552 */
551553 public function test_get_request_with_non_array_input (): void {
552554 $ 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- ) );
555+ $ request ->set_query_params (
556+ array (
557+ 'input ' => 'not-an-array ' , // String instead of array
558+ )
559+ );
556560
557561 $ response = $ this ->server ->dispatch ( $ request );
558562 // When input is not an array, WordPress returns 400 Bad Request
@@ -565,9 +569,13 @@ public function test_get_request_with_non_array_input(): void {
565569 public function test_post_request_with_non_array_input (): void {
566570 $ request = new WP_REST_Request ( 'POST ' , '/wp/v2/abilities/test/calculator/run ' );
567571 $ request ->set_header ( 'Content-Type ' , 'application/json ' );
568- $ request ->set_body ( wp_json_encode ( array (
569- 'input ' => 'string-value ' , // String instead of array
570- ) ) );
572+ $ request ->set_body (
573+ wp_json_encode (
574+ array (
575+ 'input ' => 'string-value ' , // String instead of array
576+ )
577+ )
578+ );
571579
572580 $ response = $ this ->server ->dispatch ( $ request );
573581 // When input is not an array, WordPress returns 400 Bad Request
@@ -583,9 +591,9 @@ public function test_output_validation_failure_returns_error(): void {
583591 wp_register_ability (
584592 'test/strict-output ' ,
585593 array (
586- 'label ' => 'Strict Output ' ,
587- 'description ' => 'Ability with strict output schema ' ,
588- 'output_schema ' => array (
594+ 'label ' => 'Strict Output ' ,
595+ 'description ' => 'Ability with strict output schema ' ,
596+ 'output_schema ' => array (
589597 'type ' => 'object ' ,
590598 'properties ' => array (
591599 'status ' => array (
@@ -595,12 +603,12 @@ public function test_output_validation_failure_returns_error(): void {
595603 ),
596604 'required ' => array ( 'status ' ),
597605 ),
598- 'execute_callback ' => function ( $ input ) {
606+ 'execute_callback ' => function ( $ input ) {
599607 // Return invalid output that doesn't match schema
600608 return array ( 'wrong_field ' => 'value ' );
601609 },
602610 'permission_callback ' => '__return_true ' ,
603- 'meta ' => array ( 'type ' => 'tool ' ),
611+ 'meta ' => array ( 'type ' => 'tool ' ),
604612 )
605613 );
606614
@@ -625,9 +633,9 @@ public function test_input_validation_failure_returns_error(): void {
625633 wp_register_ability (
626634 'test/strict-input ' ,
627635 array (
628- 'label ' => 'Strict Input ' ,
629- 'description ' => 'Ability with strict input schema ' ,
630- 'input_schema ' => array (
636+ 'label ' => 'Strict Input ' ,
637+ 'description ' => 'Ability with strict input schema ' ,
638+ 'input_schema ' => array (
631639 'type ' => 'object ' ,
632640 'properties ' => array (
633641 'required_field ' => array (
@@ -636,11 +644,11 @@ public function test_input_validation_failure_returns_error(): void {
636644 ),
637645 'required ' => array ( 'required_field ' ),
638646 ),
639- 'execute_callback ' => function ( $ input ) {
647+ 'execute_callback ' => function ( $ input ) {
640648 return array ( 'status ' => 'success ' );
641649 },
642650 'permission_callback ' => '__return_true ' ,
643- 'meta ' => array ( 'type ' => 'tool ' ),
651+ 'meta ' => array ( 'type ' => 'tool ' ),
644652 )
645653 );
646654
@@ -665,18 +673,18 @@ public function test_ability_without_type_defaults_to_tool(): void {
665673 wp_register_ability (
666674 'test/no-type ' ,
667675 array (
668- 'label ' => 'No Type ' ,
669- 'description ' => 'Ability without type ' ,
670- 'execute_callback ' => function ( $ input ) {
676+ 'label ' => 'No Type ' ,
677+ 'description ' => 'Ability without type ' ,
678+ 'execute_callback ' => function ( $ input ) {
671679 return array ( 'executed ' => true );
672680 },
673681 'permission_callback ' => '__return_true ' ,
674- 'meta ' => array (), // No type specified
682+ 'meta ' => array (), // No type specified
675683 )
676684 );
677685
678686 // Should require POST (default tool behavior)
679- $ get_request = new WP_REST_Request ( 'GET ' , '/wp/v2/abilities/test/no-type/run ' );
687+ $ get_request = new WP_REST_Request ( 'GET ' , '/wp/v2/abilities/test/no-type/run ' );
680688 $ get_response = $ this ->server ->dispatch ( $ get_request );
681689 $ this ->assertEquals ( 405 , $ get_response ->get_status () );
682690
@@ -699,7 +707,7 @@ public function test_permission_check_passes_when_callback_not_set(): void {
699707 array (
700708 'label ' => 'No Permission Callback ' ,
701709 'description ' => 'Ability without permission callback ' ,
702- 'execute_callback ' => function ( $ input ) {
710+ 'execute_callback ' => function ( $ input ) {
703711 return array ( 'executed ' => true );
704712 },
705713 'meta ' => array ( 'type ' => 'tool ' ),
@@ -730,31 +738,31 @@ public function test_empty_input_handling(): void {
730738 wp_register_ability (
731739 'test/resource-empty ' ,
732740 array (
733- 'label ' => 'Resource Empty ' ,
734- 'description ' => 'Resource with empty input ' ,
735- 'execute_callback ' => function ( $ input ) {
741+ 'label ' => 'Resource Empty ' ,
742+ 'description ' => 'Resource with empty input ' ,
743+ 'execute_callback ' => function ( $ input ) {
736744 return array ( 'input_was_empty ' => empty ( $ input ) );
737745 },
738746 'permission_callback ' => '__return_true ' ,
739- 'meta ' => array ( 'type ' => 'resource ' ),
747+ 'meta ' => array ( 'type ' => 'resource ' ),
740748 )
741749 );
742750
743751 wp_register_ability (
744752 'test/tool-empty ' ,
745753 array (
746- 'label ' => 'Tool Empty ' ,
747- 'description ' => 'Tool with empty input ' ,
748- 'execute_callback ' => function ( $ input ) {
754+ 'label ' => 'Tool Empty ' ,
755+ 'description ' => 'Tool with empty input ' ,
756+ 'execute_callback ' => function ( $ input ) {
749757 return array ( 'input_was_empty ' => empty ( $ input ) );
750758 },
751759 'permission_callback ' => '__return_true ' ,
752- 'meta ' => array ( 'type ' => 'tool ' ),
760+ 'meta ' => array ( 'type ' => 'tool ' ),
753761 )
754762 );
755763
756764 // Test GET with no input parameter
757- $ get_request = new WP_REST_Request ( 'GET ' , '/wp/v2/abilities/test/resource-empty/run ' );
765+ $ get_request = new WP_REST_Request ( 'GET ' , '/wp/v2/abilities/test/resource-empty/run ' );
758766 $ get_response = $ this ->server ->dispatch ( $ get_request );
759767 $ this ->assertEquals ( 200 , $ get_response ->get_status () );
760768 $ this ->assertTrue ( $ get_response ->get_data ()['input_was_empty ' ] );
@@ -813,13 +821,13 @@ public function test_php_type_strings_in_input(): void {
813821 wp_register_ability (
814822 'test/echo ' ,
815823 array (
816- 'label ' => 'Echo ' ,
817- 'description ' => 'Echoes input ' ,
818- 'execute_callback ' => function ( $ input ) {
824+ 'label ' => 'Echo ' ,
825+ 'description ' => 'Echoes input ' ,
826+ 'execute_callback ' => function ( $ input ) {
819827 return array ( 'echo ' => $ input );
820828 },
821829 'permission_callback ' => '__return_true ' ,
822- 'meta ' => array ( 'type ' => 'tool ' ),
830+ 'meta ' => array ( 'type ' => 'tool ' ),
823831 )
824832 );
825833
@@ -854,13 +862,13 @@ public function test_mixed_encoding_in_input(): void {
854862 wp_register_ability (
855863 'test/echo-encoding ' ,
856864 array (
857- 'label ' => 'Echo Encoding ' ,
858- 'description ' => 'Echoes input with encoding ' ,
859- 'execute_callback ' => function ( $ input ) {
865+ 'label ' => 'Echo Encoding ' ,
866+ 'description ' => 'Echoes input with encoding ' ,
867+ 'execute_callback ' => function ( $ input ) {
860868 return array ( 'echo ' => $ input );
861869 },
862870 'permission_callback ' => '__return_true ' ,
863- 'meta ' => array ( 'type ' => 'tool ' ),
871+ 'meta ' => array ( 'type ' => 'tool ' ),
864872 )
865873 );
866874
@@ -916,15 +924,15 @@ public function test_invalid_http_methods( string $method ): void {
916924 array (
917925 'label ' => 'Method Test ' ,
918926 'description ' => 'Test ability for HTTP method validation ' ,
919- 'execute_callback ' => function () {
927+ 'execute_callback ' => function () {
920928 return array ( 'success ' => true );
921929 },
922930 'permission_callback ' => '__return_true ' , // No permission requirements
923931 'meta ' => array ( 'type ' => 'tool ' ),
924932 )
925933 );
926934
927- $ request = new WP_REST_Request ( $ method , '/wp/v2/abilities/test/method-test/run ' );
935+ $ request = new WP_REST_Request ( $ method , '/wp/v2/abilities/test/method-test/run ' );
928936 $ response = $ this ->server ->dispatch ( $ request );
929937
930938 // Tool abilities should only accept POST, so these should return 405
@@ -937,10 +945,9 @@ public function test_invalid_http_methods( string $method ): void {
937945 * Test OPTIONS method handling.
938946 */
939947 public function test_options_method_handling (): void {
940- $ request = new WP_REST_Request ( 'OPTIONS ' , '/wp/v2/abilities/test/calculator/run ' );
948+ $ request = new WP_REST_Request ( 'OPTIONS ' , '/wp/v2/abilities/test/calculator/run ' );
941949 $ response = $ this ->server ->dispatch ( $ request );
942950 // OPTIONS requests return 200 with allowed methods
943951 $ this ->assertEquals ( 200 , $ response ->get_status () );
944952 }
945-
946953}
0 commit comments