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.

67 lines
2.7 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 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->mc = null;
  9. }
  10. private function parse($params) {
  11. $request = new Request($params);
  12. $response = new Response();
  13. $result = $this->client->parse($request, $response);
  14. $body = $result->getContent();
  15. $this->assertEquals(200, $result->getStatusCode());
  16. return json_decode($body, true);
  17. }
  18. private function loadFbObject($id) {
  19. return file_get_contents(dirname(__FILE__).'/data/graph.facebook.com/'.$id.'.json');
  20. }
  21. public function testFacebookEventWithHCard() {
  22. $url = 'https://www.facebook.com/events/446197069049722/';
  23. $json = $this->loadFbObject('446197069049722');
  24. $data = $this->parse(['url' => $url, 'body' => $json]);
  25. $this->assertEquals('event', $data['data']['type']);
  26. $this->assertEquals('IndieWeb Summit', $data['data']['name']);
  27. $this->assertEquals('2017-06-24T09:00:00-0700', $data['data']['start']);
  28. $this->assertEquals('2017-06-25T18:00:00-0700', $data['data']['end']);
  29. $this->assertContains('The seventh annual gathering for independent web creators of all kinds,', $data['data']['summary']);
  30. $this->assertEquals('https://facebook.com/332204056925945', $data['data']['location']);
  31. $card = $data['data']['refs'][0];
  32. $this->assertEquals('card', $card['type']);
  33. $this->assertEquals('https://facebook.com/332204056925945', $card['url']);
  34. $this->assertEquals('Mozilla PDX', $card['name']);
  35. $this->assertEquals('97209', $card['postal-code']);
  36. $this->assertEquals('Portland', $card['locality']);
  37. $this->assertEquals('OR', $card['region']);
  38. $this->assertEquals('1120 NW Couch St, Ste 320', $card['street-address']);
  39. $this->assertEquals('United States', $card['country']);
  40. $this->assertEquals('45.5233192', $card['latitude']);
  41. $this->assertEquals('-122.6824722', $card['longitude']);
  42. }
  43. public function testFacebookEvent() {
  44. $url = 'https://www.facebook.com/events/1596554663924436/';
  45. $json = $this->loadFbObject('1596554663924436');
  46. $data = $this->parse(['url' => $url, 'body' => $json]);
  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. }