From e9105bd37d8225002eee8770b221715a3047fe86 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 21 Dec 2017 19:00:55 +0000 Subject: [PATCH] Fix tests --- includes/class-wc-customer.php | 4 ++-- .../data-stores/class-wc-customer-data-store-session.php | 9 +++++---- tests/framework/helpers/class-wc-helper-customer.php | 5 +++-- tests/unit-tests/customer/crud.php | 3 +-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/includes/class-wc-customer.php b/includes/class-wc-customer.php index ae3e368cb3a..1209fe83f18 100644 --- a/includes/class-wc-customer.php +++ b/includes/class-wc-customer.php @@ -270,7 +270,7 @@ class WC_Customer extends WC_Legacy_Customer { * @param bool $is_vat_exempt */ public function set_is_vat_exempt( $is_vat_exempt ) { - $this->is_vat_exempt = (bool) $is_vat_exempt; + $this->is_vat_exempt = wc_string_to_bool( $is_vat_exempt ); } /** @@ -279,7 +279,7 @@ class WC_Customer extends WC_Legacy_Customer { * @param boolean $calculated */ public function set_calculated_shipping( $calculated = true ) { - $this->calculated_shipping = (bool) $calculated; + $this->calculated_shipping = wc_string_to_bool( $calculated ); } /** diff --git a/includes/data-stores/class-wc-customer-data-store-session.php b/includes/data-stores/class-wc-customer-data-store-session.php index 39a5f456a16..a5c62299186 100644 --- a/includes/data-stores/class-wc-customer-data-store-session.php +++ b/includes/data-stores/class-wc-customer-data-store-session.php @@ -77,9 +77,7 @@ class WC_Customer_Data_Store_Session extends WC_Data_Store_WP implements WC_Cust } $data[ $session_key ] = (string) $customer->{"get_$function_key"}( 'edit' ); } - if ( WC()->session->get( 'customer' ) !== $data ) { - WC()->session->set( 'customer', $data ); - } + WC()->session->set( 'customer', $data ); } /** @@ -97,8 +95,11 @@ class WC_Customer_Data_Store_Session extends WC_Data_Store_WP implements WC_Cust * * If the user object has been updated since the session was created (based on date_modified) we should not load the session - data should be reloaded. */ - if ( ! empty( $data ) && isset( $data['id'], $data['date_modified'] ) && $data['id'] === (string) $customer->get_id() && $data['date_modified'] === (string) $customer->get_date_modified( 'edit' ) ) { + if ( isset( $data['id'], $data['date_modified'] ) && $data['id'] === (string) $customer->get_id() && $data['date_modified'] === (string) $customer->get_date_modified( 'edit' ) ) { foreach ( $this->session_keys as $session_key ) { + if ( in_array( $session_key, array( 'id', 'date_modified' ), true ) ) { + continue; + } $function_key = $session_key; if ( 'billing_' === substr( $session_key, 0, 8 ) ) { $session_key = str_replace( 'billing_', '', $session_key ); diff --git a/tests/framework/helpers/class-wc-helper-customer.php b/tests/framework/helpers/class-wc-helper-customer.php index 3b7f3aac71e..503994b46e2 100644 --- a/tests/framework/helpers/class-wc-helper-customer.php +++ b/tests/framework/helpers/class-wc-helper-customer.php @@ -13,9 +13,9 @@ class WC_Helper_Customer { * @return WC_Customer */ public static function create_mock_customer() { - $customer_data = array( 'id' => 0, + 'date_modified' => null, 'country' => 'US', 'state' => 'PA', 'postcode' => '19123', @@ -35,6 +35,7 @@ class WC_Helper_Customer { WC_Helper_Customer::set_customer_details( $customer_data ); $customer = new WC_Customer( 0, true ); + return $customer; } @@ -105,7 +106,7 @@ class WC_Helper_Customer { * @param string $default_shipping_method Shipping Method slug */ public static function set_customer_details( $customer_details ) { - WC()->session->set( 'customer', $customer_details ); + WC()->session->set( 'customer', array_map( 'strval', $customer_details ) ); } /** diff --git a/tests/unit-tests/customer/crud.php b/tests/unit-tests/customer/crud.php index 476edded680..f121418b675 100644 --- a/tests/unit-tests/customer/crud.php +++ b/tests/unit-tests/customer/crud.php @@ -442,8 +442,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case { * @since 3.0.0 */ public function test_customer_sessions() { - $customer = WC_Helper_Customer::create_customer(); - $session = WC_Helper_Customer::create_mock_customer(); // set into session.... + $session = WC_Helper_Customer::create_mock_customer(); // set into session.... $this->assertEquals( '19123', $session->get_billing_postcode() ); $this->assertEquals( '123 South Street', $session->get_billing_address() );