public function CommerceCustomerUITest::testCommerceCustomerUIAddProfileViaCheckout in Commerce Core 7
Create a customer profile in the process of order creation.
File
- modules/
customer/ tests/ commerce_customer_ui.test, line 380 - Commerce customer profile tests.
Class
- CommerceCustomerUITest
- Functional tests for the commerce customer UI module.
Code
public function testCommerceCustomerUIAddProfileViaCheckout() {
// The rule that sends a mail after checkout completion should be disabled
// as it returns an error caused by how mail messages are stored.
$rules_config = rules_config_load('commerce_checkout_order_email');
$rules_config->active = FALSE;
$rules_config
->save();
// Create an order.
$order = $this
->createDummyOrder($this->store_customer->uid);
// Login with customer.
$this
->drupalLogin($this->store_customer);
// Access checkout.
$this
->drupalGet($this
->getCommerceUrl('checkout'));
// Generate random information, as city, postal code, etc.
$address_info = $this
->generateAddressInformation();
// Fill in the billing address information
$billing_pane = $this
->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
$this
->drupalPostAJAX(NULL, array(
(string) $billing_pane[0]['name'] => 'US',
), (string) $billing_pane[0]['name']);
// Check if the country has been selected correctly, this uses XPath as the
// ajax call replaces the element and the id may change
$this
->assertFieldByXPath("//select[starts-with(@id, 'edit-customer-profile-billing-commerce-customer-address')]//option[@selected='selected']", 'US', t('Country selected'));
// Fill in the required information for billing pane, with a random State.
$info = array(
'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
);
$this
->drupalPost(NULL, $info, t('Continue to next step'));
// Finish checkout process
$this
->drupalPost(NULL, array(), t('Continue to next step'));
// Login with store admin.
$this
->drupalLogin($this->store_admin);
// Check the customer profile at database level.
$orders = commerce_order_load_multiple(array(
$order->order_id,
), array(), TRUE);
$order = reset($orders);
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$profile = $order_wrapper->commerce_customer_billing
->value();
$profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile);
$address = $profile_wrapper->commerce_customer_address
->value();
$this
->assertTrue(array_intersect($address_info, $address) == $address_info, t('The address info for the checkout is stored in the customer profile'));
// Check the customer profile in the listing.
$this
->drupalGet('admin/commerce/customer-profiles');
$this
->assertTrue($address['name_line'], t('\'Name line\' text is present with the correct value: !value', array(
'!value' => $address['name_line'],
)));
}