Enable HPOS for all tests.

This commit is contained in:
Vedanshu Jain 2023-01-27 16:15:29 +05:30
parent dead6d7060
commit 3b503dc7a7
4 changed files with 27 additions and 9 deletions

View File

@ -89,6 +89,8 @@ class WC_Unit_Tests_Bootstrap {
// re-initialize dependency injection, this needs to be the last operation after everything else is in place.
$this->initialize_dependency_injection();
$this->initialize_hpos();
error_reporting(error_reporting() & ~E_DEPRECATED);
}
@ -140,6 +142,12 @@ class WC_Unit_Tests_Bootstrap {
CodeHacker::enable();
}
private function initialize_hpos() {
\Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::delete_order_custom_tables();
\Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order_custom_table_if_not_exist();
\Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::toggle_cot( true );
}
/**
* Re-initialize the dependency injection engine.
*

View File

@ -151,6 +151,23 @@ class OrderHelper {
}
}
/**
* Enables or disables the custom orders table across WP temporarily.
*
* @param boolean $enabled TRUE to enable COT or FALSE to disable.
* @return void
*/
public static function toggle_cot( bool $enabled ) {
$features_controller = wc_get_container()->get( Featurescontroller::class );
$features_controller->change_feature_enable( 'custom_order_tables', $enabled );
update_option( CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION, wc_bool_to_string( $enabled ) );
// Confirm things are really correct.
$wc_data_store = WC_Data_Store::load( 'order' );
assert( is_a( $wc_data_store->get_current_class_name(), OrdersTableDataStore::class, true ) === $enabled );
}
/**
* Helper method to create custom tables if not present.
*/

View File

@ -21,7 +21,7 @@ class WC_Admin_Tests_ProductForm_Field extends WC_Unit_Test_Case {
new Field(
'id',
'woocommerce',
array(),
array()
);
}
}

View File

@ -49,14 +49,7 @@ trait HPOSToggleTrait {
* @return void
*/
private function toggle_cot( bool $enabled ): void {
$features_controller = wc_get_container()->get( Featurescontroller::class );
$features_controller->change_feature_enable( 'custom_order_tables', $enabled );
update_option( CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION, wc_bool_to_string( $enabled ) );
// Confirm things are really correct.
$wc_data_store = WC_Data_Store::load( 'order' );
assert( is_a( $wc_data_store->get_current_class_name(), OrdersTableDataStore::class, true ) === $enabled );
OrderHelper::toggle_cot( $enabled );
}
/**