From 9ccb1e21244a2aceef5551dad30c9e11c54fdc35 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Thu, 20 Sep 2018 16:20:50 +0200 Subject: [PATCH] Added revenue stats tests. --- .../tests/api/reports-revenue-stats.php | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 plugins/woocommerce-admin/tests/api/reports-revenue-stats.php diff --git a/plugins/woocommerce-admin/tests/api/reports-revenue-stats.php b/plugins/woocommerce-admin/tests/api/reports-revenue-stats.php new file mode 100644 index 00000000000..6a72eb3f958 --- /dev/null +++ b/plugins/woocommerce-admin/tests/api/reports-revenue-stats.php @@ -0,0 +1,119 @@ +user = $this->factory->user->create( + array( + 'role' => 'administrator', + ) + ); + } + + /** + * Test route registration. + * + * @since 3.5.0 + */ + public function test_register_routes() { + $routes = $this->server->get_routes(); + + $this->assertArrayHasKey( $this->endpoint, $routes ); + } + + /** + * Test getting reports. + * + * @since 3.5.0 + */ + public function test_get_reports() { + wp_set_current_user( $this->user ); + + // @todo update after report interface is done. + $response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) ); + $data = $response->get_data(); + + $this->assertEquals( 200, $response->get_status() ); + $this->assertEquals( 2, count( $data ) ); // @todo update results after implement report interface. + //$this->assertEquals( array(), $reports ); // @todo update results after implement report interface. + } + + /** + * Test getting reports without valid permissions. + * + * @since 3.5.0 + */ + public function test_get_reports_without_permission() { + wp_set_current_user( 0 ); + $response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) ); + $this->assertEquals( 401, $response->get_status() ); + } + + /** + * Test reports schema. + * + * @since 3.5.0 + */ + public function test_reports_schema() { + wp_set_current_user( $this->user ); + + $request = new WP_REST_Request( 'OPTIONS', $this->endpoint ); + $response = $this->server->dispatch( $request ); + $data = $response->get_data(); + $properties = $data['schema']['properties']; + + $this->assertEquals( 2, count( $properties ) ); + $this->assertArrayHasKey( 'totals', $properties ); + $this->assertArrayHasKey( 'intervals', $properties ); + + $totals = $properties['totals']['properties']; + $this->assertEquals( 7, count( $totals ) ); + $this->assertArrayHasKey( 'gross_revenue', $totals ); + $this->assertArrayHasKey( 'net_revenue', $totals ); + $this->assertArrayHasKey( 'coupons', $totals ); + $this->assertArrayHasKey( 'shipping', $totals ); + $this->assertArrayHasKey( 'taxes', $totals ); + $this->assertArrayHasKey( 'refunds', $totals ); + $this->assertArrayHasKey( 'orders_count', $totals ); + + $intervals = $properties['intervals']['items']['properties']; + $this->assertEquals( 6, count( $intervals ) ); + $this->assertArrayHasKey( 'interval', $intervals ); + $this->assertArrayHasKey( 'date_start', $intervals ); + $this->assertArrayHasKey( 'date_start_gmt', $intervals ); + $this->assertArrayHasKey( 'date_end', $intervals ); + $this->assertArrayHasKey( 'date_end_gmt', $intervals ); + $this->assertArrayHasKey( 'subtotals', $intervals ); + + $subtotals = $properties['intervals']['items']['properties']['subtotals']['properties']; + $this->assertEquals( 7, count( $subtotals ) ); + $this->assertArrayHasKey( 'gross_revenue', $subtotals ); + $this->assertArrayHasKey( 'net_revenue', $subtotals ); + $this->assertArrayHasKey( 'coupons', $subtotals ); + $this->assertArrayHasKey( 'shipping', $subtotals ); + $this->assertArrayHasKey( 'taxes', $subtotals ); + $this->assertArrayHasKey( 'refunds', $subtotals ); + $this->assertArrayHasKey( 'orders_count', $subtotals ); + } +}