You are here

public function CommerceCustomerUITest::testCommerceCustomerUIAddCustomerProfileSaveAndAddAnother in Commerce Core 7

Save and add another customer profile.

File

modules/customer/tests/commerce_customer_ui.test, line 172
Commerce customer profile tests.

Class

CommerceCustomerUITest
Functional tests for the commerce customer UI module.

Code

public function testCommerceCustomerUIAddCustomerProfileSaveAndAddAnother() {

  // Login with store admin.
  $this
    ->drupalLogin($this->store_admin);

  // Check the access to the profile add page.
  $this
    ->drupalGet('admin/commerce/customer-profiles/add');

  // Fill the profile information and click on Save and add another.
  $billing_country = $this
    ->xpath("//select[starts-with(@name, 'commerce_customer_address')]");
  $this
    ->drupalPostAJAX(NULL, array(
    (string) $billing_country[0]['name'] => variable_get('site_default_country', 'US'),
  ), (string) $billing_country[0]['name']);

  // Generate random information, as city, postal code, etc.
  $address_info = $this
    ->generateAddressInformation();

  // Fill the profile information and Save.
  $info = array(
    'commerce_customer_address[und][0][name_line]' => $address_info['name_line'],
    'commerce_customer_address[und][0][thoroughfare]' => $address_info['thoroughfare'],
    'commerce_customer_address[und][0][locality]' => $address_info['locality'],
    'commerce_customer_address[und][0][administrative_area]' => $address_info['administrative_area'],
    'commerce_customer_address[und][0][postal_code]' => $address_info['postal_code'],
  );
  $this
    ->drupalPost(NULL, $info, t('Save and add another'));

  // Check the landing url and if the profile got created.
  $this
    ->assertTrue($this->url == url('admin/commerce/customer-profiles/add/billing', array(
    'absolute' => TRUE,
  )), t('Landing page after save and add another for profiles is the profile creation page'));
  $this
    ->assertText(t('Profile saved'), t('\'Profile saved\' message is displayed after saving a customer profile'));
  $this
    ->assertFieldById('edit-commerce-customer-address-und-0-name-line', '', t('\'Name line\' field is present and empty'));
  $conditions = array();
  foreach ($address_info as $id => $element) {
    $conditions[] = array(
      'field' => 'commerce_customer_address',
      'column' => $id,
      'value' => $element,
    );
  }
  $profile = $this
    ->loadCustomerProfile($conditions);
  $this
    ->assertFalse(empty($profile), t('Profile has been created in database'));
}