Making WordPress.org


Ignore:
Timestamp:
03/08/2017 04:32:24 PM (9 years ago)
Author:
iandunn
Message:

Events API: Return the name of a city when passed coordinates

File:
1 edited

Legend:

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

    r5101 r5128  
    1616    $failed = 0;
    1717    $failed += test_get_location();
     18    $failed += test_get_city_from_coordinates();
    1819
    1920    printf( "\n\nFinished running all tests. %d failed.\n", $failed );
     
    581582}
    582583
     584/**
     585 * Test `get_city_from_coordinates()`
     586 *
     587 * @todo This can probably be refactored along with test_get_location() into a more abstract/DRY general-purpose
     588 *       test runner.
     589 *
     590 * @return bool The number of failures
     591 */
     592function test_get_city_from_coordinates() {
     593    $failed = 0;
     594    $cases  = get_city_from_coordinates_test_cases();
     595
     596    printf( "\n\nRunning %d city from coordinate tests\n", count( $cases ) );
     597
     598    foreach ( $cases as $case_id => $case ) {
     599        $actual_result = get_city_from_coordinates( $case['input']['latitude'], $case['input']['longitude'] );
     600        $passed        = $case['expected'] === $actual_result;
     601
     602        output_results( $case_id, $passed, $case['expected'], $actual_result );
     603
     604        if ( ! $passed ) {
     605            $failed++;
     606        }
     607    }
     608
     609    return $failed;
     610}
     611
     612/**
     613 * Get the cases for testing `get_city_from_coordinates()`
     614 *
     615 * @return array
     616 */
     617function get_city_from_coordinates_test_cases() {
     618     $cases = array(
     619        'lower-latitude-higher-longitude' => array(
     620            'input' => array(
     621                'latitude'  => '60.199',
     622                'longitude' => '24.660'
     623            ),
     624            'expected' => 'Espoo',
     625        ),
     626
     627        'higher-latitude-lower-longitude' => array(
     628            'input' => array(
     629                'latitude'  => '22.000',
     630                'longitude' => '95.900'
     631            ),
     632            'expected' => 'Mandalay',
     633        ),
     634
     635        'middle-of-no-and-where' => array(
     636            'input' => array(
     637                'latitude'  => '-23.121',
     638                'longitude' => '125.071'
     639            ),
     640            'expected' => false,
     641        ),
     642    );
     643
     644    return $cases;
     645}
     646
    583647run_tests();
Note: See TracChangeset for help on using the changeset viewer.