Making WordPress.org


Ignore:
Timestamp:
04/20/2020 10:28:21 PM (4 years ago)
Author:
iandunn
Message:

Events: Remove duplicate events after all events have been added.

pin_next_online_wordcamp() will be added in a subsequent commit, and at that point this function will need to be called after all events from been added dynamically.

File:
1 edited

Legend:

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

    r9749 r9750  
    2727    $tests_failed += test_is_client_core();
    2828    $tests_failed += test_get_iso_3166_2_country_codes();
     29    $tests_failed += test_remove_duplicate_events();
    2930
    3031    $query_count  = count( $wpdb->queries );
     
    12581259    $tests_expect_changes['core-user-agent'] = maybe_add_regional_wordcamps( $local_events, $region_data, $core_user_agent, $time_during_promo_phase_1, $location_country_within_region );
    12591260
    1260     // There should only be one entry for an event, even if the local event array already contains the regional event.
    1261     $tests_expect_no_changes['duplicate-event'] = maybe_add_regional_wordcamps( array( $region_data['us']['event'] ), $region_data, $core_user_agent, $time_during_promo_phase_1, $location_country_within_region );
    1262 
    12631261    foreach ( $tests_expect_no_changes as $name => $result ) {
    1264         switch ( $name ) {
    1265             case 'duplicate-event':
    1266                 if ( $result !== array( $region_data['us']['event'] ) ) {
    1267                     $failed++;
    1268                     output_results( $name, false, array( $region_data['us']['event'] ), $result );
    1269                 }
    1270                 break;
    1271             default:
    1272                 if ( $result !== $local_events ) {
    1273                     $failed++;
    1274                     output_results( $name, false, $local_events, $result );
    1275                 }
    1276                 break;
     1262        if ( $result !== $local_events ) {
     1263            $failed++;
     1264            output_results( $name, false, $local_events, $result );
    12771265        }
    12781266    }
     
    14821470
    14831471/**
     1472 * Test `remove_duplicate_events()`.
     1473 */
     1474function test_remove_duplicate_events() {
     1475    $duplicate_events = array(
     1476        // Each of these represents an event; extraneous fields have been removed for readability.
     1477        array (
     1478            'url' => 'https://2020.us.wordcamp.org/',
     1479        ),
     1480
     1481        array (
     1482            'url' => 'https://2020.detroit.wordcamp.org/',
     1483        ),
     1484
     1485        array(
     1486            // Intentionally missing the trailing slash, to account for inconsistencies in data.
     1487            'url' => 'https://2020.us.wordcamp.org',
     1488        )
     1489    );
     1490
     1491    printf( "\n\nRunning 1 remove_duplicate_events() test\n" );
     1492
     1493    $expected_result = array(
     1494        array (
     1495            'url' => 'https://2020.us.wordcamp.org',
     1496        ),
     1497
     1498        array (
     1499            'url' => 'https://2020.detroit.wordcamp.org/',
     1500        ),
     1501    );
     1502
     1503    $actual_result   = remove_duplicate_events( $duplicate_events );
     1504    $passed          = $expected_result === $actual_result;
     1505
     1506    output_results( 'remove duplicate events', $passed, $expected_result, $actual_result );
     1507
     1508    return $passed ? 0 : 1;
     1509}
     1510
     1511/**
    14841512 * Stub to simulate cache misses, so that the tests always get fresh results
    14851513 *
Note: See TracChangeset for help on using the changeset viewer.