Changeset 9749
- Timestamp:
- 04/20/2020 10:28:17 PM (5 years ago)
- Location:
- sites/trunk/api.wordpress.org/public_html/events/1.0
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified sites/trunk/api.wordpress.org/public_html/events/1.0/index.php ¶
r9748 r9749 958 958 'asia' => array( 959 959 'promo_start' => strtotime( '2019-12-20 00:00:00' ), 960 'regional_countries' => array( 961 'cn', 'hk', 'jp', 'kp', 'kr', 'mn', 'mo', 'tw', 'af', 'bd', 962 'bt', 'in', 'ir', 'lk', 'mv', 'np', 'pk', 'bn', 'id', 'kh', 963 'la', 'mm', 'my', 'ph', 'sg', 'th', 'tl', 'vn', 'au', 'nf', 964 'nz', 'fj', 'nc', 'pg', 'sb', 'vu', 'fm', 'gu', 'ki', 'mh', 965 'mp', 'nr', 'pw', 'as', 'ck', 'nu', 'pf', 'pn', 'tk', 'to', 966 'tv', 'wf', 'ws', 'tm', 'tj', 'kg', 'kz', 'uz', 'ae', 'am', 967 'az', 'bh', 'cy', 'ge', 'il', 'iq', 'jo', 'kw', 'lb', 'om', 968 'ps', 'qa', 'sa', 'sy', 'tr', 'ye' 960 961 'regional_countries' => array_merge( 962 get_iso_3166_2_country_codes( 'asia' ), 963 get_iso_3166_2_country_codes( 'oceania' ), 964 965 // Russia is often considered to be part of Asia geographically, and part of Europe politically. 966 array( 'RU' ) 969 967 ), 970 968 'event' => array( … … 987 985 'europe' => array( 988 986 'promo_start' => strtotime( '2020-04-04 00:00:00' ), 989 'regional_countries' => array( 990 // todo 987 'regional_countries' => array_merge( 988 get_iso_3166_2_country_codes( 'africa' ), 989 get_iso_3166_2_country_codes( 'europe' ) 991 990 ), 992 991 'event' => array( … … 1009 1008 'us' => array( 1010 1009 'promo_start' => strtotime( '2020-08-27 00:00:00' ), 1011 'regional_countries' => array( 1012 'us', 'ca', 'bz', 'cr', 'sv', 'gt', 'hn', 'mx', 'ni', 'pa', 1013 'ar', 'bo', 'br', 'cl', 'co', 'ec', 'gf', 'gy', 'py', 'pe', 1014 'sr', 'uy', 've', 'ag', 'aw', 'bs', 'bb', 'ky', 'cu', 'dm', 1015 'do', 'gd', 'ht', 'jm', 'kn', 'lc', 'vc', 'tt', 1010 1011 'regional_countries' => array_merge( 1012 get_iso_3166_2_country_codes( 'south america' ), 1013 get_iso_3166_2_country_codes( 'north america' ) 1016 1014 ), 1017 1015 'event' => array( … … 1033 1031 ), 1034 1032 ); 1033 } 1034 1035 /** 1036 * Get a list of ISO-3166-2 countries by continent. 1037 * 1038 * Data was sourced from https://dev.maxmind.com/geoip/legacy/codes/country_continent/ on 2020-04-17. 1039 * 1040 * @param string $continent 1041 * 1042 * @return array 1043 */ 1044 function get_iso_3166_2_country_codes( $continent = '' ) { 1045 $codes = array( 1046 'antarctica' => array( 'AQ', 'BV', 'GS', 'HM', 'TF' ), 1047 1048 'africa' => array( 1049 'AO', 'BF', 'BI', 'BJ', 'BW', 'CD', 'CF', 'CG', 'CI', 'CM', 'CV', 'DJ', 'DZ', 'EG', 'EH', 'ER', 'ET', 1050 'GA', 'GH', 'GM', 'GN', 'GQ', 'GW', 'KE', 'KM', 'LR', 'LS', 'LY', 'MA', 'MG', 'ML', 'MR', 'MU', 'MW', 1051 'MZ', 'NA', 'NE', 'NG', 'RE', 'RW', 'SC', 'SD', 'SH', 'SL', 'SN', 'SO', 'ST', 'SZ', 'TD', 'TG', 'TN', 1052 'TZ', 'UG', 'YT', 'ZA', 'ZM', 'ZW', 1053 ), 1054 1055 'asia' => array( 1056 // Includes the Middle East, Armenia, Azerbaijan, Cyprus, Georgia. 1057 'AE', 'AF', 'AM', 'AP', 'AZ', 'BD', 'BH', 'BN', 'BT', 'CC', 'CN', 'CX', 'CY', 'GE', 'HK', 'ID', 'IL', 1058 'IN', 'IO', 'IQ', 'IR', 'JO', 'JP', 'KG', 'KH', 'KP', 'KR', 'KW', 'KZ', 'LA', 'LB', 'LK', 'MM', 'MN', 1059 'MO', 'MV', 'MY', 'NP', 'OM', 'PH', 'PK', 'PS', 'QA', 'SA', 'SG', 'SY', 'TH', 'TJ', 'TL', 'TM', 'TW', 1060 'UZ', 'VN', 'YE', 1061 ), 1062 1063 'europe' => array( 1064 // Includes Russia, Turkey. 1065 'AD', 'AL', 'AT', 'AX', 'BA', 'BE', 'BG', 'BY', 'CH', 'CZ', 'DE', 'DK', 'EE', 'ES', 'EU', 'FI', 'FO', 1066 'FR', 'FX', 'GB', 'GG', 'GI', 'GR', 'HR', 'HU', 'IE', 'IM', 'IS', 'IT', 'JE', 'LI', 'LT', 'LU', 'LV', 1067 'MC', 'MD', 'ME', 'MK', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RS', 'RU', 'SE', 'SI', 'SJ', 'SK', 'SM', 1068 'TR', 'UA', 'VA', 1069 ), 1070 1071 'north america' => array( 1072 'AG', 'AI', 'AN', 'AW', 'BB', 'BL', 'BM', 'BS', 'BZ', 'CA', 'CR', 'CU', 'DM', 'DO', 'GD', 'GL', 'GP', 1073 'GT', 'HN', 'HT', 'JM', 'KN', 'KY', 'LC', 'MF', 'MQ', 'MS', 'MX', 'NI', 'PA', 'PM', 'PR', 'SV', 'TC', 1074 'TT', 'US', 'VC', 'VG', 'VI', 1075 ), 1076 1077 'oceania' => array( 1078 'AS', 'AU', 'CK', 'FJ', 'FM', 'GU', 'KI', 'MH', 'MP', 'NC', 'NF', 'NR', 'NU', 'NZ', 'PF', 'PG', 'PN', 1079 'PW', 'SB', 'TK', 'TO', 'TV', 'UM', 'VU', 'WF', 'WS', 1080 ), 1081 1082 'south america' => array( 1083 'AR', 'BO', 'BR', 'CL', 'CO', 'EC', 'FK', 'GF', 'GY', 'PE', 'PY', 'SR', 'UY', 'VE', 1084 ), 1085 ); 1086 1087 if ( $continent ) { 1088 return $codes[ $continent ]; 1089 } else { 1090 return $codes; 1091 } 1035 1092 } 1036 1093 … … 1070 1127 } elseif ( is_within_date_range( $current_time, strtotime( '+ 2 weeks', $start ), strtotime( '+ 4 weeks', $start ) ) ) { 1071 1128 // Phase 2: Show within regional countries for next two weeks. 1072 if ( ! empty( $location['country'] ) && in_array( strto lower( $location['country'] ), $data['regional_countries'], true ) ) {1129 if ( ! empty( $location['country'] ) && in_array( strtoupper( $location['country'] ), $data['regional_countries'], true ) ) { 1073 1130 $regional_wordcamps[] = $data['event']; 1074 1131 } 1075 1132 } elseif ( is_within_date_range( $current_time, strtotime( '+ 4 weeks', $start ), strtotime( '+ 6 weeks', $start ) ) ) { 1076 1133 // Phase 3: Show only within the event country for the last two weeks. 1077 if ( ! empty( $location['country'] ) && strto lower( $data['event']['location']['country'] ) === strtolower( $location['country'] ) ) {1134 if ( ! empty( $location['country'] ) && strtoupper( $data['event']['location']['country'] ) === strtoupper( $location['country'] ) ) { 1078 1135 $regional_wordcamps[] = $data['event']; 1079 1136 } -
TabularUnified sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php ¶
r9641 r9749 26 26 $tests_failed += test_build_response(); 27 27 $tests_failed += test_is_client_core(); 28 $tests_failed += test_get_iso_3166_2_country_codes(); 28 29 29 30 $query_count = count( $wpdb->queries ); … … 1182 1183 'us' => array( 1183 1184 'promo_start' => strtotime( '2019-08-16 00:00:00' ), 1184 'regional_countries' => array( 1185 'us', 'ca', 'bz', 'cr', 'sv', 'gt', 'hn', 'mx', 'ni', 'pa', 1186 'ar', 'bo', 'br', 'cl', 'co', 'ec', 'gf', 'gy', 'py', 'pe', 1187 'sr', 'uy', 've', 'ag', 'aw', 'bs', 'bb', 'ky', 'cu', 'dm', 1188 'do', 'gd', 'ht', 'jm', 'kn', 'lc', 'vc', 'tt', 1185 1186 'regional_countries' => array_merge( 1187 get_iso_3166_2_country_codes( 'south america' ), 1188 get_iso_3166_2_country_codes( 'north america' ) 1189 1189 ), 1190 1190 'event' => array( … … 1448 1448 1449 1449 /** 1450 * Test `get_iso_3166_2_country_codes()`. 1451 */ 1452 function test_get_iso_3166_2_country_codes() { 1453 $failed = 0; 1454 $cases = array( 1455 'antarctica' => 'HM', 1456 'africa' => 'KM', 1457 'asia' => 'SA', 1458 'europe' => 'IM', 1459 'north america' => 'MQ', 1460 'oceania' => 'MP', 1461 'south america' => 'GY', 1462 ); 1463 1464 printf( "\n\nRunning %d get_iso_3166_2_country_codes() tests\n", count( $cases ) ); 1465 1466 foreach ( $cases as $continent => $sample_country ) { 1467 $countries = get_iso_3166_2_country_codes( $continent ); 1468 1469 $expected_result = true; 1470 $actual_result = in_array( $sample_country, $countries, true ); 1471 $passed = $expected_result === $actual_result; 1472 1473 output_results( $continent, $passed, $expected_result, $actual_result ); 1474 1475 if ( ! $passed ) { 1476 $failed++; 1477 } 1478 } 1479 1480 return $failed; 1481 } 1482 1483 /** 1450 1484 * Stub to simulate cache misses, so that the tests always get fresh results 1451 1485 *
Note: See TracChangeset
for help on using the changeset viewer.