- Timestamp:
- 01/22/2021 08:18:36 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php
r10582 r10625 3 3 namespace Dotorg\API\Events\Tests; 4 4 use PHPUnit\Framework\TestCase; 5 use Requests_Response; 6 5 7 use function Dotorg\API\Events\{ 6 8 get_events, get_location, build_response, is_client_core, pin_one_off_events, … … 14 16 public static function setUpBeforeClass() : void { 15 17 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 ); 16 56 } 17 57
Note: See TracChangeset
for help on using the changeset viewer.