public function testFetchPostsAndRepliesForProfile1() { $user_dao = new UserMySQLDAO(); $photo_dao = new PhotoMySQLDAO(); $count_history_dao = new CountHistoryMySQLDAO(); $favorite_dao = new FavoritePostMySQLDAO(); $follow_dao = new FollowMySQLDAO(); $ic = new InstagramCrawler($this->profile1_instance, 'fauxaccesstoken', 120); $config = Config::getInstance(); $instagram_crawler_log = $config->getValue('log_location'); // prepare log for reading after fetchPostsAndReplies $log_reader_handle = fopen($instagram_crawler_log, 'r'); fseek($log_reader_handle, 0, SEEK_END); // Fetch all of our mock testing data $ic->fetchPostsAndReplies(); $ic->fetchFollowers(); fflush($this->logger->log); $log_written = stream_get_contents($log_reader_handle); fclose($log_reader_handle); $this->assertFalse(preg_match('/InstagramCrawler::fetchPostsAndReplies,\\d+ \\| 0 Instagram posts found on page 2/', $log_written)); // Check all of our testing data is stored in the database // This picture has 1 reply and no likes $post = $photo_dao->getPhoto('519644594447805677_494785218', 'instagram'); $this->assertEqual($post->post_id, '519644594447805677_494785218'); $this->assertEqual($post->author_user_id, '494785218'); $this->assertEqual($post->author_username, 'snoopdogg'); $this->assertEqual($post->author_fullname, 'Snoop Dogg'); $avatar = 'http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg'; $this->assertEqual($post->author_avatar, $avatar); $this->assertEqual($post->post_text, 'Pwpw katapiesh...'); $this->assertEqual($post->reply_count_cache, 1); $this->assertFalse($post->is_protected); $this->assertEqual($post->favlike_count_cache, 0); $this->assertEqual($post->pub_date, '2013-08-10 20:28:00'); $this->assertEqual($post->network, 'instagram'); $permalink = 'http://instagram.com/p/c2JgFlg2zt/'; $this->assertEqual($post->permalink, $permalink); $this->assertEqual($post->filter, 'Valencia'); $sru = 'http://distilleryimage5.s3.amazonaws.com/5c3132b801fb11e38a2722000a9f1925_7.jpg'; $this->assertEqual($post->standard_resolution_url, $sru); $lru = 'http://distilleryimage5.s3.amazonaws.com/5c3132b801fb11e38a2722000a9f1925_6.jpg'; $this->assertEqual($post->low_resolution_url, $lru); $tnu = 'http://distilleryimage5.s3.amazonaws.com/5c3132b801fb11e38a2722000a9f1925_5.jpg'; $this->assertEqual($post->thumbnail_url, $tnu); // Check the reply was added $post = $photo_dao->getPhoto('519671854563291086', 'instagram'); $this->assertEqual($post->post_id, '519671854563291086'); $this->assertEqual($post->author_user_id, '502993749'); $this->assertEqual($post->author_username, 'ni_ato'); $this->assertEqual($post->author_fullname, 'niki'); $avatar = 'http://images.ak.instagram.com/profiles/anonymousUser.jpg'; $this->assertEqual($post->author_avatar, $avatar); $this->assertEqual($post->post_text, 'Epikinduna paixnidia'); $this->assertFalse($post->is_protected); $this->assertEqual($post->pub_date, '2013-08-10 20:28:00'); $this->assertEqual($post->network, 'instagram'); $this->assertEqual($post->in_reply_to_user_id, '494785218'); $this->assertEqual($post->in_reply_to_post_id, '519644594447805677_494785218'); // Check that the author of the reply was added to the users table $user = $user_dao->getUserByName('ni_ato', 'instagram'); $this->assertTrue(isset($user)); $this->assertEqual($user->username, 'ni_ato'); $this->assertEqual($user->full_name, 'niki'); $this->assertEqual($user->user_id, '502993749'); $this->assertEqual($user->avatar, 'http://images.ak.instagram.com/profiles/anonymousUser.jpg'); // User is private based on relationship data $this->assertTrue($user->is_protected); $this->assertEqual($user->network, 'instagram'); // Check the second photo was added, it has no comments and two likes $post = $photo_dao->getPhoto('519642461157682352_494785218', 'instagram'); $this->assertEqual($post->post_id, '519642461157682352_494785218'); $this->assertEqual($post->author_user_id, '494785218'); $this->assertEqual($post->author_username, 'afokou'); $this->assertEqual($post->author_fullname, 'Aggeliki Fokou'); $avatar = 'http://images.ak.instagram.com/profiles/anonymousUser.jpg'; $this->assertEqual($post->author_avatar, $avatar); $this->assertEqual($post->post_text, 'H diaskedastiki mou arxi ;('); $this->assertEqual($post->reply_count_cache, 0); $this->assertFalse($post->is_protected); $this->assertEqual($post->favlike_count_cache, 2); $this->assertEqual($post->pub_date, '2013-08-10 20:23:00'); $this->assertEqual($post->network, 'instagram'); $permalink = 'http://instagram.com/p/c2JBCzg2yw/'; $this->assertEqual($post->permalink, $permalink); $this->assertEqual($post->filter, 'X-Pro II'); $sru = 'http://distilleryimage8.s3.amazonaws.com/c49be7f401fa11e3bcc122000a1fa49d_7.jpg'; $this->assertEqual($post->standard_resolution_url, $sru); $lru = 'http://distilleryimage8.s3.amazonaws.com/c49be7f401fa11e3bcc122000a1fa49d_6.jpg'; $this->assertEqual($post->low_resolution_url, $lru); $tnu = 'http://distilleryimage8.s3.amazonaws.com/c49be7f401fa11e3bcc122000a1fa49d_5.jpg'; $this->assertEqual($post->thumbnail_url, $tnu); // Check we stored the details of the users who liked our photo (ni_ato was the second person to like it and // we checked he was in the DB above) $user = $user_dao->getUserByName('louk_as', 'instagram'); $this->assertTrue(isset($user)); $this->assertEqual($user->username, 'louk_as'); $this->assertEqual($user->full_name, 'lucas asimo'); $this->assertEqual($user->user_id, '20065178'); $this->assertEqual($user->avatar, 'http://images.ak.instagram.com/profiles/profile_20065178_75sq_1335521050.jpg'); $this->assertFalse($user->is_protected); // Check we stored the number of followers our owner has $number_of_followers = $count_history_dao->getLatestCountByNetworkUserIDAndType('494785218', 'instagram', 'followers'); $this->assertEqual($number_of_followers['count'], 3410); // Also check the relationship is in the follows table $this->assertTrue($follow_dao->followExists('494785218', '6623', 'instagram')); $this->assertTrue($follow_dao->followExists('494785218', '29648', 'instagram')); $this->assertTrue($follow_dao->followExists('494785218', '13096', 'instagram')); // Check we stored the two likes in the favorites table $fav_posts = $favorite_dao->getUsersWhoFavedPost('519642461157682352_494785218', 'instagram', true); $this->assertEqual($fav_posts[0]['user_id'], '20065178'); $this->assertEqual($fav_posts[1]['user_id'], '502993749'); }
public function testGetLatestCountByNetworkUserIDAndType() { $builders[] = FixtureBuilder::build('count_history', array('network_user_id' => 930061, 'network' => 'youtube', 'date' => '2013-04-21 11:52:01', 'count' => 125, 'post_id' => 'Hbfgh48', 'type' => 'views')); $builders[] = FixtureBuilder::build('count_history', array('network_user_id' => 930061, 'network' => 'youtube', 'date' => '2013-04-21 11:51:01', 'count' => 45, 'post_id' => 'Hbfgh48', 'type' => 'views')); $builders[] = FixtureBuilder::build('count_history', array('network_user_id' => 930061, 'network' => 'youtube', 'date' => '2013-04-21 11:50:01', 'count' => 25, 'post_id' => 'Hbfgh48', 'type' => 'views')); $builders[] = FixtureBuilder::build('count_history', array('network_user_id' => 930061, 'network' => 'youtube', 'date' => '2013-04-21 11:49:01', 'count' => 10, 'post_id' => 'Jhgndf7', 'type' => 'views')); $dao = new CountHistoryMySQLDAO(); $result = $dao->getLatestCountByNetworkUserIDAndType(930061, 'youtube', 'views'); // Check we got the correct result back $this->assertEqual($result['network_user_id'], 930061); $this->assertEqual($result['network'], 'youtube'); $this->assertEqual($result['date'], '2013-04-21'); $this->assertEqual($result['count'], 125); $this->assertEqual($result['post_id'], 'Hbfgh48'); $this->assertEqual($result['type'], 'views'); }
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); }