Пример #1
0
 public function testFetchPostsAndRepliesForPage()
 {
     $fbc = new FacebookCrawler($this->page1_instance, 'fauxaccesstoken', 10);
     $fbc->fetchPostsAndReplies();
     $post_dao = new PostMySQLDAO();
     $post = $post_dao->getPost('437900891355', 'facebook page');
     $this->assertEqual($post->post_text, 'Top 10 iOS Jailbreak Hacks');
     $this->assertFalse($post->is_protected);
     $this->assertEqual($post->reply_count_cache, 8);
     //test link with image
     $this->assertEqual(sizeof($post->links), 1);
     $this->assertEqual($post->links[0]->url, 'http://lifehacker.com/5653429/top-10-ios-jailbreak-hacks');
     $this->assertEqual($post->links[0]->expanded_url, '');
     $this->assertEqual($post->links[0]->image_src, 'http://platform.ak.fbcdn.net/www/app_full_proxy.php?app=45439413586&v=1&size=z&cksum=7de062ac249fe7caef80f66' . 'f49a38818&src=http%3A%2F%2Fcache-02.gawkerassets.com%2Fassets%2Fimages%2F17%2F2010%2F10%2F160x120_jailbreak-' . 'top-10.jpg');
     $this->assertEqual($post->links[0]->description, 'If you purchased an iOS device, you also signed up for its many limitations. Jailbreaking can put you back ' . 'in control. Here are ten great jailbreak hacks to help you customize and better utilize your iOS device...');
     //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');
     $this->assertTrue($user->is_protected);
     $user = $ud->getUserByName('Matthew Fleisher', 'facebook page');
     $this->assertEqual($user, null);
     $fav_dao = new FavoritePostMySQLDAO();
     $favs = $fav_dao->getUsersWhoFavedPost('437894121355', 'facebook page');
     $this->assertEqual($favs[0]['user_name'], 'Tigger Pike');
     $this->assertEqual($favs[0]['user_id'], '641265671');
     // Test Facebook paging by confirming post on second "page" was captured
     $post = $post_dao->getPost('437660146355', 'facebook page');
     $this->assertNotNull($post);
     $this->assertEqual($post->author_user_id, '7568536355');
     // Test FollowerCount is set
     $sql = "SELECT * FROM " . $this->table_prefix . "follower_count WHERE network='facebook page' AND network_user_id='7568536355';";
     $stmt = FollowerCountMySQLDAO::$PDO->query($sql);
     $data = array();
     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         array_push($data, $row);
     }
     $stmt->closeCursor();
     $this->assertEqual($data[0]['count'], 307758);
 }
Пример #2
0
 public function testFetchPageStream()
 {
     $fbc = new FacebookCrawler($this->instance, 'fauxaccesstoken');
     $fbc->fetchPostsAndReplies('7568536355', true);
     $post_dao = new PostMySQLDAO();
     $post = $post_dao->getPost('437900891355', 'facebook page');
     $this->assertEqual($post->post_text, 'Top 10 iOS Jailbreak Hacks');
     $this->assertFalse($post->is_protected);
     $this->assertEqual($post->reply_count_cache, 8);
     //test link with image
     $this->assertNotNull($post->link);
     $this->assertEqual($post->link->url, 'http://lifehacker.com/5653429/top-10-ios-jailbreak-hacks');
     $this->assertEqual($post->link->expanded_url, 'http://lifehacker.com/5653429/top-10-ios-jailbreak-hacks');
     $this->assertEqual($post->link->image_src, 'http://platform.ak.fbcdn.net/www/app_full_proxy.php?app=45439413586&v=1&size=z&cksum=7de062ac249fe7caef80f66' . 'f49a38818&src=http%3A%2F%2Fcache-02.gawkerassets.com%2Fassets%2Fimages%2F17%2F2010%2F10%2F160x120_jailbreak-' . 'top-10.jpg');
     $this->assertEqual($post->link->description, 'If you purchased an iOS device, you also signed up for its many limitations. Jailbreaking can put you back ' . 'in control. Here are ten great jailbreak hacks to help you customize and better utilize your iOS device...');
     //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');
     $this->assertTrue($user->is_protected);
     $user = $ud->getUserByName('Matthew Fleisher', 'facebook page');
     $this->assertEqual($user, null);
     $fav_dao = new FavoritePostMySQLDAO();
     $favs = $fav_dao->getUsersWhoFavedPost('437894121355', 'facebook page');
     $this->assertEqual($favs[0]['user_name'], 'Tigger Pike');
     $this->assertEqual($favs[0]['user_id'], '641265671');
 }
Пример #3
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');
 }
Пример #4
0
 public function testInitializeInstanceUserExpiredToken()
 {
     $gpc = new GooglePlusCrawler($this->profile1_instance, 'faux-expired-access-token', 10);
     $gpc->initializeInstanceUser('ci', 'cs', 'valid_token', 'test_refresh_token', 1);
     $user_dao = new UserMySQLDAO();
     $user = $user_dao->getUserByName('Gina Trapani', 'google+');
     $this->assertTrue(isset($user));
     $this->assertEqual($user->username, 'Gina Trapani');
     $this->assertEqual($user->full_name, 'Gina Trapani');
     $this->assertEqual($user->user_id, '113612142759476883204');
     $this->assertEqual($user->location, "San Diego");
     $this->assertEqual($user->description, 'ThinkUp lead developer, This Week in Google co-host, Todo.txt apps creator, founding editor of Lifehacker');
     $this->assertEqual($user->url, '');
     $this->assertFalse($user->is_protected);
 }
Пример #5
0
    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);
    }
Пример #6
0
 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');
 }
Пример #7
0
 public function testInitializeInstanceUser()
 {
     // Create a new foursquare crawler for this instance with the access token fauxaccesstoken
     $fsc = new FoursquareCrawler($this->profile1_instance, 'secret', 10);
     // Call the initaliseInstanceUser method with this users id and access token
     $fsc->initializeInstanceUser('secret', 1);
     // Get a new user DAO
     $user_dao = new UserMySQLDAO();
     // Get the foursquare users object
     $user = $user_dao->getUserByName('*****@*****.**', 'foursquare');
     // Check that we got something back from the database
     $this->assertTrue(isset($user));
     // Check the username is correct
     $this->assertEqual($user->username, '*****@*****.**');
     // Check the full name is correct
     $this->assertEqual($user->full_name, 'Bob Cats');
     // Check the user ID is correct
     $this->assertEqual($user->user_id, '113612142759476883204');
     // Check the location is correct
     $this->assertEqual($user->location, "Harefield, UK");
     // Check the URL was set correctly
     $this->assertEqual($user->url, 'http://www.foursquare.com/user/113612142759476883204');
     // Check the user isn't protected
     $this->assertFalse($user->is_protected);
 }