Making WordPress.org

Changeset 10548


Ignore:
Timestamp:
01/04/2021 11:41:00 PM (6 years ago)
Author:
iandunn
Message:

Events: Create permenant function for pinning one-off events.

This will make tasks like r10527 easier and quicker in the future.

Location:
sites/trunk/api.wordpress.org/public_html/events/1.0
Files:
2 edited

Legend:

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

    r10546 r10548  
    236236
    237237                $events = pin_next_online_wordcamp( $events, $_SERVER['HTTP_USER_AGENT'], time() );
    238 
    239238                $events = pin_next_workshop_discussion_group( $events, $_SERVER['HTTP_USER_AGENT'] );
    240 
     239                $events = pin_one_off_events( $events, time() );
    241240                $events = remove_duplicate_events( $events );
    242 
    243                 // tmp remove, only here b/c last minute
    244                 if ( time() < strtotime( 'December 18, 2020' ) ) {
    245                         array_unshift( $events, array(
    246                                 'type'                 => 'wordcamp',
    247                                 'title'                => 'State of the Word',
    248                                 'url'                  => 'https://wordpress.org/news/2020/12/state-of-the-word-2020/',
    249                                 'meetup'               => '',
    250                                 'meetup_url'           => '',
    251                                 'date'                 => '2020-12-17 00:00:00',
    252                                 'end_date'             => '2020-12-17 23:00:00',
    253                                 'start_unix_timestamp' => 1608195600,
    254                                 'end_unix_timestamp'   => 1608267600,
    255 
    256                                 'location' => array(
    257                                         'location'  => 'Online',
    258                                         'country'   => 'US',
    259                                         'latitude'  => 29.768241024468665,
    260                                         'longitude' => -95.36765276500797,
    261                                 ),
    262                         ) );
    263                 }
    264241
    265242                // Internal location data cannot be exposed in the response, see get_location().
     
    15291506
    15301507/**
     1508 * Pin one-off events.
     1509 */
     1510function pin_one_off_events( $events, $current_time ) {
     1511        if ( $current_time < strtotime( 'December 18, 2020' ) ) {
     1512                array_unshift( $events, array(
     1513                        'type'                 => 'wordcamp',
     1514                        'title'                => 'State of the Word',
     1515                        'url'                  => 'https://wordpress.org/news/2020/12/state-of-the-word-2020/',
     1516                        'meetup'               => '',
     1517                        'meetup_url'           => '',
     1518                        'date'                 => '2020-12-17 00:00:00',
     1519                        'end_date'             => '2020-12-17 23:00:00',
     1520                        'start_unix_timestamp' => 1608195600,
     1521                        'end_unix_timestamp'   => 1608267600,
     1522
     1523                        'location' => array(
     1524                                'location'  => 'Online',
     1525                                'country'   => 'US',
     1526                                'latitude'  => 29.768241024468665,
     1527                                'longitude' => -95.36765276500797,
     1528                        ),
     1529                ) );
     1530        }
     1531
     1532        return $events;
     1533}
     1534
     1535/**
    15311536 * Remove duplicate events, based on the URL.
    15321537 *
  • sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index-phpunit.php

    r10546 r10548  
    33namespace Dotorg\API\Events\Tests;
    44use PHPUnit\Framework\TestCase;
    5 use function Dotorg\API\Events\{ get_events, get_location, build_response, is_client_core };
     5use function Dotorg\API\Events\{ get_events, get_location, build_response, is_client_core, pin_one_off_events };
    66
    77/**
     
    10511051
    10521052        /**
     1053         * @covers ::pin_one_off_events
     1054         *
     1055         * @group unit
     1056         */
     1057        function test_pin_one_off_events() {
     1058                $seed_events = array();
     1059
     1060                // Don't forget to update the values here when they're updated in the FUT.
     1061                $actual_events_before_expiration = pin_one_off_events( $seed_events, strtotime( 'December 17, 2020' ) );
     1062                $actual_events_after_expiration  = pin_one_off_events( $seed_events, strtotime( 'December 18, 2020' ) );
     1063
     1064                $this->assertIsArray( $actual_events_after_expiration );
     1065                $this->assertEmpty( $actual_events_after_expiration );
     1066
     1067                $this->assertIsArray( $actual_events_before_expiration );
     1068                $this->assertSame( 'State of the Word', $actual_events_before_expiration[0]['title'] );
     1069        }
     1070
     1071        /**
    10531072         * @covers ::is_client_core
    10541073         *
Note: See TracChangeset for help on using the changeset viewer.