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.

69 lines
2.8 KiB

7 years ago
7 years ago
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('event', $data['data']['post-type']);
  27. $this->assertEquals('IndieWeb Summit', $data['data']['name']);
  28. $this->assertEquals('2017-06-24T09:00:00-0700', $data['data']['start']);
  29. $this->assertEquals('2017-06-25T18:00:00-0700', $data['data']['end']);
  30. $this->assertContains('The seventh annual gathering for independent web creators of all kinds,', $data['data']['summary']);
  31. $this->assertEquals('https://facebook.com/332204056925945', $data['data']['location']);
  32. $card = $data['data']['refs'][0];
  33. $this->assertEquals('card', $card['type']);
  34. $this->assertEquals('https://facebook.com/332204056925945', $card['url']);
  35. $this->assertEquals('Mozilla PDX', $card['name']);
  36. $this->assertEquals('97209', $card['postal-code']);
  37. $this->assertEquals('Portland', $card['locality']);
  38. $this->assertEquals('OR', $card['region']);
  39. $this->assertEquals('1120 NW Couch St, Ste 320', $card['street-address']);
  40. $this->assertEquals('United States', $card['country']);
  41. $this->assertEquals('45.5233192', $card['latitude']);
  42. $this->assertEquals('-122.6824722', $card['longitude']);
  43. }
  44. public function testFacebookEvent() {
  45. $url = 'https://www.facebook.com/events/1596554663924436/';
  46. $json = $this->loadFbObject('1596554663924436');
  47. $data = $this->parse(['url' => $url, 'body' => $json]);
  48. $this->assertEquals('event', $data['data']['type']);
  49. $this->assertEquals('event', $data['data']['post-type']);
  50. $this->assertEquals('Homebrew Website Club', $data['data']['name']);
  51. $this->assertEquals('2015-04-22T19:00:00-0400', $data['data']['start']);
  52. $this->assertContains('Are you building your own website? Indie reader?', $data['data']['summary']);
  53. $this->assertEquals('Charging Bull - WeeWork - 25 Broadway, New York, NY 10004', $data['data']['location']);
  54. }
  55. }