1f66726caedcda5a4dfd3a52fae39a3dc238db58
4 * Class CRM_Utils_AddressTest
7 class CRM_Utils_AddressTest
extends CiviUnitTestCase
{
9 public function setUp() {
13 public function testAddressFormat() {
14 $contact = $this->callAPISuccess('contact', 'create', array(
15 'first_name' => 'Micky',
16 'last_name' => 'mouse',
17 'contact_type' => 'Individual',
19 $address = $this->callAPISuccess('address', 'create', array(
20 'street_address' => '1 Happy Place',
22 'state_province' => 'Flordia',
23 'country' => 'United States',
24 'postal_code' => 33101,
25 'contact_id' => $contact['id'],
26 'location_type_id' => 5,
29 $addressDetails = $address['values'][$address['id']];
30 $countries = CRM_Core_PseudoConstant
::country();
31 $addressDetails['country'] = $countries[$addressDetails['country_id']];
32 $formatted_address = CRM_Utils_Address
::format($addressDetails, 'mailing_format', FALSE, TRUE);
33 $this->assertTrue((bool) strstr($formatted_address, 'UNITED STATES'));
37 * Test state/province field's state_province_name token on getFormattedBillingAddressFieldsFromParameters
38 * and test using alternate names for state_province field
40 public function testStateProvinceFormattedBillingAddress() {
42 'billing_street_address-99' => '123 Happy Place',
43 'billing_city-99' => 'Miami',
44 'billing_postal_code-99' => 33101,
45 // 1000 => Alabama (AL)
46 'state_province-99' => '1000',
47 'country-99' => 'United States',
50 // set address_format (we are only interested in state_province & state_province_name)
51 $addFormat = '{contact.state_province}';
52 Civi
::settings()->set('address_format', $addFormat);
53 $formatted_address = CRM_Utils_Address
::getFormattedBillingAddressFieldsFromParameters($params, '99');
54 $this->assertTrue((bool) $formatted_address == 'AL');
56 $addFormat = '{contact.state_province_name}';
57 Civi
::settings()->set('address_format', $addFormat);
58 $formatted_address = CRM_Utils_Address
::getFormattedBillingAddressFieldsFromParameters($params, '99');
59 $this->assertTrue((bool) $formatted_address == 'Alabama');
61 // test using alternate names for state/province field
62 unset($params['state_province-99']);
64 $params['billing_state_province-99'] = '1000';
65 $addFormat = '{contact.state_province_name}';
66 Civi
::settings()->set('address_format', $addFormat);
67 $formatted_address = CRM_Utils_Address
::getFormattedBillingAddressFieldsFromParameters($params, '99');
68 $this->assertTrue((bool) $formatted_address == 'Alabama');
70 unset($params['state_province-99']);
72 $params['billing_state_province_id-99'] = '1000';
73 $addFormat = '{contact.state_province_name}';
74 Civi
::settings()->set('address_format', $addFormat);
75 $formatted_address = CRM_Utils_Address
::getFormattedBillingAddressFieldsFromParameters($params, '99');
76 $this->assertTrue((bool) $formatted_address == 'Alabama');