protected function UcAddressesCartCheckoutTestCase::doDefaultAddressesTests in Ubercart Addresses 6.2
Same name and namespace in other branches
- 7 tests/uc_addresses.checkout.test \UcAddressesCartCheckoutTestCase::doDefaultAddressesTests()
Checkout with the default addresses.
Helper method for testDefaultAddresses().
Parameters
object $account: The user that's currently logged in.
See also
testDefaultAddresses()
checkCheckoutAddressFields()
1 call to UcAddressesCartCheckoutTestCase::doDefaultAddressesTests()
- UcAddressesCartCheckoutTestCase::testDefaultAddresses in tests/
uc_addresses.checkout.test - Test if the address fields are prefilled with the customer's default addresses.
File
- tests/
uc_addresses.checkout.test, line 182 - Test cases for checkout.
Class
- UcAddressesCartCheckoutTestCase
- Test cases for checkout.
Code
protected function doDefaultAddressesTests($account) {
// Load default addresses for this user.
$address_types = uc_addresses_address_types();
$addresses = array();
foreach ($address_types as $address_type) {
$address = UcAddressesAddressBook::get($account->uid)
->getDefaultAddress($address_type);
if ($address instanceof UcAddressesAddress) {
$addresses[$address_type] = $address;
}
else {
$addresses[$address_type] = UcAddressesAddressBook::newAddress();
}
}
// Create an empty address too.
$empty_address = UcAddressesAddressBook::newAddress();
// Initialize values for checkout form.
$edit = array();
// Initialize array for newly added addresses.
$new_addresses = array();
// Clear out the static variable in form_clean_id().
form_clean_id(NULL, TRUE);
// Place item in cart.
$this
->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
// Continue to checkout.
$this
->drupalPost('cart', array(), 'Checkout');
// Check if the address form is prefilled with the default addresses
// according to the settings.
foreach ($address_types as $address_type) {
$order_address_type = $address_type;
if ($address_type == 'shipping') {
$order_address_type = 'delivery';
}
if (variable_get('uc_addresses_default_' . $address_type . '_address', TRUE)) {
$this
->checkCheckoutAddressFields($order_address_type, $addresses[$address_type]);
}
else {
$this
->checkCheckoutAddressFields($order_address_type, $empty_address);
$values = UcAddressesTestCase::getEditAddressValues(array(
'panes',
$order_address_type,
$order_address_type,
), array(), 'checkout_form', $order_address_type . '_');
$edit += $values['form_values'];
$new_addresses[$order_address_type] = $values['values'];
}
}
// And checkout.
$this
->drupalPost(NULL, $edit, t('Review order'));
$messages = uc_cart_uc_message();
$this
->assertText($messages['review_instructions']);
$this
->drupalPost(NULL, array(), t('Submit order'));
// Check if any new addresses got saved.
foreach ($new_addresses as $address_type => $address_values) {
$message = '';
switch ($address_type) {
case 'delivery':
$message = t('The delivery address is correctly saved to the database.');
break;
case 'billing':
$message = t('The billing address is correctly saved to the database.');
break;
}
$this
->assertTrue(UcAddressesTestCase::checkAddressValuesInDatabase($address_values), $message);
}
}