- Timestamp:
- 04/20/2018 08:29:40 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php
r7144 r7145 21 21 $tests_failed += test_get_location(); 22 22 $tests_failed += test_get_events(); 23 $tests_failed += test_get_events_country_restriction(); 23 24 $tests_failed += test_add_regional_wordcamps(); 24 25 $tests_failed += test_build_response(); … … 125 126 'input' => array( 126 127 'country' => 'AU', 128 'restrict_by_country' => true, 127 129 ), 128 130 'expected' => array( … … 906 908 907 909 /** 908 * Get the cases for testing `get_ location()`910 * Get the cases for testing `get_events()`. 909 911 * 910 912 * @return array … … 931 933 'number' => '1', 932 934 'country' => 'AU', 935 'restrict_by_country' => true, 933 936 ), 934 937 'expected' => array( … … 936 939 'country' => 'AU', 937 940 ), 941 ), 942 ); 943 944 return $cases; 945 } 946 947 /** 948 * Test `get_events()` `restricted_by_country` parameter. 949 * 950 * @return bool The number of failures 951 */ 952 function test_get_events_country_restriction() { 953 $failed = 0; 954 $cases = get_events_country_restriction_test_cases(); 955 956 printf( "\n\nRunning %d events restrict by country tests\n", count( $cases ) ); 957 958 foreach ( $cases as $case_id => $case ) { 959 $actual_result = get_events( $case['input'] ); 960 $actual_countries = array_column( array_column( $actual_result, 'location' ), 'country' ); 961 $actual_countries = array_unique( array_map( 'strtoupper', $actual_countries ) ); 962 963 sort( $actual_countries ); 964 965 $passed = $actual_countries === $case['expected_countries']; 966 967 output_results( $case_id, $passed, $case['expected_countries'], $actual_countries ); 968 969 if ( ! $passed ) { 970 $failed++; 971 } 972 } 973 974 return $failed; 975 } 976 977 /** 978 * Get the cases for testing the `get_events()` `restricted_by_country` parameter. 979 * 980 * @return array 981 */ 982 function get_events_country_restriction_test_cases() { 983 $cases = array( 984 'restricted-by-country' => array( 985 'input' => array( 986 'number' => '500', 987 'country' => 'CA', 988 'restrict_by_country' => true, 989 ), 990 'expected_countries' => array( 'CA' ), 991 ), 992 993 /* 994 * This assumes there will always be at least an upcoming event on both sides of the border, so the 995 * coordinates need to be half-way between two very active groups in different countries, where the 996 * mid-point is less than `$event_distances['meetup']`. 997 * 998 * If Toronto, CA and Buffalo, US no longer work in the future, then another possible location would be 999 * `53.997654, -6.403377` -- between Belfast, GB and Dublin, IE -- or `47.986952, -122.961350` -- 1000 * between Seattle, US and Victoria, CA. 1001 * 1002 * See https://wordpress.slack.com/archives/C08M59V3P/p1524168308000202. 1003 */ 1004 'not-restricted-by-country' => array( 1005 'input' => array( 1006 'number' => '500', 1007 'restrict_by_country' => false, 1008 1009 'nearby' => array( 1010 'latitude' => '43.254372', 1011 'longitude' => '-79.063746', 1012 ), 1013 ), 1014 'expected_countries' => array( 'CA', 'US' ), 938 1015 ), 939 1016 ); … … 1010 1087 'location' => array( 1011 1088 'country' => 'CA', 1089 ), 1090 'location_args' => array( 1091 'restrict_by_country' => true, 1012 1092 ), 1013 1093 ),
Note: See TracChangeset
for help on using the changeset viewer.