public function UcAddressesCartCheckoutTestCase::testDoubleAddresses in Ubercart Addresses 6.2
Same name and namespace in other branches
- 7 tests/uc_addresses.checkout.test \UcAddressesCartCheckoutTestCase::testDoubleAddresses()
Test if double addresses are not saved when checking out.
File
- tests/
uc_addresses.checkout.test, line 287 - Test cases for checkout.
Class
- UcAddressesCartCheckoutTestCase
- Test cases for checkout.
Code
public function testDoubleAddresses() {
// Create an user with edit address privileges.
$this->customer = $this
->drupalCreateUser(array(
'add/edit own addresses',
'delete own addresses',
));
// Log in as customer.
$this
->drupalLogin($this->customer);
// Place item in cart.
$this
->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
// Continue to checkout.
$this
->drupalPost('cart', array(), 'Checkout');
// Fill in the same address in both the delivery and billing pane.
$edit = array();
$delivery_values = UcAddressesTestCase::getEditAddressValues(array(
'panes',
'delivery',
'delivery',
), array(), 'checkout_form', 'delivery_');
$billing_values = UcAddressesTestCase::getEditAddressValues(array(
'panes',
'billing',
'billing',
), $delivery_values['values'], 'checkout_form', 'billing_');
$edit += $delivery_values['form_values'];
$edit += $billing_values['form_values'];
// And checkout.
$this
->checkout($edit);
// Check that only one address is saved for the customer.
$result = db_query('SELECT COUNT(aid) FROM {uc_addresses} WHERE uid = %d', $this->customer->uid);
$count = (int) db_result($result);
$this
->assertTrue($count === 1, t('The customer has @number addresses. (Actual: @count)', array(
'@number' => 1,
'@count' => $count,
)));
// Checkout with the default addresses filled and verify that the customer still has only one address.
$edit = array();
$this
->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
$this
->drupalPost('cart', array(), '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'));
$result = db_query('SELECT COUNT(aid) FROM {uc_addresses} WHERE uid = %d', $this->customer->uid);
$count = (int) db_result($result);
$this
->assertTrue($count === 1, t('The customer has @number addresses. (Actual: @count)', array(
'@number' => 1,
'@count' => $count,
)));
// Checkout again, but now with a different billing address.
// The customer should have two addresses now.
$edit = array();
$billing_values = UcAddressesTestCase::getEditAddressValues(array(
'panes',
'billing',
'billing',
), array(), 'checkout_form', 'billing_');
$edit += $delivery_values['form_values'];
$edit += $billing_values['form_values'];
$this
->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
$this
->checkout($edit);
$result = db_query('SELECT COUNT(aid) FROM {uc_addresses} WHERE uid = %d', $this->customer->uid);
$count = (int) db_result($result);
$this
->assertTrue($count === 2, t('The customer has @number addresses. (Actual: @count)', array(
'@number' => 2,
'@count' => $count,
)));
}