Using new internal status constants in tests (#52433)

* Introducing order status constants

* Replacing static calls

* Additional comment blocks

* Updating PHP docs

* Updating PHP docs

* Add changefile(s) from automation for the following project(s): woocommerce

* Fix lint issues

* Fix lint issues

* Fix lint issues

* Removing unnecessary order statuses group constants + more documentation

* Including the 'new' status (legacy)

* Merge branch 'dev/introducing-order-status-constants' of https://github.com/woocommerce/woocommerce into dev/introducing-order-status-constants

* Moving statuses to a new enum class

* Fix CS issues

* Fix lint issues

* Minor doc improvement

* Changing namespace to make it less granular

* Adding missing documentation for existing filters

* Update plugins/woocommerce/src/Enums/OrderStatus.php

Co-authored-by: Barry Hughes <3594411+barryhughes@users.noreply.github.com>

* Update plugins/woocommerce/includes/class-wc-order.php

Co-authored-by: Barry Hughes <3594411+barryhughes@users.noreply.github.com>

* Update plugins/woocommerce/src/Enums/OrderStatus.php

Co-authored-by: Barry Hughes <3594411+barryhughes@users.noreply.github.com>

* Making the order status class final

* Adding missing filter comments

* Moving conditional filter back to if statement

* Merge branch 'dev/introducing-order-status-constants' of https://github.com/woocommerce/woocommerce into dev/introducing-order-status-constants

* Adding 'since' annotation to fix lint errors

* Adding 'since' annotation to fix lint errors

* Introducing order legacy status constants

* Using the new legacy status constants in tests

* Removing unnecessary status

* Add changefile(s) from automation for the following project(s): woocommerce

* Add changefile(s) from automation for the following project(s): woocommerce

* Replacing missing status occurences

* Renaming legacy status class to internal status

* Updating class name according to base branch changes

* Fix lint issues

* Fix lint issues

* Address missing replacement

* Fix tests

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Barry Hughes <3594411+barryhughes@users.noreply.github.com>
Co-authored-by: Vladimir Reznichenko <kalessil@gmail.com>
This commit is contained in:
Wesley Rosa 2024-11-13 09:58:11 -03:00 committed by GitHub
parent f33e974d01
commit 62eae71618
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 66 additions and 39 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: dev
Uses the newly introduced legacy order status constants in unit tests.

View File

@ -5,6 +5,8 @@
* @package WooCommerce\Tests\Admin\Reports
*/
use Automattic\WooCommerce\Enums\OrderInternalStatus;
/**
* Tests for the WC_Admin_Report class.
*/
@ -146,7 +148,7 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
)
);
$this->assertEquals( 'wc-completed', $data->post_status );
$this->assertEquals( OrderInternalStatus::COMPLETED, $data->post_status );
}
/**

View File

@ -1,5 +1,7 @@
<?php
use Automattic\WooCommerce\Enums\OrderInternalStatus;
/**
* Class CustomerCRUD.
* @package WooCommerce\Tests\Customer
@ -265,7 +267,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
$order = WC_Helper_Order::create_order( $customer_id );
$customer = new WC_Customer( $customer_id );
$this->assertEquals( 0, $customer->get_total_spent() );
$order->update_status( 'wc-completed' );
$order->update_status( OrderInternalStatus::COMPLETED );
$customer = new WC_Customer( $customer_id );
$this->assertEquals( 50, $customer->get_total_spent() );
$order->delete();

View File

@ -6,6 +6,7 @@
*/
use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Enums\OrderInternalStatus;
/**
* Class Functions.
@ -25,13 +26,13 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
$order_statuses = apply_filters(
'wc_order_statuses',
array(
'wc-pending' => _x( 'Pending payment', 'Order status', 'woocommerce' ),
'wc-processing' => _x( 'Processing', 'Order status', 'woocommerce' ),
'wc-on-hold' => _x( 'On hold', 'Order status', 'woocommerce' ),
'wc-completed' => _x( 'Completed', 'Order status', 'woocommerce' ),
'wc-cancelled' => _x( 'Cancelled', 'Order status', 'woocommerce' ),
'wc-refunded' => _x( 'Refunded', 'Order status', 'woocommerce' ),
'wc-failed' => _x( 'Failed', 'Order status', 'woocommerce' ),
OrderInternalStatus::PENDING => _x( 'Pending payment', 'Order status', 'woocommerce' ),
OrderInternalStatus::PROCESSING => _x( 'Processing', 'Order status', 'woocommerce' ),
OrderInternalStatus::ON_HOLD => _x( 'On hold', 'Order status', 'woocommerce' ),
OrderInternalStatus::COMPLETED => _x( 'Completed', 'Order status', 'woocommerce' ),
OrderInternalStatus::CANCELLED => _x( 'Cancelled', 'Order status', 'woocommerce' ),
OrderInternalStatus::REFUNDED => _x( 'Refunded', 'Order status', 'woocommerce' ),
OrderInternalStatus::FAILED => _x( 'Failed', 'Order status', 'woocommerce' ),
)
);
@ -44,7 +45,7 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
* @since 2.3.0
*/
public function test_wc_is_order_status() {
$this->assertTrue( wc_is_order_status( 'wc-pending' ) );
$this->assertTrue( wc_is_order_status( OrderInternalStatus::PENDING ) );
$this->assertFalse( wc_is_order_status( 'wc-another-status' ) );
}
@ -55,7 +56,7 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
*/
public function test_wc_get_order_status_name() {
$this->assertEquals( _x( 'Pending payment', 'Order status', 'woocommerce' ), wc_get_order_status_name( 'wc-pending' ) );
$this->assertEquals( _x( 'Pending payment', 'Order status', 'woocommerce' ), wc_get_order_status_name( OrderInternalStatus::PENDING ) );
$this->assertEquals( _x( 'Pending payment', 'Order status', 'woocommerce' ), wc_get_order_status_name( 'pending' ) );
}
@ -82,18 +83,18 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
$this->assertEquals( 0, wc_orders_count( 'unkown-status' ) );
// Invalid order type should return 0.
$this->assertEquals( 0, wc_orders_count( 'wc-pending', 'invalid-order-type' ) );
$this->assertEquals( 0, wc_orders_count( OrderInternalStatus::PENDING, 'invalid-order-type' ) );
wp_cache_flush();
// Fake some datastores and order types for testing.
$test_counts = array(
'order' => array(
array( 'wc-on-hold', 2 ),
array( OrderInternalStatus::ON_HOLD, 2 ),
array( 'trash', 1 ),
),
'order-fake-type' => array(
array( 'wc-on-hold', 3 ),
array( OrderInternalStatus::ON_HOLD, 3 ),
array( 'trash', 0 ),
),
);

