public function UcAddressesCartCheckoutTestCase::testDoubleAddresses in Ubercart Addresses 7
Same name and namespace in other branches
- 6.2 tests/uc_addresses.checkout.test \UcAddressesCartCheckoutTestCase::testDoubleAddresses()
Test if double addresses are not saved when checking out.
File
- tests/
uc_addresses.checkout.test, line 398 - 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',
'address',
), array(), 'checkout_form', 'delivery_');
$billing_values = UcAddressesTestCase::getEditAddressValues(array(
'panes',
'billing',
'address',
), $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.
$query = db_select('uc_addresses');
$query
->addExpression('COUNT(aid)');
$query
->condition('uid', $this->customer->uid);
$result = $query
->execute();
$count = (int) $result
->fetchField();
$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
->assertRaw($messages['review_instructions']);
$this
->drupalPost(NULL, array(), t('Submit order'));
$query = db_select('uc_addresses');
$query
->addExpression('COUNT(aid)');
$query
->condition('uid', $this->customer->uid);
$result = $query
->execute();
$count = (int) $result
->fetchField();
$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',
'address',
), 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);
$query = db_select('uc_addresses');
$query
->addExpression('COUNT(aid)');
$query
->condition('uid', $this->customer->uid);
$result = $query
->execute();
$count = (int) $result
->fetchField();
$this
->assertTrue($count === 2, t('The customer has @number addresses. (Actual: @count)', array(
'@number' => 2,
'@count' => $count,
)));
}