Rework test to rely on the REST server handling route defaults.
This commit is contained in:
parent
d6d3161bff
commit
7e87732dfb
|
@ -12,7 +12,7 @@
|
||||||
* @package WooCommerce\Tests\API
|
* @package WooCommerce\Tests\API
|
||||||
* @since 3.6.4
|
* @since 3.6.4
|
||||||
*/
|
*/
|
||||||
class WC_Tests_API_Report_Controllers extends WP_UnitTestCase {
|
class WC_Tests_API_Report_Controllers extends WC_REST_Unit_Test_Case {
|
||||||
/**
|
/**
|
||||||
* Setup test admin notes data. Called before every test.
|
* Setup test admin notes data. Called before every test.
|
||||||
*
|
*
|
||||||
|
@ -35,66 +35,50 @@ class WC_Tests_API_Report_Controllers extends WP_UnitTestCase {
|
||||||
*/
|
*/
|
||||||
public function test_default_params() {
|
public function test_default_params() {
|
||||||
// These controllers intentionally missing:
|
// These controllers intentionally missing:
|
||||||
|
// - `WC_Admin_REST_Admin_Note_Action_Controller`
|
||||||
// - `WC_Admin_REST_Setting_Options_Controller`
|
// - `WC_Admin_REST_Setting_Options_Controller`
|
||||||
// - `WC_Admin_REST_Data_Download_Ips_Controller`
|
// - `WC_Admin_REST_Data_Download_Ips_Controller`
|
||||||
// because they don't have defaults for required params.
|
// - `WC_Admin_REST_Product_Variations_Controller`
|
||||||
$controller_classes = array(
|
// - `WC_Admin_REST_Reports_Import_Controller`
|
||||||
'WC_Admin_REST_Admin_Notes_Controller',
|
// because they don't have defaults for required params or a get_items() method.
|
||||||
'WC_Admin_REST_Admin_Note_Action_Controller',
|
$endpoints = array(
|
||||||
'WC_Admin_REST_Coupons_Controller',
|
'/wc/v4/admin/notes',
|
||||||
'WC_Admin_REST_Customers_Controller',
|
'/wc/v4/coupons',
|
||||||
'WC_Admin_REST_Data_Controller',
|
'/wc/v4/customers',
|
||||||
'WC_Admin_REST_Data_Countries_Controller',
|
'/wc/v4/data',
|
||||||
'WC_Admin_REST_Leaderboards_Controller',
|
'/wc/v4/data/countries',
|
||||||
'WC_Admin_REST_Orders_Controller',
|
'/wc/v4/leaderboards',
|
||||||
'WC_Admin_REST_Products_Controller',
|
'/wc/v4/orders',
|
||||||
'WC_Admin_REST_Product_Categories_Controller',
|
'/wc/v4/products',
|
||||||
'WC_Admin_REST_Product_Variations_Controller',
|
'/wc/v4/products/categories',
|
||||||
'WC_Admin_REST_Product_Reviews_Controller',
|
'/wc/v4/reports',
|
||||||
'WC_Admin_REST_Product_Variations_Controller',
|
'/wc/v4/reports/products',
|
||||||
'WC_Admin_REST_Reports_Controller',
|
'/wc/v4/reports/variations',
|
||||||
'WC_Admin_REST_Reports_Import_Controller',
|
'/wc/v4/reports/products/stats',
|
||||||
'WC_Admin_REST_Reports_Products_Controller',
|
'/wc/v4/reports/revenue/stats',
|
||||||
'WC_Admin_REST_Reports_Variations_Controller',
|
'/wc/v4/reports/orders',
|
||||||
'WC_Admin_REST_Reports_Products_Stats_Controller',
|
'/wc/v4/reports/orders/stats',
|
||||||
'WC_Admin_REST_Reports_Revenue_Stats_Controller',
|
'/wc/v4/reports/categories',
|
||||||
'WC_Admin_REST_Reports_Orders_Controller',
|
'/wc/v4/reports/taxes',
|
||||||
'WC_Admin_REST_Reports_Orders_Stats_Controller',
|
'/wc/v4/reports/taxes/stats',
|
||||||
'WC_Admin_REST_Reports_Categories_Controller',
|
'/wc/v4/reports/coupons',
|
||||||
'WC_Admin_REST_Reports_Taxes_Controller',
|
'/wc/v4/reports/coupons/stats',
|
||||||
'WC_Admin_REST_Reports_Taxes_Stats_Controller',
|
'/wc/v4/reports/stock',
|
||||||
'WC_Admin_REST_Reports_Coupons_Controller',
|
'/wc/v4/reports/stock/stats',
|
||||||
'WC_Admin_REST_Reports_Coupons_Stats_Controller',
|
'/wc/v4/reports/downloads',
|
||||||
'WC_Admin_REST_Reports_Stock_Controller',
|
'/wc/v4/reports/downloads/stats',
|
||||||
'WC_Admin_REST_Reports_Stock_Stats_Controller',
|
'/wc/v4/reports/customers',
|
||||||
'WC_Admin_REST_Reports_Downloads_Controller',
|
'/wc/v4/reports/customers/stats',
|
||||||
'WC_Admin_REST_Reports_Downloads_Stats_Controller',
|
'/wc/v4/taxes',
|
||||||
'WC_Admin_REST_Reports_Customers_Controller',
|
'/wc/v4/reports/performance-indicators',
|
||||||
'WC_Admin_REST_Reports_Customers_Stats_Controller',
|
'/wc-admin/v1/onboarding/levels',
|
||||||
'WC_Admin_REST_Taxes_Controller',
|
'/wc-admin/v1/onboarding/profile',
|
||||||
'WC_Admin_REST_Onboarding_Levels_Controller',
|
'/wc-admin/v1/onboarding/plugins',
|
||||||
'WC_Admin_REST_Onboarding_Profile_Controller',
|
|
||||||
'WC_Admin_REST_Onboarding_Plugins_Controller',
|
|
||||||
'WC_Admin_REST_Reports_Performance_Indicators_Controller',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Force REST controllers to load.
|
foreach ( $endpoints as $endpoint ) {
|
||||||
do_action( 'rest_api_init' );
|
$request = new WP_REST_Request( 'GET', $endpoint );
|
||||||
|
$response = $this->server->dispatch( $request );
|
||||||
foreach ( $controller_classes as $controller_class ) {
|
|
||||||
$controller = new $controller_class();
|
|
||||||
$params = $controller->get_collection_params();
|
|
||||||
$defaults = array();
|
|
||||||
|
|
||||||
foreach ( $params as $arg => $options ) {
|
|
||||||
if ( isset( $options['default'] ) ) {
|
|
||||||
$defaults[ $arg ] = $options['default'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$request = new WP_REST_Request();
|
|
||||||
$request->set_default_params( $defaults );
|
|
||||||
$response = $controller->get_items( $request );
|
|
||||||
|
|
||||||
// Surface any errors for easier debugging.
|
// Surface any errors for easier debugging.
|
||||||
if ( is_wp_error( $response ) ) {
|
if ( is_wp_error( $response ) ) {
|
||||||
|
|
Loading…
Reference in New Issue