2019-06-21 22:21:47 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* REST Controller Tests
|
|
|
|
*
|
2020-08-11 19:18:47 +00:00
|
|
|
* @package WooCommerce\Admin\Tests\API
|
2019-06-21 22:21:47 +00:00
|
|
|
* @since 3.6.4
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* REST Controller Tests Class
|
|
|
|
*
|
2020-08-11 19:18:47 +00:00
|
|
|
* @package WooCommerce\Admin\Tests\API
|
2019-06-21 22:21:47 +00:00
|
|
|
* @since 3.6.4
|
|
|
|
*/
|
2019-06-27 17:38:54 +00:00
|
|
|
class WC_Tests_API_Report_Controllers extends WC_REST_Unit_Test_Case {
|
2019-06-24 16:42:08 +00:00
|
|
|
/**
|
|
|
|
* Setup test admin notes data. Called before every test.
|
|
|
|
*
|
|
|
|
* @since 3.5.0
|
|
|
|
*/
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->user = $this->factory->user->create(
|
|
|
|
array(
|
|
|
|
'role' => 'administrator',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_set_current_user( $this->user );
|
|
|
|
}
|
|
|
|
|
2019-06-21 22:21:47 +00:00
|
|
|
/**
|
|
|
|
* Ensure that every REST controller works with their defaults.
|
|
|
|
*/
|
|
|
|
public function test_default_params() {
|
2019-06-24 18:16:58 +00:00
|
|
|
// These controllers intentionally missing:
|
2019-06-27 17:38:54 +00:00
|
|
|
// - `WC_Admin_REST_Admin_Note_Action_Controller`
|
2019-06-24 18:16:58 +00:00
|
|
|
// - `WC_Admin_REST_Setting_Options_Controller`
|
|
|
|
// - `WC_Admin_REST_Data_Download_Ips_Controller`
|
2019-06-27 17:38:54 +00:00
|
|
|
// - `WC_Admin_REST_Product_Variations_Controller`
|
|
|
|
// - `WC_Admin_REST_Reports_Import_Controller`
|
|
|
|
// because they don't have defaults for required params or a get_items() method.
|
|
|
|
$endpoints = array(
|
2019-11-12 18:15:55 +00:00
|
|
|
'/wc-analytics/admin/notes',
|
|
|
|
'/wc-analytics/coupons',
|
|
|
|
'/wc-analytics/customers',
|
|
|
|
'/wc-analytics/data',
|
|
|
|
'/wc-analytics/data/countries',
|
|
|
|
'/wc-analytics/leaderboards',
|
|
|
|
'/wc-analytics/orders',
|
|
|
|
'/wc-analytics/products',
|
|
|
|
'/wc-analytics/products/categories',
|
|
|
|
'/wc-analytics/reports',
|
|
|
|
'/wc-analytics/reports/products',
|
|
|
|
'/wc-analytics/reports/variations',
|
|
|
|
'/wc-analytics/reports/products/stats',
|
|
|
|
'/wc-analytics/reports/revenue/stats',
|
|
|
|
'/wc-analytics/reports/orders',
|
|
|
|
'/wc-analytics/reports/orders/stats',
|
|
|
|
'/wc-analytics/reports/categories',
|
|
|
|
'/wc-analytics/reports/taxes',
|
|
|
|
'/wc-analytics/reports/taxes/stats',
|
|
|
|
'/wc-analytics/reports/coupons',
|
|
|
|
'/wc-analytics/reports/coupons/stats',
|
|
|
|
'/wc-analytics/reports/stock',
|
|
|
|
'/wc-analytics/reports/stock/stats',
|
|
|
|
'/wc-analytics/reports/downloads',
|
|
|
|
'/wc-analytics/reports/downloads/stats',
|
|
|
|
'/wc-analytics/reports/customers',
|
|
|
|
'/wc-analytics/reports/customers/stats',
|
|
|
|
'/wc-analytics/taxes',
|
|
|
|
'/wc-analytics/reports/performance-indicators',
|
2019-06-21 22:21:47 +00:00
|
|
|
);
|
|
|
|
|
2019-06-27 17:38:54 +00:00
|
|
|
foreach ( $endpoints as $endpoint ) {
|
|
|
|
$request = new WP_REST_Request( 'GET', $endpoint );
|
|
|
|
$response = $this->server->dispatch( $request );
|
2019-06-24 16:42:08 +00:00
|
|
|
|
|
|
|
// Surface any errors for easier debugging.
|
|
|
|
if ( is_wp_error( $response ) ) {
|
|
|
|
$this->fail( $response->get_error_message() );
|
|
|
|
}
|
2019-06-21 22:21:47 +00:00
|
|
|
|
2019-06-24 16:42:08 +00:00
|
|
|
$this->assertTrue( is_array( $response->get_data() ) );
|
2019-06-21 22:21:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|