From 6b286157e3e4126245ee3fe183382404a7387f45 Mon Sep 17 00:00:00 2001 From: sebsel Date: Sat, 24 Jun 2017 10:17:45 +0200 Subject: [PATCH] based tests on TwitterTest.php --- lib/XRay/Formats/Facebook.php | 1 + tests/FacebookTest.php | 26 ++++++++++--------- ...1596554663924436 => 1596554663924436.json} | 16 ------------ ...9_446197069049722 => 446197069049722.json} | 16 ------------ 4 files changed, 15 insertions(+), 44 deletions(-) rename tests/data/graph.facebook.com/{v2.9_1596554663924436 => 1596554663924436.json} (61%) rename tests/data/graph.facebook.com/{v2.9_446197069049722 => 446197069049722.json} (57%) diff --git a/lib/XRay/Formats/Facebook.php b/lib/XRay/Formats/Facebook.php index fb7daae..330b20e 100644 --- a/lib/XRay/Formats/Facebook.php +++ b/lib/XRay/Formats/Facebook.php @@ -17,6 +17,7 @@ class Facebook extends Format { } public static function parse($fbObject, $url) { + if(is_string($fbObject)) $fbObject = json_decode($fbObject, true); $parts = self::extract_url_parts($url); diff --git a/tests/FacebookTest.php b/tests/FacebookTest.php index 4f07530..002a5b8 100644 --- a/tests/FacebookTest.php +++ b/tests/FacebookTest.php @@ -8,24 +8,28 @@ class FacebookTest extends PHPUnit_Framework_TestCase { 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); + + $result = $this->client->parse($request, $response); + $body = $result->getContent(); + $this->assertEquals(200, $result->getStatusCode()); + return json_decode($body, true); + } + + private function loadFbObject($id) { + return file_get_contents(dirname(__FILE__).'/data/graph.facebook.com/'.$id.'.json'); } public function testFacebookEventWithHCard() { $url = 'https://www.facebook.com/events/446197069049722/'; - $response = $this->parse(['url' => $url]); + $json = $this->loadFbObject('446197069049722'); - $body = $response->getContent(); - $this->assertEquals(200, $response->getStatusCode()); - $data = json_decode($body, true); - $card = $data['data']['refs'][0]; + $data = $this->parse(['url' => $url, 'body' => $json]); $this->assertEquals('event', $data['data']['type']); $this->assertEquals('IndieWeb Summit', $data['data']['name']); @@ -34,6 +38,7 @@ class FacebookTest extends PHPUnit_Framework_TestCase { $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']); + $card = $data['data']['refs'][0]; $this->assertEquals('card', $card['type']); $this->assertEquals('https://facebook.com/332204056925945', $card['url']); $this->assertEquals('Mozilla PDX', $card['name']); @@ -48,12 +53,9 @@ class FacebookTest extends PHPUnit_Framework_TestCase { public function testFacebookEvent() { $url = 'https://www.facebook.com/events/1596554663924436/'; - $response = $this->parse(['url' => $url]); + $json = $this->loadFbObject('1596554663924436'); - $body = $response->getContent(); - $this->assertEquals(200, $response->getStatusCode()); - $data = json_decode($body, true); - $card = $data['data']['refs'][0]; + $data = $this->parse(['url' => $url, 'body' => $json]); $this->assertEquals('event', $data['data']['type']); $this->assertEquals('Homebrew Website Club', $data['data']['name']); diff --git a/tests/data/graph.facebook.com/v2.9_1596554663924436 b/tests/data/graph.facebook.com/1596554663924436.json similarity index 61% rename from tests/data/graph.facebook.com/v2.9_1596554663924436 rename to tests/data/graph.facebook.com/1596554663924436.json index f42dd20..aeb5f61 100644 --- a/tests/data/graph.facebook.com/v2.9_1596554663924436 +++ b/tests/data/graph.facebook.com/1596554663924436.json @@ -1,17 +1 @@ -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"} \ No newline at end of file diff --git a/tests/data/graph.facebook.com/v2.9_446197069049722 b/tests/data/graph.facebook.com/446197069049722.json similarity index 57% rename from tests/data/graph.facebook.com/v2.9_446197069049722 rename to tests/data/graph.facebook.com/446197069049722.json index 2e0d904..7818a4d 100644 --- a/tests/data/graph.facebook.com/v2.9_446197069049722 +++ b/tests/data/graph.facebook.com/446197069049722.json @@ -1,17 +1 @@ -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"} \ No newline at end of file