Browse Source

added tests

pull/39/head
sebsel 7 years ago
parent
commit
67c159ec29
3 changed files with 99 additions and 0 deletions
  1. +65
    -0
      tests/FacebookTest.php
  2. +17
    -0
      tests/data/graph.facebook.com/v2.9_1596554663924436
  3. +17
    -0
      tests/data/graph.facebook.com/v2.9_446197069049722

+ 65
- 0
tests/FacebookTest.php View File

@ -0,0 +1,65 @@
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class FacebookTest extends PHPUnit_Framework_TestCase {
private $http;
public function setUp() {
$this->client = new Parse();
$this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
$this->client->mc = null;
}
private function parse($params) {
$request = new Request($params);
$response = new Response();
return $this->client->parse($request, $response);
}
public function testFacebookEventWithHCard() {
$url = 'https://www.facebook.com/events/446197069049722/';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$card = $data['data']['refs'][0];
$this->assertEquals('event', $data['data']['type']);
$this->assertEquals('IndieWeb Summit', $data['data']['name']);
$this->assertEquals('2017-06-24T09:00:00-0700', $data['data']['start']);
$this->assertEquals('2017-06-25T18:00:00-0700', $data['data']['end']);
$this->assertContains('The seventh annual gathering for independent web creators of all kinds,', $data['data']['summary']);
$this->assertEquals('https://facebook.com/332204056925945', $data['data']['location']);
$this->assertEquals('card', $card['type']);
$this->assertEquals('https://facebook.com/332204056925945', $card['url']);
$this->assertEquals('Mozilla PDX', $card['name']);
$this->assertEquals('97209', $card['postal-code']);
$this->assertEquals('Portland', $card['locality']);
$this->assertEquals('OR', $card['region']);
$this->assertEquals('1120 NW Couch St, Ste 320', $card['street-address']);
$this->assertEquals('United States', $card['country']);
$this->assertEquals('45.5233192', $card['latitude']);
$this->assertEquals('-122.6824722', $card['longitude']);
}
public function testFacebookEvent() {
$url = 'https://www.facebook.com/events/1596554663924436/';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$card = $data['data']['refs'][0];
$this->assertEquals('event', $data['data']['type']);
$this->assertEquals('Homebrew Website Club', $data['data']['name']);
$this->assertEquals('2015-04-22T19:00:00-0400', $data['data']['start']);
$this->assertContains('Are you building your own website? Indie reader?', $data['data']['summary']);
$this->assertEquals('Charging Bull - WeeWork - 25 Broadway, New York, NY 10004', $data['data']['location']);
}
}

+ 17
- 0
tests/data/graph.facebook.com/v2.9_1596554663924436 View File

@ -0,0 +1,17 @@
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
ETag: "dd72a86bf1349e65bf77eb6ea08dd8df8ead9100"
Pragma: no-cache
Cache-Control: private, no-cache, no-store, must-revalidate
x-fb-rev: 3113126
Content-Type: application/json; charset=UTF-8
x-fb-trace-id: GBOFw9pYkZY
facebook-api-version: v2.9
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Vary: Accept-Encoding
X-FB-Debug: J6wZdSjkKDtf5Tyc3RO0VzVdsjAOdRwB1q7NxbzSmkUGPheeqeYYQ4nSHCjHxFTGuqsXhLzdAt4UVnK56yvR8Q==
Date: Fri, 23 Jun 2017 22:59:59 GMT
Transfer-Encoding: chunked
Connection: keep-alive
{"description":"Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with like-minded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project. \n\n Contact (914) 414-1775 when you arrive to be admitted. \n\n\nMore information: \u0040[NjQyMTgzOTU5MjA4MTA3Omh0dHBzXGEvL2luZGlld2ViY2FtcC5jb20vZXZlbnRzLzIwMTUtMDQtMjItaG9tZWJyZXctd2Vic2l0ZS1jbHViOjo=:\u0040[NjQyMTgzOTU5MjA4MTA3Omh0dHBzXGEvL2luZGlld2ViY2FtcC5jb20vZXZlbnRzLzIwMTUtMDQtMjItaG9tZWJyZXctd2Vic2l0ZS1jbHViOjo=:https:\/\/indiewebcamp.com\/events\/2015-04-22-homebrew-website-club]]","name":"Homebrew Website Club","place":{"name":"Charging Bull - WeeWork - 25 Broadway, New York, NY 10004"},"start_time":"2015-04-22T19:00:00-0400","id":"1596554663924436"}

+ 17
- 0
tests/data/graph.facebook.com/v2.9_446197069049722 View File

@ -0,0 +1,17 @@
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
ETag: "cf33fe9966e2a664781acc2043f226d67946b048"
Pragma: no-cache
Cache-Control: private, no-cache, no-store, must-revalidate
x-fb-rev: 3113126
Content-Type: application/json; charset=UTF-8
x-fb-trace-id: Ad/GSn3EwKN
facebook-api-version: v2.9
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Vary: Accept-Encoding
X-FB-Debug: 4p8L2dOeNMJ5Ay6meL3zW4mh9TZgCNUEOsNRDUS8twNTtlvnkHiHfqSuQBIyvTlppBpOG8sWF+2MNQT4LaENtg==
Date: Fri, 23 Jun 2017 22:57:08 GMT
Transfer-Encoding: chunked
Connection: keep-alive
{"description":"The seventh annual gathering for independent web creators of all kinds, from graphic artists, to designers, UX engineers, coders, hackers, to share ideas, actively work on creating for their own personal websites, and build upon each others creations.\n\nIMPORTANT: Please register for a ticket from https:\/\/2017.indieweb.org\/ to attend! RSVPing on Facebook is not enough. Your registration will ensure that we get enough food for everyone!\n\nOriginally posted at https:\/\/aaronparecki.com\/2017\/06\/24\/1\/indieweb-summit","end_time":"2017-06-25T18:00:00-0700","name":"IndieWeb Summit","place":{"name":"Mozilla PDX","location":{"city":"Portland","country":"United States","latitude":45.5233192,"longitude":-122.6824722,"state":"OR","street":"1120 NW Couch St, Ste 320","zip":"97209"},"id":"332204056925945"},"start_time":"2017-06-24T09:00:00-0700","id":"446197069049722"}

Loading…
Cancel
Save