Correct customer escaping and tests

This commit is contained in:
Mike Jolley 2016-08-15 16:53:48 +01:00
parent 14b40ea340
commit 83dca89d0c
3 changed files with 8 additions and 13 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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() );
}