From 6458a246133e74e504fd6c906613abb637c26d38 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Wed, 2 Dec 2026 09:51:12 -0400 Subject: [PATCH] Map every Address field country to a country code 14 countries in the Address field dropdown had no entry in the country code map, so get_country_code() returned an empty string for them. Add the dropdown spellings as aliases of the existing entries, plus the decoded Cote d'Ivoire name that a submitted entry holds. Co-Authored-By: Claude Opus 5.5 --- .../controllers/FrmAddressesController.php | 15 +++++++++++ tests/phpunit/fields/test_FrmFieldAddress.php | 26 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/classes/controllers/FrmAddressesController.php b/classes/controllers/FrmAddressesController.php index 01e5f29b19..2d9e69756d 100644 --- a/classes/controllers/FrmAddressesController.php +++ b/classes/controllers/FrmAddressesController.php @@ -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', @@ -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', @@ -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', @@ -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', @@ -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', @@ -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', @@ -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', @@ -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', @@ -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', @@ -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', diff --git a/tests/phpunit/fields/test_FrmFieldAddress.php b/tests/phpunit/fields/test_FrmFieldAddress.php index d5fa1bc776..6180838eea 100644 --- a/tests/phpunit/fields/test_FrmFieldAddress.php +++ b/tests/phpunit/fields/test_FrmFieldAddress.php @@ -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. */