From 83dca89d0c99a48b2c2f1f24fc417482cf33b1ad Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 15 Aug 2016 16:53:48 +0100 Subject: [PATCH] Correct customer escaping and tests --- includes/abstracts/abstract-wc-data.php | 4 ++-- includes/class-wc-customer.php | 9 +++------ tests/unit-tests/customer/crud.php | 8 +++----- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/includes/abstracts/abstract-wc-data.php b/includes/abstracts/abstract-wc-data.php index beed5f3ef5f..e7409a3b0a5 100644 --- a/includes/abstracts/abstract-wc-data.php +++ b/includes/abstracts/abstract-wc-data.php @@ -254,7 +254,7 @@ abstract class WC_Data { SELECT " . $db_info['meta_id_field'] . ", meta_key, meta_value FROM " . $db_info['table'] . " WHERE " . $db_info['object_id_field'] . " = %d ORDER BY " . $db_info['meta_id_field'] . " - AND meta_key NOT LIKE 'wp_%' + AND meta_key NOT LIKE 'wp\_%%' ", $this->get_id() ) ); if ( $raw_meta_data ) { @@ -287,7 +287,7 @@ abstract class WC_Data { SELECT " . $db_info['meta_id_field'] . " FROM " . $db_info['table'] . " WHERE " . $db_info['object_id_field'] . " = %d", $this->get_id() ) . " AND meta_key NOT IN ('" . implode( "','", array_map( 'esc_sql', $this->get_internal_meta_keys() ) ) . "') - AND meta_key NOT LIKE 'wp_%'; + AND meta_key NOT LIKE 'wp\_%%'; " ) ); $set_meta_ids = array(); diff --git a/includes/class-wc-customer.php b/includes/class-wc-customer.php index 0baa51c7477..6ffb677f738 100644 --- a/includes/class-wc-customer.php +++ b/includes/class-wc-customer.php @@ -130,7 +130,7 @@ class WC_Customer extends WC_Legacy_Customer { * @since 2.7.0 */ public function save_session_if_changed() { - if ( $this->_is_session && $this->_changed ) { + if ( $this->_changed ) { $this->save_to_session(); } } @@ -968,8 +968,8 @@ class WC_Customer extends WC_Legacy_Customer { */ public function create() { $customer_id = wc_create_new_customer( $this->get_email(), $this->get_username(), $this->_data['password'] ); - unset( $this->_data['password'] ); - if ( $customer_id ) { + + if ( ! is_wp_error( $customer_id ) ) { $this->_data['id'] = $customer_id; update_user_meta( $this->get_id(), 'billing_first_name', $this->get_billing_first_name() ); update_user_meta( $this->get_id(), 'billing_last_name', $this->get_billing_last_name() ); @@ -1163,9 +1163,6 @@ class WC_Customer extends WC_Legacy_Customer { * @since 2.7.0 */ public function save_to_session() { - if ( ! $this->_is_session ) { - return; - } $data = array(); foreach ( $this->_session_keys as $session_key ) { $function_key = $session_key; diff --git a/tests/unit-tests/customer/crud.php b/tests/unit-tests/customer/crud.php index d710d760306..5e981a528d7 100644 --- a/tests/unit-tests/customer/crud.php +++ b/tests/unit-tests/customer/crud.php @@ -406,8 +406,6 @@ class CustomerCRUD extends \WC_Unit_Test_Case { $customer = \WC_Helper_Customer::create_customer(); $session = \WC_Helper_Customer::create_mock_customer(); // set into session.... - $this->assertNotEmpty( $session->get_id() ); - $this->assertFalse( is_numeric( $session->get_id() ) ); $this->assertEquals( '19123', $session->get_billing_postcode() ); $this->assertEquals( '123 South Street', $session->get_billing_address() ); $this->assertEquals( 'Philadelphia', $session->get_billing_city() ); @@ -415,17 +413,17 @@ class CustomerCRUD extends \WC_Unit_Test_Case { $session->set_billing_address( '124 South Street' ); $session->save_to_session(); - $session = new \WC_Customer(); + $session = new \WC_Customer( 0, true ); $session->load_session(); $this->assertEquals( '124 South Street', $session->get_billing_address() ); - $session = new \WC_Customer(); + $session = new \WC_Customer( 0, true ); $session->load_session(); $session->set_billing_postcode( '32191' ); $session->save(); // should still be session ID, not a created row, since we are working with guests/sessions - $this->assertFalse( is_numeric( $session->get_id() ) ); + $this->assertFalse( $session->get_id() > 0 ); $this->assertEquals( '32191' , $session->get_billing_postcode() ); }