public function UcAddressesApiTestCase::testAddressFormatWithoutDefaultCountry in Ubercart Addresses 7
Same name and namespace in other branches
- 6.2 tests/uc_addresses.api.test \UcAddressesApiTestCase::testAddressFormatWithoutDefaultCountry()
Tests if a proper address format is generated when there is no default country set.
File
- tests/
uc_addresses.api.test, line 275 - Test cases for the api component.
Class
- UcAddressesApiTestCase
- Test cases for the api component.
Code
public function testAddressFormatWithoutDefaultCountry() {
$this
->drupalLogin($this->adminUser);
// Ensure there is no store country set.
variable_del('uc_store_country');
// Remove the U.S. country from Ubercart.
// This will leave Canada as the only available country.
$country_id = 840;
db_delete('uc_countries')
->condition('country_id', $country_id)
->execute();
db_delete('uc_zones')
->condition('zone_country_id', $country_id)
->execute();
variable_del('uc_address_format_' . $country_id);
// Adjust the address format for Canada.
$canada_address_format = self::randomName();
$this
->verbose($canada_address_format);
variable_set('uc_addresses_address_format_124', $canada_address_format);
// Disable the country field.
$address_fields = variable_get('uc_address_fields', drupal_map_assoc(array(
'first_name',
'last_name',
'phone',
'company',
'street1',
'street2',
'city',
'zone',
'postal_code',
'country',
)));
unset($address_fields['country']);
variable_set('uc_address_fields', $address_fields);
// Create an address.
$aid = $this
->createAddress($this->adminUser);
$addressBook = UcAddressesAddressBook::get($this->adminUser->uid);
$addressBook
->reset();
$address = $addressBook
->getAddressById($aid);
if ($address instanceof UcAddressesAddress) {
// Ensure Canada is used for the address.
$this
->assertEqual($address
->getField('country'), '124', format_string('Canada is used as the default country. (ID = !country_id)', array(
'!country_id' => $address
->getField('country'),
)));
// Output the address for display.
$this
->viewAddress($this->adminUser, $address
->getId());
// Ensure Canada's address format is used.
$this
->assertText($canada_address_format, 'The address format for Canada was used for the address label.');
// Test also if the displayed address is not empty
// when a country is used that does not exists.
$address
->setField('country', 1234);
$address
->save();
$this
->viewAddress($this->adminUser, $address
->getId());
$this
->assertText($address
->getFieldValue('last_name'), 'Last name was found in the outputted address label.');
$this
->assertText($address
->getFieldValue('city'), 'City was found in the outputted address label.');
}
}