public function UcAddressesApiTestCase::testDefaultAddresses in Ubercart Addresses 6.2
Same name and namespace in other branches
- 7 tests/uc_addresses.api.test \UcAddressesApiTestCase::testDefaultAddresses()
Tests default addresses.
File
- tests/
uc_addresses.api.test, line 110 - Test cases for the api component.
Class
- UcAddressesApiTestCase
- Test cases for the api component.
Code
public function testDefaultAddresses() {
$addressBook = $this
->UcAddressesGetAddressBook($this->adminUser->uid);
// Create a new address and mark it as default billing.
$address1 = $addressBook
->addAddress();
$addressBook
->setAddressAsDefault($address1, 'billing');
$address1
->save();
// Ensure that the address is the default billing address.
$default_billing_aid = db_result(db_query("SELECT aid FROM {uc_addresses} WHERE default_billing = 1"));
$this
->assertEqual($address1
->getId(), $default_billing_aid, 'The address is the default billing address.');
// Reset the address book.
$addressBook
->reset();
// Try to delete address1. This should not be possible, because
// deleting default addresses is not allowed.
$this
->assertFalse($addressBook
->deleteAddressById($address1
->getId()), t('Address %aid is not deleted.', array(
'%aid' => $address1
->getId(),
)));
// Create a new address and delete the first one.
$address2 = $addressBook
->addAddress();
$addressBook
->setAddressAsDefault($address2, 'billing');
$this
->assertTrue($addressBook
->deleteAddressById($address1
->getId()), t('Address %aid is deleted.', array(
'%aid' => $address1
->getId(),
)));
// Ensure the database table is empty now ($address2 is not yet saved).
$number_of_addresses = db_result(db_query("SELECT COUNT(aid) AS number_of_addresses FROM {uc_addresses}"));
$this
->assertEqual($number_of_addresses, 0, 'There are no addresses in the uc_addresses table.');
// Now save $address2 and ensure that this address is the default
// billing address in the database.
$address2
->save();
$default_billing_aid = db_result(db_query("SELECT aid FROM {uc_addresses} WHERE default_billing = 1"));
$this
->assertEqual($address2
->getId(), $default_billing_aid, 'The address is the default billing address.');
// Create a third address and mark this as default billing as well.
$address3 = $addressBook
->addAddress();
$addressBook
->setAddressAsDefault($address3, 'billing');
$address3
->save();
// Ensure the user has only one default billing address.
$number_of_addresses = (int) db_result(db_query("SELECT COUNT(aid) AS number_of_addresses FROM {uc_addresses} WHERE default_billing = 1"));
$this
->assertEqual($number_of_addresses, 1, 'The database contains one default billing address.');
}