Making WordPress.org


Ignore:
Timestamp:
04/20/2018 08:29:40 PM (8 years ago)
Author:
iandunn
Message:

Events: Only restrict results to a country when explicitly requested.

Otherwise, this creates a situation where an event within driving distance is not shown to somebody, just because it's on the other side of a border. There are some cases where the event might not be relevant (e.g., different languages are spoken in those countries), but there are many others where the event is relevant, so it's better to err on the side of showing too many events than too few.

See https://wordpress.slack.com/archives/C08M59V3P/p1524168308000202.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php

    r7144 r7145  
    2121    $tests_failed += test_get_location();
    2222    $tests_failed += test_get_events();
     23    $tests_failed += test_get_events_country_restriction();
    2324    $tests_failed += test_add_regional_wordcamps();
    2425    $tests_failed += test_build_response();
     
    125126            'input' => array(
    126127                'country' => 'AU',
     128                'restrict_by_country' => true,
    127129            ),
    128130            'expected' => array(
     
    906908
    907909/**
    908  * Get the cases for testing `get_location()`
     910 * Get the cases for testing `get_events()`.
    909911 *
    910912 * @return array
     
    931933                'number'  => '1',
    932934                'country' => 'AU',
     935                'restrict_by_country' => true,
    933936            ),
    934937            'expected' => array(
     
    936939                'country' => 'AU',
    937940            ),
     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 */
     952function 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 */
     982function 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' ),
    9381015        ),
    9391016    );
     
    10101087                'location' => array(
    10111088                    'country' => 'CA',
     1089                ),
     1090                'location_args' => array(
     1091                    'restrict_by_country' => true,
    10121092                ),
    10131093            ),
Note: See TracChangeset for help on using the changeset viewer.