public function CommerceCustomerUITest::testCommerceCustomerUIAddProfileViaOrderUI in Commerce Core 7
Add a customer profile using the Order interface.
File
- modules/
customer/ tests/ commerce_customer_ui.test, line 439 - Commerce customer profile tests.
Class
- CommerceCustomerUITest
- Functional tests for the commerce customer UI module.
Code
public function testCommerceCustomerUIAddProfileViaOrderUI() {
// Create an order for store customer.
$order = $this
->createDummyOrder($this->store_customer->uid, array(), 'pending');
// Login with store admin.
$this
->drupalLogin($this->store_admin);
// Access the order and fill customer profile information.
$this
->drupalGet('admin/commerce/orders/' . $order->order_id . '/edit');
$address_info = $this
->generateAddressInformation();
// Add a billing information profile to the order.
$this
->drupalPostAJAX(NULL, array(), array(
'op' => t('Add billing information'),
));
$billing_country = $this
->xpath("//select[starts-with(@name, 'commerce_customer_billing')]");
$this
->drupalPostAJAX(NULL, array(
(string) $billing_country[0]['name'] => variable_get('site_default_country', 'US'),
), (string) $billing_country[0]['name']);
// Fill the profile information and Save.
$info = array(
'commerce_customer_billing[und][profiles][0][commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
'commerce_customer_billing[und][profiles][0][commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
'commerce_customer_billing[und][profiles][0][commerce_customer_address][und][0][locality]' => $address_info['locality'],
'commerce_customer_billing[und][profiles][0][commerce_customer_address][und][0][administrative_area]' => $address_info['administrative_area'],
'commerce_customer_billing[und][profiles][0][commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
);
$this
->drupalPost(NULL, $info, t('Save order'));
$this
->assertText(t('Order saved'), t('\'Order saved\' message is displayed'));
// Check the customer profile in the listing.
$this
->drupalGet('admin/commerce/customer-profiles');
$this
->assertTrue($address_info['name_line'], t('\'Name line\' text is present with the correct value: !value', array(
'!value' => $address_info['name_line'],
)));
// Check the customer profile at database level.
$conditions = array();
foreach ($address_info as $id => $element) {
$conditions[] = array(
'field' => 'commerce_customer_address',
'column' => $id,
'value' => $element,
);
}
$profiles = $this
->loadCustomerProfile($conditions);
$profile = commerce_customer_profile_load(reset($profiles)->profile_id);
$profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile);
$this
->assertFalse(empty($profile), t('Profile has been created in database'));
foreach ($address_info as $name => $info) {
$this
->assertEqual($profile_wrapper->commerce_customer_address->{$name}
->value(), $info, t('!name is present in the profile with value !value', array(
'!name' => $name,
'!value' => $info,
)));
}
}