Fix tests currently failing against HPOS environment setup (#46242)

* Fix tests currently failing against HPOS environment setup

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

* fix lint warning for print_r usage

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Michael Pretty 2024-04-04 14:19:22 -04:00 committed by GitHub
parent d80086ef87
commit 6328ad01a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 5 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Fix tests that were failing against HPOS environment setup.

View File

@ -91,6 +91,8 @@ class WC_Tests_CRUD_Meta_Data extends WC_Unit_Test_Case {
$order->delete_meta_data( 'random_other' );
$order->delete_meta_data( 'random_other_pre_crud' );
$order->save();
// Track the number of meta items we originally have for future assertions.
$original_meta_count = count( $order->get_meta_data() );
// Now add one piece of meta
$order->add_meta_data( 'random', (string) rand( 0, 0xffffff ) );
@ -105,13 +107,13 @@ class WC_Tests_CRUD_Meta_Data extends WC_Unit_Test_Case {
// Get a new instance of the same order. It should have both 'random' and 'random_other' set on it
$new_order = wc_get_order( $this->order_id );
// The original $order should have 1 item of meta - random.
$this->assertCount( 1, $order->get_meta_data() );
// The original $order should have $original_meta_count + 1 item of meta - random.
$this->assertCount( $original_meta_count + 1, $order->get_meta_data() );
$this->assertTrue( in_array( 'random', wp_list_pluck( $order->get_meta_data(), 'key' ) ) );
$expected_count = OrderUtil::custom_orders_table_usage_is_enabled() ? 2 : 3;
$expected_new_meta = OrderUtil::custom_orders_table_usage_is_enabled() ? 2 : 3;
// The new $order should have 3 items (or 2 in case of HPOS since direct post updates are not read) of meta since it's freshly loaded.
$this->assertCount( $expected_count, $new_order->get_meta_data() );
$this->assertCount( $expected_new_meta + $original_meta_count, $new_order->get_meta_data() );
$this->assertTrue( in_array( 'random', wp_list_pluck( $new_order->get_meta_data(), 'key' ) ) );
$this->assertTrue( in_array( 'random_other', wp_list_pluck( $new_order->get_meta_data(), 'key' ) ) );
if ( ! OrderUtil::custom_orders_table_usage_is_enabled() ) {

View File

@ -222,6 +222,9 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
* @since 2.6
*/
public function test_wc_order_get_payment_tokens() {
if ( \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled() ) {
$this->markTestSkipped( 'Test only works against Post Meta' );
}
$order = WC_Helper_Order::create_order();
$this->assertEmpty( $order->get_payment_tokens() );

View File

@ -29,7 +29,7 @@ class WC_Tests_Payment_Tokens extends WC_Unit_Test_Case {
$this->assertEmpty( WC_Payment_Tokens::get_order_tokens( $order->get_id() ) );
$token = WC_Helper_Payment_Token::create_cc_token();
update_post_meta( $order->get_id(), '_payment_tokens', array( $token->get_id() ) );
$order->add_payment_token( $token );
$this->assertCount( 1, WC_Payment_Tokens::get_order_tokens( $order->get_id() ) );