Making WordPress.org


Ignore:
Timestamp:
01/22/2021 08:18:36 PM (5 years ago)
Author:
iandunn
Message:

Events: Add e2e test.

File:
1 edited

Legend:

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

    r10582 r10625  
    33namespace Dotorg\API\Events\Tests;
    44use PHPUnit\Framework\TestCase;
     5use Requests_Response;
     6
    57use function Dotorg\API\Events\{
    68    get_events, get_location, build_response, is_client_core, pin_one_off_events,
     
    1416    public static function setUpBeforeClass() : void {
    1517        require_once dirname( __DIR__ ) . '/index.php';
     18    }
     19
     20    /**
     21     * Asserts that an HTTP response is valid and contains an event.
     22     *
     23     * @param Requests_Response $response
     24     */
     25    public function assertResponseHasEvent( $response ) {
     26        $body  = json_decode( $response->body );
     27        $event = $body->events[0];
     28
     29        $this->assertSame( 200, $response->status_code );
     30        $this->assertNull( $body->error );
     31
     32        $this->assertIsObject( $body->location );
     33        $this->assertTrue(
     34            ( isset( $body->location->ip ) && is_numeric( $body->location->ip ) ) ||
     35            ( isset( $body->location->latitude ) && is_numeric( $body->location->latitude ) )
     36        );
     37
     38        $this->assertContains( $event->type, array( 'wordcamp', 'meetup' ) );
     39        $this->assertIsString( $event->title );
     40        $this->assertIsNumeric( $event->start_unix_timestamp );
     41        $this->assertSame( $event->url, filter_var( $event->url, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED & FILTER_FLAG_QUERY_REQUIRED ) );
     42        $this->assertIsNumeric( $event->location->latitude );
     43    }
     44
     45    /**
     46     * @covers ::main
     47     *
     48     * @group e2e
     49     */
     50    public function test_get_events_e2e() : void {
     51        $response = send_request( '/events/1.0/?location=seattle&locale=en_US&timezone=America/Los_Angeles' );
     52        $body     = json_decode( $response->body );
     53
     54        $this->assertResponseHasEvent( $response );
     55        $this->assertSame( 'Seattle', $body->location->description );
    1656    }
    1757
Note: See TracChangeset for help on using the changeset viewer.