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');
 }
Exemplo n.º 2
0
 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');
 }