Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions classes/controllers/FrmAddressesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ private static function maybe_define_country_codes() { // phpcs:ignore SlevomatC
'Bhutan' => 'BT',
'Bolivia' => 'BO',
'Bonaire, Saint Eustatius and Saba' => 'BQ',
'Bonaire, Sint Eustatius and Saba' => 'BQ',
'Bosnia and Herzegovina' => 'BA',
'Botswana' => 'BW',
'Bouvet Island' => 'BV',
Expand All @@ -263,6 +264,8 @@ private static function maybe_define_country_codes() { // phpcs:ignore SlevomatC
'Bulgaria' => 'BG',
'Burkina Faso' => 'BF',
'Burundi' => 'BI',
'Côte d\'Ivoire' => 'CI',
'Côte d\'Ivoire' => 'CI',
'Cambodia' => 'KH',
'Cameroon' => 'CM',
'Canada' => 'CA',
Expand All @@ -273,9 +276,11 @@ private static function maybe_define_country_codes() { // phpcs:ignore SlevomatC
'Chile' => 'CL',
'China' => 'CN',
'Christmas Island' => 'CX',
'Cocos (Keeling) Islands' => 'CC',
'Cocos Islands' => 'CC',
'Colombia' => 'CO',
'Comoros' => 'KM',
'Congo' => 'CG',
'Cook Islands' => 'CK',
'Costa Rica' => 'CR',
'Croatia' => 'HR',
Expand All @@ -297,6 +302,7 @@ private static function maybe_define_country_codes() { // phpcs:ignore SlevomatC
'Estonia' => 'EE',
'Ethiopia' => 'ET',
'Falkland Islands' => 'FK',
'Falkland Islands (Malvinas)' => 'FK',
'Faroe Islands' => 'FO',
'Fiji' => 'FJ',
'Finland' => 'FI',
Expand All @@ -322,6 +328,7 @@ private static function maybe_define_country_codes() { // phpcs:ignore SlevomatC
'Guyana' => 'GY',
'Haiti' => 'HT',
'Heard Island and McDonald Islands' => 'HM',
'Holy See' => 'VA',
'Honduras' => 'HN',
'Hong Kong' => 'HK',
'Hungary' => 'HU',
Expand Down Expand Up @@ -394,6 +401,7 @@ private static function maybe_define_country_codes() { // phpcs:ignore SlevomatC
'Oman' => 'OM',
'Pakistan' => 'PK',
'Palau' => 'PW',
'Palestine' => 'PS',
'Palestinian Territory' => 'PS',
'Panama' => 'PA',
'Papua New Guinea' => 'PG',
Expand All @@ -412,9 +420,11 @@ private static function maybe_define_country_codes() { // phpcs:ignore SlevomatC
'Rwanda' => 'RW',
'Saint Barthelemy' => 'BL',
'Saint Helena' => 'SH',
'Saint Helena, Ascension and Tristan da Cunha' => 'SH',
'Saint Kitts and Nevis' => 'KN',
'Saint Lucia' => 'LC',
'Saint Martin' => 'MF',
'Saint Martin (French part)' => 'MF',
'Saint Pierre and Miquelon' => 'PM',
'Saint Vincent and the Grenadines' => 'VC',
'Samoa' => 'WS',
Expand All @@ -427,6 +437,7 @@ private static function maybe_define_country_codes() { // phpcs:ignore SlevomatC
'Sierra Leone' => 'SL',
'Singapore' => 'SG',
'Sint Maarten' => 'SX',
'Sint Maarten (Dutch part)' => 'SX',
'Slovakia' => 'SK',
'Slovenia' => 'SI',
'Solomon Islands' => 'SB',
Expand All @@ -448,6 +459,7 @@ private static function maybe_define_country_codes() { // phpcs:ignore SlevomatC
'Tajikistan' => 'TJ',
'Tanzania' => 'TZ',
'Thailand' => 'TH',
'Timor-Leste' => 'TL',
'Togo' => 'TG',
'Tokelau' => 'TK',
'Tonga' => 'TO',
Expand All @@ -468,8 +480,11 @@ private static function maybe_define_country_codes() { // phpcs:ignore SlevomatC
'Uzbekistan' => 'UZ',
'Vanuatu' => 'VU',
'Vatican' => 'VA',
'Vatican City' => 'VA',
'Venezuela' => 'VE',
'Vietnam' => 'VN',
'Virgin Islands, British' => 'VG',
'Virgin Islands, U.S.' => 'VI',
'Wallis and Futuna' => 'WF',
'Western Sahara' => 'EH',
'Yemen' => 'YE',
Expand Down
26 changes: 26 additions & 0 deletions tests/phpunit/fields/test_FrmFieldAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,32 @@ public function test_get_country_codes_matches_get_country_code() {
}
}

/**
* Every country the Address field offers has a country code.
*
* @covers FrmAddressesController::get_country_code
*/
public function test_get_country_code_covers_every_country_option() {
$missing = array();

foreach ( FrmFieldsHelper::get_countries() as $country ) {
if ( '' === FrmAddressesController::get_country_code( $country ) ) {
$missing[] = $country;
}
}

$this->assertSame( array(), $missing, 'Every country option should map to a country code.' );
}

/**
* A submitted country is the decoded option text, so it needs a code too.
*
* @covers FrmAddressesController::get_country_code
*/
public function test_get_country_code_maps_decoded_country_name() {
$this->assertSame( 'CI', FrmAddressesController::get_country_code( html_entity_decode( 'Côte d\'Ivoire', ENT_QUOTES, 'UTF-8' ) ) );
}

/**
* Test get_export_headings adds address columns.
*/
Expand Down