View File

@ -6,6 +6,7 @@
* @since 3.5.0
*/
use Automattic\WooCommerce\Enums\OrderInternalStatus;
use Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
use Automattic\WooCommerce\RestApi\UnitTests\HPOSToggleTrait;
@ -81,9 +82,9 @@ class WC_Tests_API_Reports_Orders_Totals extends WC_REST_Unit_Test_Case {
// Create some orders with HPOS enabled.
$order_counts = array(
'wc-pending' => 3,
'wc-processing' => 2,
'wc-on-hold' => 1,
OrderInternalStatus::PENDING => 3,
OrderInternalStatus::PROCESSING => 2,
OrderInternalStatus::ON_HOLD => 1,
);
foreach ( $order_counts as $status => $count ) {
for ( $i = 0; $i < $count; $i++ ) {

View File

@ -5,6 +5,7 @@
* @package WooCommerce\Tests\WC_Tracker.
*/
use Automattic\WooCommerce\Enums\OrderInternalStatus;
use Automattic\WooCommerce\Internal\Features\FeaturesController;
use Automattic\WooCommerce\Utilities\PluginUtil;
@ -166,7 +167,7 @@ class WC_Tracker_Test extends \WC_Unit_Test_Case {
*/
public function test_get_tracking_data_orders() {
$dummy_product = WC_Helper_Product::create_simple_product();
$status_entries = array( 'wc-processing', 'wc-completed', 'wc-refunded', 'wc-pending' );
$status_entries = array( OrderInternalStatus::PROCESSING, OrderInternalStatus::COMPLETED, OrderInternalStatus::REFUNDED, OrderInternalStatus::PENDING );
$created_via_entries = array( 'api', 'checkout', 'admin' );
$payment_method_entries = array( 'paypal', 'stripe', 'cod' );

View File

@ -1,6 +1,7 @@
<?php
use Automattic\WooCommerce\Enums\OrderStatus;
use Automattic\WooCommerce\Enums\OrderInternalStatus;
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
use Automattic\WooCommerce\Internal\Utilities\Users;
@ -64,7 +65,7 @@ class WC_Customer_Data_Store_CPT_Test extends WC_Unit_Test_Case {
* @return string[]
*/
public function get_pending_only_as_order_statuses() {
return array( 'wc-pending' => 'pending' );
return array( OrderInternalStatus::PENDING => OrderStatus::PENDING );
}
/**
@ -103,10 +104,13 @@ class WC_Customer_Data_Store_CPT_Test extends WC_Unit_Test_Case {
$sql =
'INSERT INTO ' . OrdersTableDataStore::get_orders_table_name() . "
( id, customer_id, status, type )
( id, customer_id, status, type )
VALUES
( 1, %d, 'wc-completed', 'shop_order' ), ( %d, %d, 'wc-completed', 'shop_order' ), ( 3, %d, 'wc-invalid-status', 'shop_order' ),
( 4, %d, 'wc-completed', 'shop_order' ), ( 5, %d, 'wc-completed', 'shop_order' )";
( 1, %d, '" . OrderInternalStatus::COMPLETED . "', 'shop_order' ),
( %d, %d, '" . OrderInternalStatus::COMPLETED . "', 'shop_order' ),
( 3, %d, 'wc-invalid-status', 'shop_order' ),
( 4, %d, '" . OrderInternalStatus::COMPLETED . "', 'shop_order' ),
( 5, %d, '" . OrderInternalStatus::COMPLETED . "', 'shop_order' )";
$customer_1_id = $customer_1->get_id();
$customer_2_id = $customer_2->get_id();
@ -191,10 +195,14 @@ class WC_Customer_Data_Store_CPT_Test extends WC_Unit_Test_Case {
$sql =
'INSERT INTO ' . OrdersTableDataStore::get_orders_table_name() . "
( id, customer_id, status )
( id, customer_id, status )
VALUES
( 1, %d, 'wc-completed' ), ( 2, %d, 'wc-completed' ), ( 3, %d, 'wc-completed' ), ( 4, %d, 'wc-invalid-status' ),
( 5, %d, 'wc-completed' ), ( 6, %d, 'wc-completed' )";
( 1, %d, '" . OrderInternalStatus::COMPLETED . "' ),
( 2, %d, '" . OrderInternalStatus::COMPLETED . "' ),
( 3, %d, '" . OrderInternalStatus::COMPLETED . "' ),
( 4, %d, 'wc-invalid-status' ),
( 5, %d, '" . OrderInternalStatus::COMPLETED . "' ),
( 6, %d, '" . OrderInternalStatus::COMPLETED . "' )";
$customer_1_id = $customer_1->get_id();
$customer_2_id = $customer_2->get_id();
@ -246,10 +254,14 @@ class WC_Customer_Data_Store_CPT_Test extends WC_Unit_Test_Case {
$sql =
'INSERT INTO ' . OrdersTableDataStore::get_orders_table_name() . "
( id, customer_id, status, total_amount )
( id, customer_id, status, total_amount )
VALUES
( 1, %d, 'wc-completed', 10 ), ( 2, %d, 'wc-completed', 20 ), ( 3, %d, 'wc-completed', 30 ), ( 4, %d, 'wc-invalid-status', 40 ),
( 5, %d, 'wc-completed', 200 ), ( 6, %d, 'wc-completed', 300 )";
( 1, %d, '" . OrderInternalStatus::COMPLETED . "', 10 ),
( 2, %d, '" . OrderInternalStatus::COMPLETED . "', 20 ),
( 3, %d, '" . OrderInternalStatus::COMPLETED . "', 30 ),
( 4, %d, 'wc-invalid-status', 40 ),
( 5, %d, '" . OrderInternalStatus::COMPLETED . "', 200 ),
( 6, %d, '" . OrderInternalStatus::COMPLETED . "', 300 )";
$customer_1_id = $customer_1->get_id();
$customer_2_id = $customer_2->get_id();

View File

@ -5,6 +5,8 @@
* @package WooCommerce\Tests\Functions\Stock
*/
use Automattic\WooCommerce\Enums\OrderInternalStatus;
/**
* Class WC_Stock_Functions_Tests.
*/
@ -24,7 +26,7 @@ class WC_Stock_Functions_Tests extends \WC_Unit_Test_Case {
*/
public $order_stock_restore_statuses = array(
'wc-cancelled',
'wc-pending',
OrderInternalStatus::PENDING,
);
/**

View File

@ -4,6 +4,7 @@ declare( strict_types = 1 );
namespace Automattic\WooCommerce\Tests\Internal\DataStores\Orders;
use Automattic\WooCommerce\Enums\OrderStatus;
use Automattic\WooCommerce\Enums\OrderInternalStatus;
use Automattic\WooCommerce\Internal\BatchProcessing\BatchProcessingController;
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
use Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer;
@ -202,7 +203,7 @@ class DataSynchronizerTests extends \HposTestCase {
$order->set_status( OrderStatus::PENDING );
$order->save();
$this->assertEquals(
'wc-pending',
OrderInternalStatus::PENDING,
$wpdb->get_var( "SELECT status FROM $orders_table WHERE id = $order_id" ), //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
'When the order status is updated, the change should be observed by the DataSynhronizer and a matching update will take place in the COT table.'
);

View File

@ -5,6 +5,7 @@ namespace Automattic\WooCommerce\Tests\Internal\DataStores\Orders;
use Automattic\WooCommerce\Database\Migrations\CustomOrderTable\PostsToOrdersMigrationController;
use Automattic\WooCommerce\Enums\OrderStatus;
use Automattic\WooCommerce\Enums\OrderInternalStatus;
use Automattic\WooCommerce\Internal\CostOfGoodsSold\CogsAwareUnitTestSuiteTrait;
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
use Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer;
@ -585,7 +586,7 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$this->sut->untrash_order( $order );
$this->assertEquals( OrderStatus::ON_HOLD, $order->get_status() );
$this->assertEquals( 'wc-on-hold', get_post_status( $order_id ) );
$this->assertEquals( OrderInternalStatus::ON_HOLD, get_post_status( $order_id ) );
$this->assertEmpty( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$this->sut->get_meta_table_name()} WHERE order_id = %d AND meta_key LIKE '_wp_trash_meta_%'", $order_id ) ) );
$this->assertEmpty( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key LIKE '_wp_trash_meta_%'", $order_id ) ) );
@ -1198,9 +1199,9 @@ class OrdersTableDataStoreTests extends \HposTestCase {
*/
public function test_get_order_count(): void {
$number_of_orders_by_status = array(
'wc-completed' => 4,
'wc-processing' => 2,
'wc-pending' => 4,
OrderInternalStatus::COMPLETED => 4,
OrderInternalStatus::PROCESSING => 2,
OrderInternalStatus::PENDING => 4,
);
foreach ( $number_of_orders_by_status as $order_status => $number_of_orders ) {
@ -1234,8 +1235,8 @@ class OrdersTableDataStoreTests extends \HposTestCase {
// Create a few orders.
$orders_by_status = array(
'wc-completed' => 3,
'wc-pending' => 2,
OrderInternalStatus::COMPLETED => 3,
OrderInternalStatus::PENDING => 2,
);
$unpaid_ids = array();
foreach ( $orders_by_status as $order_status => $order_count ) {
@ -1253,7 +1254,7 @@ class OrdersTableDataStoreTests extends \HposTestCase {
}
// Confirm not all orders are unpaid.
$this->assertEquals( $orders_by_status['wc-completed'], $this->sut->get_order_count( 'wc-completed' ) );
$this->assertEquals( $orders_by_status[ OrderInternalStatus::COMPLETED ], $this->sut->get_order_count( OrderInternalStatus::COMPLETED ) );
// Find unpaid orders.
$this->assertEqualsCanonicalizing( $unpaid_ids, $this->sut->get_unpaid_orders( $now_ist ) );
@ -1644,7 +1645,7 @@ class OrdersTableDataStoreTests extends \HposTestCase {
foreach ( $orders_test_data as $i => $order_data ) {
$order = new \WC_Order();
$this->switch_data_store( $order, $this->sut );
$order->set_status( 'wc-completed' );
$order->set_status( OrderInternalStatus::COMPLETED );
$order->set_shipping_city( 'The Universe' );
$order->set_billing_first_name( $order_data[0] );
$order->set_billing_last_name( $order_data[1] );
@ -2477,7 +2478,7 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$db_row = $db_row_callback->call( $this->sut, $order, false );
$this->assertEquals( 'wc-completed', $db_row['data']['status'] );
$this->assertEquals( OrderInternalStatus::COMPLETED, $db_row['data']['status'] );
}
/**