Browse Source

based tests on TwitterTest.php

pull/39/head
sebsel 6 years ago
parent
commit
6b286157e3
4 changed files with 15 additions and 44 deletions
  1. +1
    -0
      lib/XRay/Formats/Facebook.php
  2. +14
    -12
      tests/FacebookTest.php
  3. +0
    -16
      tests/data/graph.facebook.com/1596554663924436.json
  4. +0
    -16
      tests/data/graph.facebook.com/446197069049722.json

+ 1
- 0
lib/XRay/Formats/Facebook.php View File

@ -17,6 +17,7 @@ class Facebook extends Format {
} }
public static function parse($fbObject, $url) { public static function parse($fbObject, $url) {
if(is_string($fbObject)) $fbObject = json_decode($fbObject, true);
$parts = self::extract_url_parts($url); $parts = self::extract_url_parts($url);

+ 14
- 12
tests/FacebookTest.php View File

@ -8,24 +8,28 @@ class FacebookTest extends PHPUnit_Framework_TestCase {
public function setUp() { public function setUp() {
$this->client = new Parse(); $this->client = new Parse();
$this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
$this->client->mc = null; $this->client->mc = null;
} }
private function parse($params) { private function parse($params) {
$request = new Request($params); $request = new Request($params);
$response = new Response(); $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() { public function testFacebookEventWithHCard() {
$url = 'https://www.facebook.com/events/446197069049722/'; $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('event', $data['data']['type']);
$this->assertEquals('IndieWeb Summit', $data['data']['name']); $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->assertContains('The seventh annual gathering for independent web creators of all kinds,', $data['data']['summary']);
$this->assertEquals('https://facebook.com/332204056925945', $data['data']['location']); $this->assertEquals('https://facebook.com/332204056925945', $data['data']['location']);
$card = $data['data']['refs'][0];
$this->assertEquals('card', $card['type']); $this->assertEquals('card', $card['type']);
$this->assertEquals('https://facebook.com/332204056925945', $card['url']); $this->assertEquals('https://facebook.com/332204056925945', $card['url']);
$this->assertEquals('Mozilla PDX', $card['name']); $this->assertEquals('Mozilla PDX', $card['name']);
@ -48,12 +53,9 @@ class FacebookTest extends PHPUnit_Framework_TestCase {
public function testFacebookEvent() { public function testFacebookEvent() {
$url = 'https://www.facebook.com/events/1596554663924436/'; $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('event', $data['data']['type']);
$this->assertEquals('Homebrew Website Club', $data['data']['name']); $this->assertEquals('Homebrew Website Club', $data['data']['name']);

tests/data/graph.facebook.com/v2.9_1596554663924436 → tests/data/graph.facebook.com/1596554663924436.json View File

@ -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"} {"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"}

tests/data/graph.facebook.com/v2.9_446197069049722 → tests/data/graph.facebook.com/446197069049722.json View File

@ -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"} {"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"}

Loading…
Cancel
Save