Skip to content

Commit 4145fce

Browse files
committed
REST API: Expand ability schema keyword tests
1 parent 7d7328f commit 4145fce

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,11 +842,15 @@ public function test_internal_schema_keywords_stripped_from_response(): void {
842842
'category' => 'general',
843843
'input_schema' => array(
844844
'type' => 'object',
845+
'required' => array( 'content' ),
845846
'properties' => array(
846847
'content' => array(
847848
'type' => 'string',
848849
'description' => 'The content value.',
850+
'example' => 'example content',
849851
'examples' => array( 'example content' ),
852+
'context' => array( 'view', 'edit', 'embed' ),
853+
'readonly' => true,
850854
'sanitize_callback' => 'sanitize_text_field',
851855
'validate_callback' => 'is_string',
852856
'arg_options' => array( 'sanitize_callback' => 'wp_kses_post' ),
@@ -855,7 +859,13 @@ public function test_internal_schema_keywords_stripped_from_response(): void {
855859
),
856860
'output_schema' => array(
857861
'type' => 'string',
862+
'example' => 'example output',
863+
'examples' => array( 'example output' ),
864+
'context' => array( 'view', 'edit', 'embed' ),
865+
'readonly' => true,
858866
'sanitize_callback' => 'sanitize_text_field',
867+
'validate_callback' => 'is_string',
868+
'arg_options' => array( 'sanitize_callback' => 'wp_kses_post' ),
859869
),
860870
'execute_callback' => static function ( $input ) {
861871
return $input['content'];
@@ -876,19 +886,29 @@ public function test_internal_schema_keywords_stripped_from_response(): void {
876886
$this->assertArrayHasKey( 'content', $data['input_schema']['properties'] );
877887
$this->assertArrayHasKey( 'output_schema', $data );
878888

879-
// Verify internal keywords are stripped from input_schema properties.
889+
// Verify unsupported schema keywords are stripped from input_schema properties.
880890
$content_schema = $data['input_schema']['properties']['content'];
881891
$this->assertArrayNotHasKey( 'sanitize_callback', $content_schema );
882892
$this->assertArrayNotHasKey( 'validate_callback', $content_schema );
883893
$this->assertArrayNotHasKey( 'arg_options', $content_schema );
894+
$this->assertArrayNotHasKey( 'example', $content_schema );
884895
$this->assertArrayNotHasKey( 'examples', $content_schema );
896+
$this->assertArrayNotHasKey( 'context', $content_schema );
897+
$this->assertArrayNotHasKey( 'readonly', $content_schema );
885898

886899
// Verify valid JSON Schema keywords are preserved.
887900
$this->assertSame( 'string', $content_schema['type'] );
888901
$this->assertSame( 'The content value.', $content_schema['description'] );
902+
$this->assertSame( array( 'content' ), $data['input_schema']['required'] );
889903

890904
// Verify internal keywords are stripped from output_schema.
891905
$this->assertArrayNotHasKey( 'sanitize_callback', $data['output_schema'] );
906+
$this->assertArrayNotHasKey( 'validate_callback', $data['output_schema'] );
907+
$this->assertArrayNotHasKey( 'arg_options', $data['output_schema'] );
908+
$this->assertArrayNotHasKey( 'example', $data['output_schema'] );
909+
$this->assertArrayNotHasKey( 'examples', $data['output_schema'] );
910+
$this->assertArrayNotHasKey( 'context', $data['output_schema'] );
911+
$this->assertArrayNotHasKey( 'readonly', $data['output_schema'] );
892912
$this->assertSame( 'string', $data['output_schema']['type'] );
893913
}
894914

0 commit comments

Comments
 (0)