From 0996ab115a7d4cc0619f405c04343f96c9f87e6a Mon Sep 17 00:00:00 2001 From: Ben Liyanage Date: Wed, 8 Oct 2014 13:46:54 -0400 Subject: [PATCH] initial dev added some mach data for unit testing. Also added some base classes for structuring post creation using different versions of the api --- fbsync/fbsync.php | 2 +- fbsync/object/Facebook.php | 10 ++++ fbsync/object/Facebook_Graph21.php | 41 +++++++++++++ fbsync/tests/fbsync_test.php | 19 +++++- fbsync/tests/fql.txt | 64 ++++++++++++++++++++ fbsync/tests/graph2.1-no-filter.txt | 90 +++++++++++++++++++++++++++++ fbsync/tests/graph2.1.txt | 53 +++++++++++++++++ 7 files changed, 276 insertions(+), 3 deletions(-) create mode 100644 fbsync/object/Facebook.php create mode 100644 fbsync/object/Facebook_Graph21.php create mode 100644 fbsync/tests/fql.txt create mode 100644 fbsync/tests/graph2.1-no-filter.txt create mode 100644 fbsync/tests/graph2.1.txt diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index e78f46b4..8e87cfc5 100644 --- a/fbsync/fbsync.php +++ b/fbsync/fbsync.php @@ -213,7 +213,7 @@ function fbsync_expire($a,$b) { } function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $create_user) { - + //Sanitize Inputs $post->actor_id = number_format($post->actor_id, 0, '', ''); $post->source_id = number_format($post->source_id, 0, '', ''); $post->app_id = number_format($post->app_id, 0, '', ''); diff --git a/fbsync/object/Facebook.php b/fbsync/object/Facebook.php new file mode 100644 index 00000000..8e7598b3 --- /dev/null +++ b/fbsync/object/Facebook.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/fbsync/object/Facebook_Graph21.php b/fbsync/object/Facebook_Graph21.php new file mode 100644 index 00000000..0c459f4f --- /dev/null +++ b/fbsync/object/Facebook_Graph21.php @@ -0,0 +1,41 @@ +post_id) + ); + if(count($r)) + return; + + $postarray = array(); + $postarray['gravity'] = 0; + $postarray['uid'] = $uid; + $postarray['wall'] = 0; + + $postarray['verb'] = ACTIVITY_POST; + $postarray['object-type'] = ACTIVITY_OBJ_NOTE; // default value - is maybe changed later when media is attached + $postarray['network'] = dbesc(NETWORK_FACEBOOK); + + $postarray['uri'] = "fb::".$post->post_id; + $postarray['thr-parent'] = $postarray['uri']; + $postarray['parent-uri'] = $postarray['uri']; + $postarray['plink'] = $post->permalink; + } +} +?> \ No newline at end of file diff --git a/fbsync/tests/fbsync_test.php b/fbsync/tests/fbsync_test.php index 676b74fd..3ae2596e 100644 --- a/fbsync/tests/fbsync_test.php +++ b/fbsync/tests/fbsync_test.php @@ -9,9 +9,24 @@ $d = datetime_convert(); global $db; $db = new dba($db_host, $db_user, $db_pass, $db_data, $install); -$data = fbsync_fetchfeed($a, 1); -var_dump($data); +//Test Data Retrieval +//$data = fbsync_fetchfeed($a, 1); +//var_dump($data); + +//Test Data Processing + +// Test Base Class +require_once("./addon/fbsync/object/Facebook.php"); +$myFBSync = new Facebook(); + +// Test graph 2.1 class +require_once("./addon/fbsync/object/Facebook_Graph21.php"); +$myFBSync = new Facebook_Graph21(); +$uid = 1; +$post = json_decode(readfile("./addon/fbsync/tests/graph2.1.txt")); +$myFBSync->CreatePost($a,$uid,0,0,0,$post,0); + /* https://developers.facebook.com/tools/explorer diff --git a/fbsync/tests/fql.txt b/fbsync/tests/fql.txt new file mode 100644 index 00000000..c3f9b9d1 --- /dev/null +++ b/fbsync/tests/fql.txt @@ -0,0 +1,64 @@ +{ + "data": [ + { + "action_links": null, + "actor_id": "109524391244", + "app_data": [ + ], + "app_id": "2309869772", + "attachment": { + "media": [ + { + "href": "http://www.theverge.com/2014/10/8/6946033/google-put-street-view-camera-on-camels-back-to-tour-desert", + "alt": "", + "type": "link", + "src": "https://fbexternal-a.akamaihd.net/safe_image.php?d=AQC6sIH1Zb6kwIlg&w=158&h=158&url=http%3A%2F%2Fcdn1.vox-cdn.com%2Fuploads%2Fchorus_image%2Fimage%2F41261020%2FScreen_Shot_2014-10-08_at_10.44.15_AM.0.0_cinema_1200.0.png" + } + ], + "name": "Google put its Street View camera on a camel's back to tour the Arabian desert", + "href": "http://www.theverge.com/2014/10/8/6946033/google-put-street-view-camera-on-camels-back-to-tour-desert", + "caption": "www.theverge.com", + "description": "Google's Street View cameras have been carried around on cars, boats, people, and now camels. The company recently set out to capture 360-degree imagery of the Arabian desert, and to \"minimize\"...", + "properties": [ + ], + "icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif" + }, + "attribution": null, + "comment_info": { + "can_comment": true, + "comment_count": 0, + "comment_order": "chronological" + }, + "created_time": 1412784080, + "filter_key": "nf", + "like_info": { + "can_like": true, + "like_count": 0, + "user_likes": false + }, + "message": "", + "message_tags": [ + ], + "parent_post_id": null, + "permalink": "https://www.facebook.com/baltimorenode/posts/10152483187826245", + "place": null, + "post_id": "109524391244_10152483187826245", + "privacy": { + "value": "" + }, + "share_count": 0, + "share_info": { + "can_share": true, + "share_count": 0 + }, + "source_id": "109524391244", + "subscribed": false, + "tagged_ids": [ + ], + "type": 80, + "updated_time": 1412784080, + "with_tags": [ + ] + } + ] +} \ No newline at end of file diff --git a/fbsync/tests/graph2.1-no-filter.txt b/fbsync/tests/graph2.1-no-filter.txt new file mode 100644 index 00000000..96a463d9 --- /dev/null +++ b/fbsync/tests/graph2.1-no-filter.txt @@ -0,0 +1,90 @@ +{ + "data": [ + { + "id": "109524391244_10152483187826245", + "from": { + "category": "Non-profit organization", + "category_list": [ + { + "id": "133436743388217", + "name": "Arts & Entertainment" + }, + { + "id": "139823692748565", + "name": "Computers & Electronics" + }, + { + "id": "292231357479999", + "name": "Robotics" + } + ], + "name": "Baltimore Node", + "id": "109524391244" + }, + "story": "Baltimore Node shared a link.", + "picture": "https://fbexternal-a.akamaihd.net/safe_image.php?d=AQC6sIH1Zb6kwIlg&w=158&h=158&url=http%3A%2F%2Fcdn1.vox-cdn.com%2Fuploads%2Fchorus_image%2Fimage%2F41261020%2FScreen_Shot_2014-10-08_at_10.44.15_AM.0.0_cinema_1200.0.png", + "link": "http://www.theverge.com/2014/10/8/6946033/google-put-street-view-camera-on-camels-back-to-tour-desert", + "name": "Google put its Street View camera on a camel's back to tour the Arabian desert", + "caption": "www.theverge.com", + "description": "Google's Street View cameras have been carried around on cars, boats, people, and now camels. The company recently set out to capture 360-degree imagery of the Arabian desert, and to \"minimize\"...", + "icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif", + "actions": [ + { + "name": "Comment", + "link": "https://www.facebook.com/109524391244/posts/10152483187826245" + }, + { + "name": "Like", + "link": "https://www.facebook.com/109524391244/posts/10152483187826245" + } + ], + "privacy": { + "value": "" + }, + "type": "link", + "status_type": "shared_story", + "application": { + "name": "Links", + "id": "2309869772" + }, + "created_time": "2014-10-08T16:01:20+0000", + "updated_time": "2014-10-08T16:01:20+0000" + }, + { + "id": "146218052067513_801079643248014", + "from": { + "category": "Local business", + "category_list": [ + { + "id": "2500", + "name": "Local Business" + } + ], + "name": "The Loading Dock, Inc.", + "id": "146218052067513" + }, + "message": "Blow In Insulation\n\n$2/ bag\n\nEach bag covers about 10 sf (at 6\" thickness)\n\nInsulation is used but very, very clean.\n\nRoughly 860 sf is available.", + "actions": [ + { + "name": "Comment", + "link": "https://www.facebook.com/146218052067513/posts/801079643248014" + }, + { + "name": "Like", + "link": "https://www.facebook.com/146218052067513/posts/801079643248014" + } + ], + "privacy": { + "value": "" + }, + "type": "status", + "status_type": "mobile_status_update", + "created_time": "2014-10-08T15:56:47+0000", + "updated_time": "2014-10-08T15:56:47+0000" + } + ], + "paging": { + "previous": "https://graph.facebook.com/v2.1/10152271780185899/home?limit=10&since=1412784449", + "next": "https://graph.facebook.com/v2.1/10152271780185899/home?limit=10&until=1412780437" + } +} \ No newline at end of file diff --git a/fbsync/tests/graph2.1.txt b/fbsync/tests/graph2.1.txt new file mode 100644 index 00000000..a8263d59 --- /dev/null +++ b/fbsync/tests/graph2.1.txt @@ -0,0 +1,53 @@ +{ + "data": [ + { + "actions": [ + { + "name": "Comment", + "link": "https://www.facebook.com/109524391244/posts/10152483187826245" + }, + { + "name": "Like", + "link": "https://www.facebook.com/109524391244/posts/10152483187826245" + } + ], + "link": "http://www.theverge.com/2014/10/8/6946033/google-put-street-view-camera-on-camels-back-to-tour-desert", + "id": "109524391244_10152483187826245", + "created_time": "2014-10-08T16:01:20+0000", + "application": { + "name": "Links", + "id": "2309869772" + }, + "updated_time": "2014-10-08T16:01:20+0000", + "description": "Google's Street View cameras have been carried around on cars, boats, people, and now camels. The company recently set out to capture 360-degree imagery of the Arabian desert, and to \"minimize\"...", + "privacy": { + "value": "" + }, + "attachments": { + "data": [ + { + "description": "Google's Street View cameras have been carried around on cars, boats, people, and now camels. The company recently set out to capture 360-degree imagery of the Arabian desert, and to \"minimize\"...", + "media": { + "image": { + "height": 674, + "src": "https://fbexternal-a.akamaihd.net/safe_image.php?d=AQBgDPhjhIZYFbxy&w=720&h=720&url=http%3A%2F%2Fcdn1.vox-cdn.com%2Fuploads%2Fchorus_image%2Fimage%2F41261020%2FScreen_Shot_2014-10-08_at_10.44.15_AM.0.0_cinema_1200.0.png&cfs=1", + "width": 674 + } + }, + "target": { + "id": "10152483187826245", + "url": "http://www.facebook.com/l.php?u=http%3A%2F%2Fwww.theverge.com%2F2014%2F10%2F8%2F6946033%2Fgoogle-put-street-view-camera-on-camels-back-to-tour-desert&h=XAQGWkIO2&s=1&enc=AZNOhgg2O7yFa63a0PeP8UE1EdJLbSArpD1HntdBft53llpu9kK38pKnp5svQCc6B355x1mgDXK3fD6dZfqIm29e" + }, + "title": "Google put its Street View camera on a camel's back to tour the Arabian desert", + "type": "share", + "url": "http://www.facebook.com/l.php?u=http%3A%2F%2Fwww.theverge.com%2F2014%2F10%2F8%2F6946033%2Fgoogle-put-street-view-camera-on-camels-back-to-tour-desert&h=XAQGWkIO2&s=1&enc=AZNOhgg2O7yFa63a0PeP8UE1EdJLbSArpD1HntdBft53llpu9kK38pKnp5svQCc6B355x1mgDXK3fD6dZfqIm29e" + } + ] + } + } + ], + "paging": { + "previous": "https://graph.facebook.com/v2.1/10152271780185899/home?fields=actions,link,id,created_time,application,attachments,updated_time,object_id,with_tags,comments{can_comment,comment_count},likes,message,message_tags,description,parent_id,place,privacy,shares&limit=1&since=1412784080", + "next": "https://graph.facebook.com/v2.1/10152271780185899/home?fields=actions,link,id,created_time,application,attachments,updated_time,object_id,with_tags,comments{can_comment,comment_count},likes,message,message_tags,description,parent_id,place,privacy,shares&limit=1&until=1412784079" + } +} \ No newline at end of file