You are here

public function CommerceCustomerUITest::testCommerceCustomerUIEditCustomerProfile in Commerce Core 7

Edit a previously existing customer profile.

File

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

Class

CommerceCustomerUITest
Functional tests for the commerce customer UI module.

Code

public function testCommerceCustomerUIEditCustomerProfile() {

  // Create a new customer profile.
  $profile = $this
    ->createDummyCustomerProfile('billing', $this->store_customer->uid);

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

  // Edit the customer profile.
  $this
    ->drupalGet('admin/commerce/customer-profiles/' . $profile->profile_id . '/edit');
  $address = $profile->commerce_customer_address[LANGUAGE_NONE][0];

  // Check the integrity of the edit form.
  $this
    ->pass(t('Test the integrity of the edit customer profile form:'));
  $this
    ->assertFieldById('edit-commerce-customer-address-und-0-country', $address['country'], t('Country field exists and it has the default country selected'));
  $this
    ->assertFieldById('edit-commerce-customer-address-und-0-name-line', $address['name_line'], t('Field !field exists in the customer profile form and has the correct value !value', array(
    '!field' => 'Name line',
    '!value' => $address['name_line'],
  )));

  // Also check for the buttons and cancel link.
  $this
    ->assertFieldById('edit-submit', t('Save profile'), t('\'Save profile\' button is present'));
  $this
    ->assertRaw(l(t('Cancel'), 'admin/commerce/customer-profiles'), t('Cancel link is present'));

  // Change some fields and save.
  $edit = array(
    'commerce_customer_address[und][0][name_line]' => 'Example Name line',
    'commerce_customer_address[und][0][locality]' => 'Example Locality',
    'name' => '',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save profile'));

  // Assert fields after saving the profile.
  $this
    ->pass(t('Assert the field values after saving the profile form:'));
  $this
    ->assertTrue($this->url == url('admin/commerce/customer-profiles/' . $profile->profile_id . '/edit', array(
    'absolute' => TRUE,
  )), t('Landing page after save the profile is the profile edit 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', $edit['commerce_customer_address[und][0][name_line]'], t('Field !field exists in the customer profile form and has the correct value !value', array(
    '!field' => 'Name line',
    '!value' => $edit['commerce_customer_address[und][0][name_line]'],
  )));
  $this
    ->assertFieldById('edit-commerce-customer-address-und-0-locality', $edit['commerce_customer_address[und][0][locality]'], t('Field !field exists in the customer profile form and has the correct value !value', array(
    '!field' => 'Locality',
    '!value' => $edit['commerce_customer_address[und][0][locality]'],
  )));
  $this
    ->assertFieldByName('name', NULL, t('Name field is present and empty'));

  // Check at database level.
  $profiles = commerce_customer_profile_load_multiple(array(
    $profile->profile_id,
  ), array(), TRUE);
  $profile = reset($profiles);
  $this
    ->assertTrue($profile->commerce_customer_address[LANGUAGE_NONE][0]['name_line'] == $edit['commerce_customer_address[und][0][name_line]'], t('\'Name line\' field has been correctly modified in the customer profile'));
  $this
    ->assertTrue($profile->commerce_customer_address[LANGUAGE_NONE][0]['locality'] == $edit['commerce_customer_address[und][0][locality]'], t('\'Locality\' field has been correctly modified in the customer profile'));
  $this
    ->assertTrue($profile->uid == 0, t('Profile owner is now anonymous user'));
}