You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.6 KiB

6 years ago
  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. use Symfony\Component\HttpFoundation\Response;
  4. class FacebookTest extends PHPUnit_Framework_TestCase {
  5. private $http;
  6. public function setUp() {
  7. $this->client = new Parse();
  8. $this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
  9. $this->client->mc = null;
  10. }
  11. private function parse($params) {
  12. $request = new Request($params);
  13. $response = new Response();
  14. return $this->client->parse($request, $response);
  15. }
  16. public function testFacebookEventWithHCard() {
  17. $url = 'https://www.facebook.com/events/446197069049722/';
  18. $response = $this->parse(['url' => $url]);
  19. $body = $response->getContent();
  20. $this->assertEquals(200, $response->getStatusCode());
  21. $data = json_decode($body, true);
  22. $card = $data['data']['refs'][0];
  23. $this->assertEquals('event', $data['data']['type']);
  24. $this->assertEquals('IndieWeb Summit', $data['data']['name']);
  25. $this->assertEquals('2017-06-24T09:00:00-0700', $data['data']['start']);
  26. $this->assertEquals('2017-06-25T18:00:00-0700', $data['data']['end']);
  27. $this->assertContains('The seventh annual gathering for independent web creators of all kinds,', $data['data']['summary']);
  28. $this->assertEquals('https://facebook.com/332204056925945', $data['data']['location']);
  29. $this->assertEquals('card', $card['type']);
  30. $this->assertEquals('https://facebook.com/332204056925945', $card['url']);
  31. $this->assertEquals('Mozilla PDX', $card['name']);
  32. $this->assertEquals('97209', $card['postal-code']);
  33. $this->assertEquals('Portland', $card['locality']);
  34. $this->assertEquals('OR', $card['region']);
  35. $this->assertEquals('1120 NW Couch St, Ste 320', $card['street-address']);
  36. $this->assertEquals('United States', $card['country']);
  37. $this->assertEquals('45.5233192', $card['latitude']);
  38. $this->assertEquals('-122.6824722', $card['longitude']);
  39. }
  40. public function testFacebookEvent() {
  41. $url = 'https://www.facebook.com/events/1596554663924436/';
  42. $response = $this->parse(['url' => $url]);
  43. $body = $response->getContent();
  44. $this->assertEquals(200, $response->getStatusCode());
  45. $data = json_decode($body, true);
  46. $card = $data['data']['refs'][0];
  47. $this->assertEquals('event', $data['data']['type']);
  48. $this->assertEquals('Homebrew Website Club', $data['data']['name']);
  49. $this->assertEquals('2015-04-22T19:00:00-0400', $data['data']['start']);
  50. $this->assertContains('Are you building your own website? Indie reader?', $data['data']['summary']);
  51. $this->assertEquals('Charging Bull - WeeWork - 25 Broadway, New York, NY 10004', $data['data']['location']);
  52. }
  53. }