You are here

public function UcAddressesCartCheckoutTestCase::testDefaultAddresses in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 tests/uc_addresses.checkout.test \UcAddressesCartCheckoutTestCase::testDefaultAddresses()

Test if the address fields are prefilled with the customer's default addresses.

See also

doDefaultAddressesTests()

checkCheckoutAddressFields()

File

tests/uc_addresses.checkout.test, line 245
Test cases for checkout.

Class

UcAddressesCartCheckoutTestCase
Test cases for checkout.

Code

public function testDefaultAddresses() {

  // Create an user with edit address privileges.
  $this->customer = $this
    ->drupalCreateUser(array(
    'add/edit own addresses',
    'delete own addresses',
  ));

  // Create a default shipping and a default billing address for this user.
  $addressBook = UcAddressesAddressBook::get($this->customer->uid);
  $address_types = uc_addresses_address_types();
  foreach ($address_types as $address_type) {
    $address = $addressBook
      ->addAddress();
    $values = UcAddressesTestCase::getEditAddressValues(array(), array(), 'address_form');
    $address
      ->setMultipleFields($values['values']);
    $address
      ->setAsDefault($address_type);
    $address
      ->save();
  }

  // Log in as customer.
  $this
    ->drupalLogin($this->customer);

  // Check if address fields are prefilled with values from the default addresses.
  $this
    ->doDefaultAddressesTests();

  // Now, turn off the option to prefill the billing address and check again.
  variable_set('uc_addresses_default_shipping_address', TRUE);
  variable_set('uc_addresses_default_billing_address', FALSE);
  $this
    ->doDefaultAddressesTests();

  // Reverse, don't fill in a default for the delivery address, but do
  // so for the billing address.
  variable_set('uc_addresses_default_shipping_address', FALSE);
  variable_set('uc_addresses_default_billing_address', TRUE);
  $this
    ->doDefaultAddressesTests();

  // Now turn off both and check again.
  variable_set('uc_addresses_default_shipping_address', FALSE);
  variable_set('uc_addresses_default_billing_address', FALSE);
  $this
    ->doDefaultAddressesTests();
}