public function testFetchFavoritesOfInstanceuser() { self::setUpInstanceUserAmygdala(); $this->api->available_api_calls_for_crawler = 3; $this->api->to->setDataPath('webapp/plugins/twitter/tests/testdata/favs_tests/favs_stage1/'); $twitter_crawler = new TwitterCrawler($this->instance, $this->api); $twitter_crawler->fetchInstanceUserInfo(); $twitter_crawler->fetchInstanceFavorites(); // Save instance $instance_dao = DAOFactory::getDAO('TwitterInstanceDAO'); if (isset($twitter_crawler->user)) { $instance_dao->save($this->instance, $twitter_crawler->user->post_count, $this->logger); } $this->instance = $instance_dao->getByUsernameOnNetwork("amygdala", "twitter"); $this->assertEqual($this->instance->owner_favs_in_system, 22); $this->assertEqual($this->instance->last_page_fetched_favorites, 4); $this->assertEqual($this->instance->favorites_profile, 82); $this->logger->logInfo("second round of archiving", __METHOD__ . ',' . __LINE__); $this->api->available_api_calls_for_crawler = 10; $this->api->to->setDataPath('webapp/plugins/twitter/tests/testdata/favs_tests/favs_stage2/'); $twitter_crawler = new TwitterCrawler($this->instance, $this->api); $twitter_crawler->fetchInstanceUserInfo(); $twitter_crawler->fetchInstanceFavorites(); // Save instance if (isset($twitter_crawler->user)) { $instance_dao->save($this->instance, $twitter_crawler->user->post_count, $this->logger); } $this->instance = $instance_dao->getByUsernameOnNetwork("amygdala", "twitter"); $this->assertEqual($this->instance->owner_favs_in_system, 84); $this->assertEqual($this->instance->last_page_fetched_favorites, 1); $this->logger->logInfo("now in maintenance mode", __METHOD__ . ',' . __LINE__); $this->api->available_api_calls_for_crawler = 4; $this->api->to->setDataPath('webapp/plugins/twitter/tests/testdata/favs_tests/favs_stage3/'); $twitter_crawler = new TwitterCrawler($this->instance, $this->api); $twitter_crawler->fetchInstanceUserInfo(); $retval = $twitter_crawler->fetchInstanceFavorites(); // Save instance if (isset($twitter_crawler->user)) { $instance_dao->save($this->instance, $twitter_crawler->user->post_count, $this->logger); } $this->instance = $instance_dao->getByUsernameOnNetwork("amygdala", "twitter"); $this->assertEqual($this->instance->owner_favs_in_system, 87); $this->assertEqual($this->instance->last_page_fetched_favorites, 1); $this->assertEqual($retval, true); // now test case where there are 'extra' favs being reported by twitter, // not findable via the N pages searched back through, with existing pages < N // override a cfg value $this->logger->logInfo("now in maintenance mode, second pass", __METHOD__ . ',' . __LINE__); $this->api->available_api_calls_for_crawler = 10; $this->api->to->setDataPath('webapp/plugins/twitter/tests/testdata/favs_tests/favs_stage5/'); $twitter_crawler = new TwitterCrawler($this->instance, $this->api); $twitter_crawler->fetchInstanceUserInfo(); $retval = $twitter_crawler->fetchInstanceFavorites(); // Save instance if (isset($twitter_crawler->user)) { $instance_dao->save($this->instance, $twitter_crawler->user->post_count, $this->logger); } $this->instance = $instance_dao->getByUsernameOnNetwork("amygdala", "twitter"); $this->assertEqual($this->instance->owner_favs_in_system, 88); $this->assertEqual($this->instance->last_page_fetched_favorites, 1); $this->assertEqual($retval, true); $builder2 = null; //Assert links got saved $post_dao = new PostMySQLDAO(); $post = $post_dao->getPost('25138632577', 'twitter'); $this->assertIsA($post->links[0], "Link"); $this->assertEqual($post->post_text, "Raw RSS feed of independent neuroblogs " . "http://friendfeed.com/neuroghetto Now also listed at scienceblogging.org Yay!"); $this->assertEqual($post->links[0]->url, "http://friendfeed.com/neuroghetto"); $this->assertEqual($post->links[0]->expanded_url, ''); $post = $post_dao->getPost('25598018110', 'twitter'); $this->assertIsA($post->links[0], "Link"); $this->assertEqual($post->post_text, "Wal-mart: People line up at midnight to buy baby formula, waiting for " . "monthly govt checks to hit accounts http://bit.ly/aK5pCQ"); $this->assertEqual($post->links[0]->url, "http://bit.ly/aK5pCQ"); $this->assertEqual($post->links[0]->expanded_url, ''); }
/** * This test checks 'old-style' rt handling and mentions */ public function testAddPostOldStyleRTNoPostID() { list($post, $entities, $user_array) = $this->buildStreamPostArray3(); $dao = new PostMySQLDAO(); $user_dao = new UserMySQLDAO(); $dao->addPostAndAssociatedInfo($post, $entities, $user_array); $post = $dao->getPost('39088041628934144', 'twitter'); $this->assertEqual($post->in_rt_of_user_id, 40025121); $user = $user_dao->getDetails(140955302, 'twitter'); $this->assertEqual($user->username, 'DAaronovitch'); $m_dao = new MentionMySQLDAO(); $mention = $m_dao->getMentionInfoUserID(40025121); $mp = $m_dao->getMentionsForPost('39088041628934144'); $this->assertTrue($mention != null); $this->assertEqual($mention['user_name'], 'RSAMatthew'); $this->assertEqual($mention['count_cache'], 1); $this->assertEqual($mp[0]['author_user_id'], 140955302); }
public function getPhoto($post_id, $network, $is_public = false) { $associated_post = parent::getPost($post_id, $network, $is_public); $photo = self::getPhotoObjectFromAssociatedPostObject($associated_post); return $photo; }
/** * Test setGeoencodedPost */ public function testSetGeoencodedPost() { $dao = new PostMySQLDAO(); $setData = $dao->setGeoencodedPost(131, 1); $post = $dao->getPost(131, 'twitter'); $this->assertEqual($post->is_geo_encoded, 1); $this->assertEqual($post->reply_retweet_distance, 0); $setData = $dao->setGeoencodedPost(131, 1, 'New Delhi', '78', 100); $post = $dao->getPost(131, 'twitter'); $this->assertEqual($post->is_geo_encoded, 1); $this->assertEqual($post->geo, 78); $this->assertEqual($post->location, 'New Delhi'); $this->assertEqual($post->reply_retweet_distance, 100); //Since both of $location and $geodata are not defined, only is_geo_encoded field is updated $setData = $dao->setGeoencodedPost(131, 2, '', 29); $post = $dao->getPost(131, 'twitter'); $this->assertEqual($post->is_geo_encoded, 2); $this->assertEqual($post->geo, '78'); $this->assertEqual($post->location, 'New Delhi'); //Since both of $location and $geodata are not defined, only is_geo_encoded field is updated $setData = $dao->setGeoencodedPost(131, 1, 'Dwarka'); $post = $dao->getPost(131, 'twitter'); $this->assertEqual($post->geo, '78'); $this->assertEqual($post->location, 'New Delhi'); }
public function testPostReplyPaging() { $fbc = new FacebookCrawler($this->instance, 'fauxaccesstoken'); $fbc->fetchPostsAndReplies('133954286636768', true); $post_dao = new PostMySQLDAO(); $post = $post_dao->getPost('144568048938151', 'facebook page'); $this->assertEqual($post->reply_count_cache, 70); }
public function testFetchInstanceUserPosts() { $builders = self::buildData(); $gpc = new GooglePlusCrawler($this->profile1_instance, 'fauxaccesstoken', 10); $gpc->fetchInstanceUserPosts(); $post_dao = new PostMySQLDAO(); $post = $post_dao->getPost('z12is5v4snurihgdl22iiz3pjrnws3lle', 'google+', true); $this->assertIsA($post, 'Post'); $this->assertEqual($post->post_text, 'I've got a date with the G+ API this weekend to make a ThinkUp plugin!'); $this->assertEqual($post->reply_count_cache, 24); $this->assertEqual($post->favlike_count_cache, 159); $this->assertEqual($post->retweet_count_cache, 29); $this->assertIsA($post->links[0], 'Link'); $this->assertEqual($post->links[0]->url, 'http://googleplusplatform.blogspot.com/2011/09/getting-started-on-google-api.html'); $this->assertEqual($post->links[0]->title, 'Getting Started on the Google+ API - Google+ Platform Blog'); $this->assertEqual($post->links[0]->description, 'Official source of information about the Google+ platform'); $this->assertEqual($post->links[0]->image_src, ''); //test reshare with annotation $post = $post_dao->getPost('z12pcfdr2wvyzjfff22iiz3pjrnws3lle', 'google+', true); $this->assertIsA($post, 'Post'); $this->assertEqual($post->post_text, 'Really fun episode this week.'); //test reshare without annotation $post = $post_dao->getPost('z12pxlfjxpujivy3e230t3aqawfoz1qf1', 'google+', true); $this->assertIsA($post, 'Post'); $this->assertEqual($post->post_text, ''); //now crawl on updated data and assert counts and post text get updated in database $gpc->api_accessor->setDataLocation('new_counts/'); $gpc->fetchInstanceUserPosts(); $post = $post_dao->getPost('z12is5v4snurihgdl22iiz3pjrnws3lle', 'google+', true); $this->assertEqual($post->reply_count_cache, 64); $this->assertEqual($post->favlike_count_cache, 199); $this->assertEqual($post->retweet_count_cache, 69); $this->assertEqual($post->post_text, "I've got a date with the G+ API this weekend to make a ThinkUp plugin! Updated: New text here!"); }
public function testUpdatePostText() { $dao = new PostMySQLDAO(); $post = $dao->getPost(10, 'twitter'); $this->assertEqual($post->post_text, "This is post 10"); // bad id $update_cnt = $dao->updatePostText(-99, 'twitter', 'updated post text'); $this->assertEqual($update_cnt, 0); // bad network $update_cnt = $dao->updatePostText(10, 'no-net', 'updated post text'); $this->assertEqual($update_cnt, 0); // good id $update_cnt = $dao->updatePostText(10, 'twitter', 'This is updated post 10'); $this->assertEqual($update_cnt, 1); $post = $dao->getPost(10, 'twitter'); $this->assertEqual($post->post_text, 'This is updated post 10'); }
public function testPaginatedPostLikes() { $fbc = new FacebookCrawler($this->profile5_instance, 'fauxaccesstoken', 10); $fbc->fetchPostsAndReplies('501771984', 'facebook'); $post_dao = new PostMySQLDAO(); $post = $post_dao->getPost('10151734003261985', 'facebook'); $this->assertEqual($post->favlike_count_cache, 27); }
public function testFetchPageStream() { $fbc = new FacebookCrawler($this->instance, 'fauxaccesstoken'); $fbc->fetchPagePostsAndReplies(7568536355); $pd = new PostMySQLDAO(); $post = $pd->getPost('437900891355', 'facebook page'); $this->assertEqual($post->post_text, 'Top 10 iOS Jailbreak Hacks'); $this->assertEqual($post->reply_count_cache, 8); //assert user network is set to Facebook, not Facebook Page $ud = new UserMySQLDAO(); $user = $ud->getUserByName('Matthew Fleisher', 'facebook'); $this->assertEqual($user->full_name, 'Matthew Fleisher'); $this->assertEqual($user->network, 'facebook'); $user = $ud->getUserByName('Matthew Fleisher', 'facebook page'); $this->assertEqual($user, null); }
/** * Test assignParent */ function testAssignParent() { //Add two "parent" posts $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES (550, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is parent post 1', 'web', '2006-03-01 00:01:00', 1, 0);"; PDODAO::$PDO->exec($q); $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES (551, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is parent post 2', 'web', '2006-03-01 00:01:00', 0, 0);"; PDODAO::$PDO->exec($q); //Add a post with the parent post 550 $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache, in_reply_to_post_id) VALUES (552, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is a reply with the wrong parent', 'web', '2006-03-01 00:01:00', 0, 0, 550);"; PDODAO::$PDO->exec($q); $pdao = new PostMySQLDAO(); $post = $pdao->getPost(552); //Assert parent post is 550 $this->assertEqual($post->in_reply_to_post_id, 550); //Change parent post to 551 $pdao->assignParent(551, 552); $child_post = $pdao->getPost(552); //Assert parent post is now 551 $this->assertEqual($child_post->in_reply_to_post_id, 551); //Assert old parent post has one fewer reply total $old_parent = $pdao->getPost(550); $this->assertEqual($old_parent->mention_count_cache, 0); //Assert new parent post has one more reply total $new_parent = $pdao->getPost(551); $this->assertEqual($new_parent->mention_count_cache, 1); }
public function testFetchPostsAndRepliesForPage() { $fbc = new FacebookCrawler($this->page1_instance, 'abc', 10); $fbc->fetchPostsAndReplies(); $post_dao = new PostMySQLDAO(); $post = $post_dao->getPost('10152714332426356', 'facebook page'); $this->assertEqual($post->post_text, 'Looks like a very serene place to work:'); $this->assertFalse($post->is_protected); $this->assertEqual($post->reply_count_cache, 4); //test link with image $this->assertEqual(sizeof($post->links), 1); $this->assertEqual($post->links[0]->url, 'http://lifehac.kr/Jg0mR3E'); $this->assertEqual($post->links[0]->expanded_url, ''); $this->assertEqual($post->links[0]->image_src, 'https://fbexternal-a.akamaihd.net/safe_image.php?d=AQDJyDKV3JDoU0-y&w=130&h=130&url=http%3A%2F%2' . 'Fi.kinja-img.com%2Fgawker-media%2Fimage%2Fupload%2Fs--G2ekOhHZ--%2Fgobnypf78nigkkl7cwpl.png&cfs=1'); $this->assertEqual($post->links[0]->description, 'Today’s featured workspace looks immaculate, with its pristine white walls, simple white desk, and ' . 'wood accents. Those skylights help too.'); //assert user network is set to Facebook, not Facebook Page $ud = new UserMySQLDAO(); $user = $ud->getUserByName('Gregory Robert Dumas', 'facebook'); $this->assertEqual($user->full_name, 'Gregory Robert Dumas'); $this->assertEqual($user->network, 'facebook'); $this->assertTrue($user->is_protected); $user = $ud->getUserByName('Matthew Fleisher', 'facebook page'); $this->assertEqual($user, null); $fav_dao = new FavoritePostMySQLDAO(); $favs = $fav_dao->getUsersWhoFavedPost('10152714332426356', 'facebook page'); $this->assertEqual($favs[0]['user_name'], 'Peter-Sarah Crofton'); $this->assertEqual($favs[0]['user_id'], '25913266'); // Test Facebook paging by confirming post on second "page" was captured $post = $post_dao->getPost('10152712264921356', 'facebook page'); $this->assertNotNull($post); $this->assertEqual($post->author_user_id, '7568536355'); }
public function testFetchInstanceUserVideos() { $builders = self::buildData(); $ytc = new YouTubeCrawler($this->instance, 'at', 20); $ytc->fetchInstanceUserVideos(); $video_dao = new VideoMySQLDAO(); $post_dao = new PostMySQLDAO(); $count_history_dao = new CountHistoryMySQLDAO(); // Check the first video got added $video_one = $video_dao->getVideoByID('H', 'youtube'); $this->assertEqual($video_one->post_text, 'My Slideshow'); $this->assertEqual($video_one->description, 'I created this video with the YouTube Slideshow Creator (http://www.youtube.com/upload)'); $this->assertEqual($video_one->likes, 1); $this->assertEqual($video_one->dislikes, 0); $this->assertEqual($video_one->views, 6); $this->assertEqual($video_one->post_id, 'H'); $this->assertEqual($video_one->is_protected, 0); $this->assertEqual($video_one->favorites_added, 0); $this->assertEqual($video_one->favorites_removed, 0); $this->assertEqual($video_one->shares, 0); $this->assertEqual($video_one->subscribers_gained, 0); $this->assertEqual($video_one->subscribers_lost, 0); $this->assertEqual($video_one->minutes_watched, 4); $this->assertEqual($video_one->average_view_duration, 52); $this->assertEqual($video_one->average_view_percentage, 24.8284); $this->assertEqual($video_one->author_user_id, '113612142759476883204'); $this->assertEqual($video_one->author_username, 'Gina Trapani'); $this->assertEqual($video_one->author_fullname, 'Gina Trapani'); $this->assertEqual($video_one->author_avatar, 'http://www.myavatar.com'); $this->assertEqual($video_one->source, ''); $this->assertEqual($video_one->network, 'youtube'); // Check the all time counts were added correctly $favs_added_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'favorites_added_all_time'); $favs_removed_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'favorites_removed_all_time'); $shares_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'shares_all_time'); $subs_gained_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'subscribers_gained_all_time'); $subs_lost_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'subscribers_lost_all_time'); $mins_watched_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'minutes_watched_all_time'); $avg_view_percent_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'average_view_percentage_all_time'); $avg_view_dur_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'average_view_duration_all_time'); $views_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'views_all_time'); $likes_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'likes_all_time'); $dislikes_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'dislikes_all_time'); $this->assertEqual($favs_added_all_time['count'], 0); $this->assertEqual($favs_removed_all_time['count'], 0); $this->assertEqual($shares_all_time['count'], 0); $this->assertEqual($subs_gained_all_time['count'], 0); $this->assertEqual($subs_lost_all_time['count'], 0); $this->assertEqual($mins_watched_all_time['count'], 4); $this->assertEqual($avg_view_percent_all_time['count'], 25); $this->assertEqual($avg_view_dur_all_time['count'], 52); $this->assertEqual($views_all_time['count'], 6); $this->assertEqual($likes_all_time['count'], 1); $this->assertEqual($dislikes_all_time['count'], 0); // Check the replies to it got added // Basic 1st reply $reply_one = $post_dao->getPost('jm_SGXNfF6AmF20tsHqF_2h_S_fV_0l2DU3AfqjbsNc', 'youtube'); $this->assertEqual($reply_one->post_id, 'jm_SGXNfF6AmF20tsHqF_2h_S_fV_0l2DU3AfqjbsNc'); $this->assertEqual($reply_one->post_text, 'Test comment'); $this->assertEqual($reply_one->author_username, 'Aaron Kalair'); $this->assertEqual($reply_one->author_fullname, 'Aaron Kalair'); $this->assertEqual($reply_one->author_avatar, 'https://lh5.googleusercontent.com/-Z2vFxu2wO6E/AAAAAAAAAAI/AAAAAAAAANQ/Pp0EB7dNKLY/photo.jpg?sz=50'); $this->assertEqual($reply_one->author_user_id, '115383827382290096528'); $this->assertEqual($reply_one->pub_date, '2013-06-05 08:13:43'); $this->assertEqual($reply_one->source, ''); $this->assertEqual($reply_one->is_protected, 0); $this->assertEqual($reply_one->network, 'youtube'); $this->assertEqual($reply_one->in_reply_to_user_id, '113612142759476883204'); $this->assertEqual($reply_one->in_reply_to_post_id, 'H'); // Check we can itterate over replies in a single page $reply_two = $post_dao->getPost('gm_SGXNffMJT58F20tsHqF_2h_S_fV_0l2DU3AfqjbsNc', 'youtube'); $this->assertEqual($reply_two->post_id, 'gm_SGXNffMJT58F20tsHqF_2h_S_fV_0l2DU3AfqjbsNc'); $this->assertEqual($reply_two->post_text, 'yet another comment'); $this->assertEqual($reply_two->author_username, 'Aaron Kalair'); $this->assertEqual($reply_two->author_fullname, 'Aaron Kalair'); $this->assertEqual($reply_two->author_avatar, 'https://lh5.googleusercontent.com/-Z2vFxu2wO6E/AAAAAAAAAAI/AAAAAAAAANQ/Pp0EB7dNKLY/photo.jpg?sz=50'); $this->assertEqual($reply_two->author_user_id, '115383827382290096528'); $this->assertEqual($reply_two->pub_date, '2013-06-15 07:45:11'); $this->assertEqual($reply_two->source, ''); $this->assertEqual($reply_two->is_protected, 0); $this->assertEqual($reply_two->network, 'youtube'); $this->assertEqual($reply_two->in_reply_to_user_id, '113612142759476883204'); $this->assertEqual($reply_two->in_reply_to_post_id, 'H'); // Check we can get a reply from another page $reply_three = $post_dao->getPost('hg_HF75HJSNY38JH_ht5_fh', 'youtube'); $this->assertEqual($reply_three->post_id, 'hg_HF75HJSNY38JH_ht5_fh'); $this->assertEqual($reply_three->post_text, 'A comment on the second page'); $this->assertEqual($reply_three->author_username, 'Aaron Kalair'); $this->assertEqual($reply_three->author_fullname, 'Aaron Kalair'); $this->assertEqual($reply_three->author_avatar, 'https://lh5.googleusercontent.com/-Z2vFxu2wO6E/AAAAAAAAAAI/AAAAAAAAANQ/Pp0EB7dNKLY/photo.jpg?sz=50'); $this->assertEqual($reply_three->author_user_id, '115383827382290096528'); $this->assertEqual($reply_three->pub_date, '2013-06-10 18:14:33'); $this->assertEqual($reply_three->source, ''); $this->assertEqual($reply_three->is_protected, 0); $this->assertEqual($reply_three->network, 'youtube'); $this->assertEqual($reply_three->in_reply_to_user_id, '113612142759476883204'); $this->assertEqual($reply_three->in_reply_to_post_id, 'H'); // Check we can itterate over videos on the same page of replies $video_two = $video_dao->getVideoByID('a', 'youtube'); $this->assertEqual($video_two->post_text, 'Same Page Video'); $this->assertEqual($video_two->description, 'This video is on the same page'); $this->assertEqual($video_two->likes, 10); $this->assertEqual($video_two->dislikes, 110); $this->assertEqual($video_two->views, 50); $this->assertEqual($video_two->post_id, 'a'); $this->assertEqual($video_two->is_protected, 0); $this->assertEqual($video_two->favorites_added, 5); $this->assertEqual($video_two->favorites_removed, 1); $this->assertEqual($video_two->shares, 0); $this->assertEqual($video_two->subscribers_gained, 0); $this->assertEqual($video_two->subscribers_lost, 0); $this->assertEqual($video_two->minutes_watched, 1); $this->assertEqual($video_two->average_view_duration, 2); $this->assertEqual($video_two->average_view_percentage, 24.8284); $this->assertEqual($video_two->author_user_id, '113612142759476883204'); $this->assertEqual($video_two->author_username, 'Gina Trapani'); $this->assertEqual($video_two->author_fullname, 'Gina Trapani'); $this->assertEqual($video_two->author_avatar, 'http://www.myavatar.com'); $this->assertEqual($video_two->source, ''); $this->assertEqual($video_two->network, 'youtube'); // Check the per day counts got added correctly $favs_added = $count_history_dao->getLatestCountByPostIDAndType('a', 'favorites_added'); $favs_removed = $count_history_dao->getLatestCountByPostIDAndType('a', 'favorites_removed'); $shares = $count_history_dao->getLatestCountByPostIDAndType('a', 'shares'); $subs_gained = $count_history_dao->getLatestCountByPostIDAndType('a', 'subscribers_gained'); $subs_lost = $count_history_dao->getLatestCountByPostIDAndType('a', 'subscribers_lost'); $mins_watched = $count_history_dao->getLatestCountByPostIDAndType('a', 'minutes_watched'); $avg_view_percent = $count_history_dao->getLatestCountByPostIDAndType('a', 'average_view_percentage'); $avg_view_dur = $count_history_dao->getLatestCountByPostIDAndType('a', 'average_view_duration'); $views = $count_history_dao->getLatestCountByPostIDAndType('a', 'views'); $likes = $count_history_dao->getLatestCountByPostIDAndType('a', 'likes'); $dislikes = $count_history_dao->getLatestCountByPostIDAndType('a', 'dislikes'); $this->assertEqual($favs_added['count'], 4); $this->assertEqual($favs_removed['count'], 2); $this->assertEqual($shares['count'], 3); $this->assertEqual($subs_gained['count'], 10); $this->assertEqual($subs_lost['count'], 11); $this->assertEqual($mins_watched['count'], 11); $this->assertEqual($avg_view_percent['count'], 14); $this->assertEqual($avg_view_dur['count'], 15); $this->assertEqual($views['count'], 100); $this->assertEqual($likes['count'], 0); $this->assertEqual($dislikes['count'], 0); // Check the all time counts were added correctly $favs_added_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'favorites_added_all_time'); $favs_removed_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'favorites_removed_all_time'); $shares_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'shares_all_time'); $subs_gained_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'subscribers_gained_all_time'); $subs_lost_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'subscribers_lost_all_time'); $mins_watched_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'minutes_watched_all_time'); $avg_view_percent_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'average_view_percentage_all_time'); $avg_view_dur_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'average_view_duration_all_time'); $views_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'views_all_time'); $likes_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'likes_all_time'); $dislikes_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'dislikes_all_time'); $this->assertEqual($favs_added_all_time['count'], 5); $this->assertEqual($favs_removed_all_time['count'], 1); $this->assertEqual($shares_all_time['count'], 0); $this->assertEqual($subs_gained_all_time['count'], 0); $this->assertEqual($subs_lost_all_time['count'], 0); $this->assertEqual($mins_watched_all_time['count'], 1); $this->assertEqual($avg_view_percent_all_time['count'], 25); $this->assertEqual($avg_view_dur_all_time['count'], 2); $this->assertEqual($views_all_time['count'], 50); $this->assertEqual($likes_all_time['count'], 10); $this->assertEqual($dislikes_all_time['count'], 110); // Check we can get a video from the next page of videos $video_three = $video_dao->getVideoByID('g', 'youtube'); $this->assertEqual($video_three->post_text, 'My Slideshow'); $this->assertEqual($video_three->description, 'I created this video with the YouTube Slideshow Creator (http://www.youtube.com/upload)'); $this->assertEqual($video_three->likes, 0); $this->assertEqual($video_three->dislikes, 0); $this->assertEqual($video_three->views, 5); $this->assertEqual($video_three->post_id, 'g'); $this->assertEqual($video_three->is_protected, 0); $this->assertEqual($video_three->favorites_added, 0); $this->assertEqual($video_three->favorites_removed, 0); $this->assertEqual($video_three->shares, 0); $this->assertEqual($video_three->subscribers_gained, 0); $this->assertEqual($video_three->subscribers_lost, 0); $this->assertEqual($video_three->minutes_watched, 0); $this->assertEqual($video_three->average_view_duration, 15); $this->assertEqual($video_three->average_view_percentage, 42.7689); $this->assertEqual($video_three->author_user_id, '113612142759476883204'); $this->assertEqual($video_three->author_username, 'Gina Trapani'); $this->assertEqual($video_three->author_fullname, 'Gina Trapani'); $this->assertEqual($video_three->author_avatar, 'http://www.myavatar.com'); $this->assertEqual($video_three->source, ''); $this->assertEqual($video_three->network, 'youtube'); // Check the all time counts were added correctly $favs_added_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'favorites_added_all_time'); $favs_removed_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'favorites_removed_all_time'); $shares_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'shares_all_time'); $subs_gained_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'subscribers_gained_all_time'); $subs_lost_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'subscribers_lost_all_time'); $mins_watched_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'minutes_watched_all_time'); $avg_view_percent_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'average_view_percentage_all_time'); $avg_view_dur_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'average_view_duration_all_time'); $views_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'views_all_time'); $likes_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'likes_all_time'); $dislikes_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'dislikes_all_time'); $this->assertEqual($favs_added_all_time['count'], 0); $this->assertEqual($favs_removed_all_time['count'], 0); $this->assertEqual($shares_all_time['count'], 0); $this->assertEqual($subs_gained_all_time['count'], 0); $this->assertEqual($subs_lost_all_time['count'], 0); $this->assertEqual($mins_watched_all_time['count'], 0); $this->assertEqual($avg_view_percent_all_time['count'], 43); $this->assertEqual($avg_view_dur_all_time['count'], 15); $this->assertEqual($views_all_time['count'], 5); $this->assertEqual($likes_all_time['count'], 0); $this->assertEqual($dislikes_all_time['count'], 0); }
public function testFetchInstanceUserCheckinsFullArchive() { $builders = self::buildData(); // Tell ThinkUp we haven't loaded old posts yet $this->profile1_instance->is_archive_loaded_posts = false; // Create a new foursquare crawler for this instance with a valid access token $fsc = new FoursquareCrawler($this->profile1_instance, 'secret', 10); // Make a request for this users checkins $fsc->fetchInstanceUserCheckins(); // Get a new post dao $post_dao = new PostMySQLDAO(); // Get a new place DAO $place_dao = new PlaceMySQLDAO(); // Get a new link DAO $link_dao = new LinkMySQLDAO(); // Get the first checkin from the database that the fetchInstanceUserCheckins method should have saved $post = $post_dao->getPost('4efa01068b81ef98d2e9cd0b', 'foursquare', true); // Get the first place information from the database that fetchInstanceUserCheckins method should have saved $place = $place_dao->getPlaceByID('4e22eac31838712abe8186e3'); // Check the post was actually set $this->assertIsA($post, 'Post'); // Check these values were set as blank, as they can't be null but we dont use them $this->assertEqual($post->reply_count_cache, 1); $this->assertEqual($post->favlike_count_cache, 0); $this->assertEqual($post->retweet_count_cache, 0); $this->assertEqual($post->author_follower_count, 0); // Check the source was set $this->assertEqual($post->source, 'foursquare for iPhone'); // Check the username was set $this->assertEqual($post->author_username, '*****@*****.**'); // Check the fullname was set $this->assertEqual($post->author_fullname, 'Bob Cats'); // Check the avatar was set $this->assertEqual($post->author_avatar, 'https://foursquare.com/img/100x100/blank_boy.png'); // Check the author used id was set $this->assertEqual($post->author_user_id, '113612142759476883204'); // Check the publication date was set //$this->assertEqual($post->pub_date, '2011-12-27 17:31:50'); $this->assertEqual($post->pub_date, date('Y-m-d H:i:s', '1325007110')); // Check the checkin was set as public $this->assertFalse($post->is_protected); // Check the place name was set $this->assertEqual($post->place, 'Bedworth Sloughs'); // Check the location was set $this->assertEqual($post->location, 'Bedworth, CV12 0AS'); // Check the place ID was set $this->assertEqual($post->place_id, '4e22eac31838712abe8186e3'); // Check the geo co ordinates were set //$this->assertEqual($post->geo, '52.477241961421,-1.4845029364055'); $this->assertPattern('/52.4772419614/', $post->geo); $this->assertPattern('/-1.4845029364/', $post->geo); // Now check the details about the place were stored in the places table // Check all the fields were returned $this->assertEqual(sizeof($place), 12); // Check the place type was set $this->assertEqual($place['place_type'], 'Field'); // Check the place name was set $this->assertEqual($place['name'], 'Bedworth Sloughs'); // Check the fullname was set $this->assertEqual($place['full_name'], 'Bedworth Sloughs'); // Check the network was set $this->assertEqual($place['network'], 'foursquare'); // Build the map url to check against like this to meet code style guidelines $map_url = "http://maps.googleapis.com/maps/api/staticmap?size=150x150&zoom=15&maptype=roadmap&markers"; $map_url .= "=color:blue%7C" . $post->geo . "&sensor=false"; // Check the map image was set $this->assertEqual($place['map_image'], $map_url); // Check the lat long co ordinates were set $this->assertPattern('/POINT\\(52.4772419614/', $place['longlat']); $this->assertPattern('/ -1.4845029364/', $place['longlat']); // Check the comment for this post was set // Get the comment from the database $comment = $post_dao->getPost('4f4135f9e4b028f640ef42eb', 'foursquare', true); // Check the post was actually set $this->assertIsA($comment, 'Post'); // Check these values were set as blank, as they can't be null but we dont use them $this->assertEqual($comment->reply_count_cache, 0); $this->assertEqual($comment->favlike_count_cache, 0); $this->assertEqual($comment->retweet_count_cache, 0); $this->assertEqual($comment->author_follower_count, 0); $this->assertEqual($comment->source, ''); // Check the username was set $this->assertEqual($comment->author_username, '*****@*****.**'); // Check the fullname was set $this->assertEqual($comment->author_fullname, 'Bob Cats'); // Check the avatar was set $this->assertEqual($comment->author_avatar, 'https://foursquare.com/img/100x100/blank_boy.png'); // Check the author used id was set $this->assertEqual($comment->author_user_id, '113612142759476883204'); // Check the publication date was set //$this->assertEqual($comment->pub_date, '2012-02-19 17:48:41'); $this->assertEqual($comment->pub_date, date('Y-m-d H:i:s', '1329673721')); // Check the checkin was set as public $this->assertFalse($comment->is_protected); // Check the place name was set $this->assertEqual($comment->place, 'Bedworth Sloughs'); // Check the location was set $this->assertEqual($comment->location, 'Bedworth, CV12 0AS'); // Check the place ID was set $this->assertEqual($comment->place_id, '4e22eac31838712abe8186e3'); // Check the geo co ordinates were set //$this->assertEqual($comment->geo, '52.477241961421,-1.4845029364055'); $this->assertPattern('/52.4772419614/', $comment->geo); $this->assertPattern('/-1.484502936/', $comment->geo); // Check the link for this checkin was set // Link string $link_string = 'https://img-s.foursquare.com/pix/noTc5a0afTgqTuLlsi3a33tLR0iUOZaa2hLm7LsNn1Q.jpg'; $link = $link_dao->getLinkByUrl($link_string); // Check the expanded url was set correctly // Expanded URL string $expanded_url = 'https://img-s.foursquare.com/pix/noTc5a0afTgqTuLlsi3a33tLR0iUOZaa2hLm7LsNn1Q.jpg'; $this->assertEqual($link->expanded_url, $expanded_url); // Check the title was set $this->assertEqual($link->title, ' '); // Check the description was set $this->assertEqual($link->description, ' '); // Check the img_src was set // img_src string $img_src = 'https://img-s.foursquare.com/pix/noTc5a0afTgqTuLlsi3a33tLR0iUOZaa2hLm7LsNn1Q.jpg'; $this->assertEqual($link->image_src, $img_src); // Check the caption was set $this->assertEqual($link->caption, ' '); // Check the post key is correct $this->assertEqual($link->post_key, 1); // Check the checkin from the second page of results was inserted correctly // Get the first checkin from the database that the fetchInstanceUserCheckins method should have saved $post = $post_dao->getPost('4efa01068b81ef98d679cd0b', 'foursquare', true); // Get the first place information from the database that fetchInstanceUserCheckins method should have saved $place = $place_dao->getPlaceByID('4e22eac31838712aui8186e3'); // Check the post was actually set $this->assertIsA($post, 'Post'); // Check these values were set as blank, as they can't be null but we dont use them $this->assertEqual($post->reply_count_cache, 0); $this->assertEqual($post->favlike_count_cache, 0); $this->assertEqual($post->retweet_count_cache, 0); $this->assertEqual($post->author_follower_count, 0); // Check the source was set $this->assertEqual($post->source, 'foursquare for iPhone'); // Check the username was set $this->assertEqual($post->author_username, '*****@*****.**'); // Check the fullname was set $this->assertEqual($post->author_fullname, 'Bob Cats'); // Check the avatar was set $this->assertEqual($post->author_avatar, 'https://foursquare.com/img/100x100/blank_boy.png'); // Check the author used id was set $this->assertEqual($post->author_user_id, '113612142759476883204'); // Check the publication date was set //$this->assertEqual($post->pub_date, '2011-12-27 17:31:59'); $this->assertEqual($post->pub_date, date('Y-m-d H:i:s', '1325007119')); // Check the checkin was set as public $this->assertFalse($post->is_protected); // Check the place name was set $this->assertEqual($post->place, 'Empire State Building'); // Check the location was set $this->assertEqual($post->location, 'New York'); // Check the place ID was set $this->assertEqual($post->place_id, '4e22eac31838712aui8186e3'); // Check the geo co ordinates were set //$this->assertEqual($post->geo, '82.476241961421,-6.4845029364055'); $this->assertPattern('/82.4762419614/', $post->geo); $this->assertPattern('/-6.4845029364/', $post->geo); // Now check the details about the place were stored in the places table // Check all the fields were returned $this->assertEqual(sizeof($place), 12); // Check the place type was set $this->assertEqual($place['place_type'], 'Building'); // Check the place name was set $this->assertEqual($place['name'], 'Empire State Building'); // Check the fullname was set $this->assertEqual($place['full_name'], 'Empire State Building'); // Check the network was set $this->assertEqual($place['network'], 'foursquare'); // Check we set the old posts loaded bit $this->assertTrue($this->profile1_instance->is_archive_loaded_posts); }
public function testUpdateFavLikeCount() { $dao = new PostMySQLDAO(); $post = $dao->getPost(10, 'twitter'); $this->assertEqual($post->favlike_count_cache, 0); // bad id $update_cnt = $dao->updateFavLikeCount(-99, 'twitter', 25); $this->assertEqual($update_cnt, 0); // bad network $update_cnt = $dao->updateFavLikeCount(10, 'no-net', 25); $this->assertEqual($update_cnt, 0); // good id $update_cnt = $dao->updateFavLikeCount(10, 'twitter', 25); $this->assertEqual($update_cnt, 1); $post = $dao->getPost(10, 'twitter'); $this->assertEqual($post->favlike_count_cache, 25); }