Skip to content

Commit

Permalink
code/dev/69: Add Tests For Formatted Billing Address
Browse files Browse the repository at this point in the history
  • Loading branch information
vinuvarshith committed May 1, 2018
1 parent 8568b05 commit f71eabb
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/phpunit/CRM/Utils/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,43 @@ public function testAddressFormat() {
$this->assertTrue((bool) strstr($formatted_address, 'UNITED STATES'));
}

/**
* Test state/province field's state_province_name token on getFormattedBillingAddressFieldsFromParameters
* and test using alternate names for state_province field
*/
public function testStateProvinceFormattedBillingAddress() {
$params = array(
'billing_street_address-99' => '123 Happy Place',
'billing_city-99' => 'Miami',
'billing_postal_code-99' => 33101,
'state_province-99' => '1000', // 1000 => Alabama (AL)
'country-99' => 'United States',
);

// set address_format (we are only interested in state_province & state_province_name)
$addFormat = '{contact.state_province}';
Civi::settings()->set('address_format', $addFormat);
$formatted_address = CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters($params, '99');
$this->assertTrue((bool) $formatted_address == 'AL');

$addFormat = '{contact.state_province_name}';
Civi::settings()->set('address_format', $addFormat);
$formatted_address = CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters($params, '99');
$this->assertTrue((bool) $formatted_address == 'Alabama');

// test using alternate names for state/province field
unset($params['state_province-99']);
$params['billing_state_province-99'] = '1000'; // alternate name 1
$addFormat = '{contact.state_province_name}';
Civi::settings()->set('address_format', $addFormat);
$formatted_address = CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters($params, '99');
$this->assertTrue((bool) $formatted_address == 'Alabama');

unset($params['state_province-99']);
$params['billing_state_province_id-99'] = '1000'; // alternate name 2
$addFormat = '{contact.state_province_name}';
Civi::settings()->set('address_format', $addFormat);
$formatted_address = CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters($params, '99');
$this->assertTrue((bool) $formatted_address == 'Alabama');
}
}

0 comments on commit f71eabb

Please sign in to comment.