public function UcAddressesApiTestCase::testAddressNames in Ubercart Addresses 7
Same name and namespace in other branches
- 6.2 tests/uc_addresses.api.test \UcAddressesApiTestCase::testAddressNames()
Tests unique address names.
File
- tests/
uc_addresses.api.test, line 76 - Test cases for the api component.
Class
- UcAddressesApiTestCase
- Test cases for the api component.
Code
public function testAddressNames() {
$addressBook = $this
->UcAddressesGetAddressBook($this->adminUser->uid);
// Add a new address and give it a name.
$address1 = $addressBook
->addAddress();
$addressBook
->setAddressAsDefault($address1, 'billing');
$name = self::randomName(12);
$address1
->setName($name);
$address1
->save();
// Ensure the address has the name assigned.
$this
->assertEqual($address1
->getName(), $name, format_string('Address %aid got the name %name.', array(
'%aid' => $address1
->getId(),
'%name' => $name,
)));
// Reset the address book.
$addressBook
->reset();
// Add a new address and try to give it the same name as address1.
$address2 = $addressBook
->addAddress();
$address2
->setName($name);
// Ensure address2 has NOT the name assigned.
$this
->assertNotEqual($address2
->getName(), $name, format_string('Address %aid does not got the name %name.', array(
'%aid' => $address2
->getId(),
'%name' => $name,
)));
// Try to delete address1 (should not be possible, because address should be a default address).
$this
->assertFalse($addressBook
->deleteAddressByName($name), format_string('Address %name is not deleted.', array(
'%name' => $name,
)));
// Make address2 the default and try again.
$addressBook
->setAddressAsDefault($address2, 'billing');
$this
->assertTrue($addressBook
->deleteAddressByName($name), format_string('Address %name is deleted.', array(
'%name' => $name,
)));
}