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.

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