From bb0d2965ce6afd4efb4efa275af2a5c8de5ed76d Mon Sep 17 00:00:00 2001 From: John Hooks Date: Mon, 27 Mar 2023 03:41:11 -0700 Subject: [PATCH] test: add rest schema test --- .../rest-api/test-notification-controller.php | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/phpunit/tests/rest-api/test-notification-controller.php diff --git a/tests/phpunit/tests/rest-api/test-notification-controller.php b/tests/phpunit/tests/rest-api/test-notification-controller.php new file mode 100644 index 00000000..593df9af --- /dev/null +++ b/tests/phpunit/tests/rest-api/test-notification-controller.php @@ -0,0 +1,77 @@ +markTestSkipped( 'TODO Implement' ); + + } + public function test_context_param() { + $this->markTestSkipped( 'TODO Implement' ); + + } + public function test_get_items() { + $this->markTestSkipped( 'TODO Implement' ); + + } + public function test_get_item() { + $this->markTestSkipped( 'TODO Implement' ); + + } + public function test_create_item() { + $this->markTestSkipped( 'TODO Implement' ); + + } + public function test_update_item() { + $this->markTestSkipped( 'TODO Implement' ); + + } + public function test_delete_item() { + $this->assert( true ); + } + public function test_prepare_item() { + $this->markTestSkipped( 'TODO Implement' ); + } + + public function test_registered_query_params() { + $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/notifications' ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); + $keys = array_keys( $data['endpoints'][0]['args'] ); + sort( $keys ); + $this->assertSame( + array( + 'channel', + 'offset', + 'order', + 'orderby', + 'page', + 'per_page', + 'search', + 'status', + ), + $keys + ); + } + + public function test_get_item_schema() { + $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/notifications' ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); + $properties = $data['schema']['properties']; + // $this->assertCount( 14, $properties ); + $this->assertArrayHasKey( 'channel_id', $properties ); + $this->assertArrayHasKey( 'context', $properties ); + $this->assertArrayHasKey( 'created_at', $properties ); + $this->assertArrayHasKey( 'dismissed_at', $properties ); + $this->assertArrayHasKey( 'expires_at', $properties ); + $this->assertArrayHasKey( 'message', $properties ); + // $this->assertArrayHasKey( 'message_key', $properties ); + $this->assertArrayHasKey( 'meta', $properties ); + $this->assertArrayHasKey( 'severity', $properties ); + $this->assertArrayHasKey( 'status', $properties ); + $this->assertArrayHasKey( 'title', $properties ); + // $this->assertArrayHasKey( 'title_key', $properties ); + } +}