Making WordPress.org


Ignore:
Timestamp:
11/06/2017 09:03:28 PM (7 years ago)
Author:
iandunn
Message:

Events: Add regional WordCamps to the Core widget for extra promotion.

File:
1 edited

Legend:

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

    r6076 r6078  
    2020    $tests_failed += test_get_location();
    2121    $tests_failed += test_get_events();
     22    $tests_failed += test_add_regional_wordcamps();
    2223    $tests_failed += test_build_response();
    2324    $query_count  = count( $wpdb->queries );
     
    10191020
    10201021/**
     1022 * Test `add_regional_events()`
     1023 *
     1024 * @return int
     1025 */
     1026function test_add_regional_wordcamps() {
     1027    $failed = 0;
     1028
     1029    $local_events = get_events( array(
     1030        'number' => '5',
     1031        'nearby' => array(
     1032            'latitude'  => '-33.849951',
     1033            'longitude' => '18.426246',
     1034        ),
     1035    ) );
     1036
     1037    // Make sure there's at least one event, otherwise there could be false positives.
     1038    if ( ! $local_events ) {
     1039        $local_events[] = array( 'title' => 'Mock Event' );
     1040    }
     1041
     1042    printf( "\n\nRunning %d add_regional_wordcamps() tests\n", 2 );
     1043
     1044    // Test that no changes were made if the user agent isn't Core.
     1045    $events_no_user_agent = add_regional_wordcamps( $local_events, '' );
     1046
     1047    if ( $events_no_user_agent !== $local_events ) {
     1048        $failed++;
     1049        output_results( 'no-user-agent', false, $local_events, $events_no_user_agent );
     1050    }
     1051
     1052    /*
     1053     * Test that local events were unharmed if the user agent is Core.
     1054     *
     1055     * There isn't an easy way to mock time(), so this doesn't test that the events were added
     1056     * correctly. It just makes sure that local events weren't removed.
     1057     */
     1058    $events_core_user_agent = add_regional_wordcamps( $local_events, 'WordPress/4.9; https://example.org' );
     1059
     1060    if (
     1061        count( $events_core_user_agent ) < count( $local_events ) ||
     1062        ! in_array( $local_events[0], $events_core_user_agent, true )
     1063    ) {
     1064        $failed++;
     1065        output_results( 'core-user-agent', false, 'local events were not affected', $events_core_user_agent );
     1066    }
     1067
     1068    return $failed;
     1069}
     1070
     1071/**
    10211072 * Stub to simulate cache misses, so that the tests always get fresh results
    10221073 *
Note: See TracChangeset for help on using the changeset viewer.