/** * Test WC_Customer's session handling code. * @since 2.7.0 */ public function test_customer_sessions() { $customer = WC_Helper_Customer::create_customer(); $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()); $this->assertEquals('Philadelphia', $session->get_billing_city()); $session->set_billing_address('124 South Street'); $session->save_to_session(); $session = new WC_Customer(0, true); $session->load_session(); $this->assertEquals('124 South Street', $session->get_billing_address()); $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($session->get_id() > 0); $this->assertEquals('32191', $session->get_billing_postcode()); }
/** * Creates a customer in the tests DB. */ public static function create_customer($username = '******', $password = '******', $email = '*****@*****.**') { $customer = new WC_Customer(); $customer->set_billing_country('US'); $customer->set_first_name('Justin'); $customer->set_billing_state('PA'); $customer->set_billing_postcode('19123'); $customer->set_billing_city('Philadelphia'); $customer->set_billing_address('123 South Street'); $customer->set_billing_address_2('Apt 1'); $customer->set_shipping_country('US'); $customer->set_shipping_state('PA'); $customer->set_shipping_postcode('19123'); $customer->set_shipping_city('Philadelphia'); $customer->set_shipping_address('123 South Street'); $customer->set_shipping_address_2('Apt 1'); $customer->set_username($username); $customer->set_password($password); $customer->set_email($email); $customer->create(); return $customer; }