public function testProcessTweetInstagramURLs() { //instagr.am $tweet["post_id"] = 105; $tweet['post_text'] = "This is an Instagram post: http://instagr.am/p/oyQ6/ :)"; URLProcessor::processTweetURLs($this->logger, $tweet); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://instagr.am/p/oyQ6/'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://instagr.am/p/oyQ6/'); $this->assertEqual($result->expanded_url, 'http://distillery.s3.amazonaws.com/media/2010/12/20/f0f411210cc54353be07cf74ceb79f3b_7.jpg'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 105); $this->assertEqual($result->network, 'twitter'); $this->assertTrue($result->is_image); // bad instagr.am URL $tweet["post_id"] = 106; $tweet['post_text'] = "This is an Instagram post with a bad URL: http://instagr.am/p/oyQ5/ :("; URLProcessor::processTweetURLs($this->logger, $tweet); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://instagr.am/p/oyQ5/'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://instagr.am/p/oyQ5/'); $this->assertEqual($result->expanded_url, ''); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 106); $this->assertEqual($result->network, 'twitter'); $this->assertFalse($result->is_image); // test regexp extraction of image link from html $api_call = $this->faux_data_path . "/instagr_am_p_oyQ6"; $resp = file_get_contents($api_call); list($eurl, $is_image) = URLProcessor::extractInstagramImageURL($this->logger, $resp); $this->assertEqual($eurl, 'http://distillery.s3.amazonaws.com/media/2010/12/20/f0f411210cc54353be07cf74ceb79f3b_7.jpg'); $this->assertTrue($is_image); }
public function testProcessTweetURLs() { //Twitpic $tweet["post_id"] = 100; $tweet['post_text'] = "This is a Twitpic post http://twitpic.com/blah Yay!"; URLProcessor::processTweetURLs($this->logger, $tweet); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://twitpic.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://twitpic.com/blah'); $this->assertEqual($result->expanded_url, 'http://twitpic.com/show/thumb/blah'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 100); $this->assertEqual($result->network, 'twitter'); $this->assertTrue($result->is_image); //Yfrog $tweet["post_id"] = 101; $tweet['post_text'] = "This is a Yfrog post http://yfrog.com/blah Yay!"; URLProcessor::processTweetURLs($this->logger, $tweet); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://yfrog.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://yfrog.com/blah'); $this->assertEqual($result->expanded_url, 'http://yfrog.com/blah.th.jpg'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 101); $this->assertEqual($result->network, 'twitter'); $this->assertTrue($result->is_image); //Twitgoo $tweet["post_id"] = 102; $tweet['post_text'] = "This is a Twitgoo post http://twitgoo.com/blah Yay!"; URLProcessor::processTweetURLs($this->logger, $tweet); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://twitgoo.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://twitgoo.com/blah'); $this->assertEqual($result->expanded_url, 'http://twitgoo.com/show/thumb/blah'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 102); $this->assertEqual($result->network, 'twitter'); $this->assertTrue($result->is_image); //Picplz $tweet["post_id"] = 103; $tweet['post_text'] = "This is a Picplz post http://picplz.com/blah Yay!"; URLProcessor::processTweetURLs($this->logger, $tweet); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://picplz.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://picplz.com/blah'); $this->assertEqual($result->expanded_url, 'http://picplz.com/blah/thumb/'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 103); $this->assertEqual($result->network, 'twitter'); $this->assertTrue($result->is_image); // instagr.am // check first with ending slash in URL (which the URLs 'should' include) $tweet["post_id"] = 104; $tweet['post_text'] = "This is an instagram post http:/instagr.am/blah/ Yay!"; URLProcessor::processTweetURLs($this->logger, $tweet); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://instagr.am/blah/'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://instagr.am/blah/'); $this->assertEqual($result->expanded_url, 'http://instagr.am/blah/media/'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 104); $this->assertEqual($result->network, 'twitter'); $this->assertTrue($result->is_image); // check w/out ending slash also just in case $tweet["post_id"] = 105; $tweet['post_text'] = "This is an instagram post http:/instagr.am/blah Yay!"; URLProcessor::processTweetURLs($this->logger, $tweet); $result = $link_dao->getLinkByUrl('http://instagr.am/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://instagr.am/blah'); $this->assertEqual($result->expanded_url, 'http://instagr.am/blah/media/'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 105); $this->assertEqual($result->network, 'twitter'); $this->assertTrue($result->is_image); //Flic.kr $tweet["post_id"] = 106; $tweet['post_text'] = "This is a Flickr post http://flic.kr/blah Yay!"; URLProcessor::processTweetURLs($this->logger, $tweet); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://flic.kr/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://flic.kr/blah'); $this->assertEqual($result->expanded_url, ''); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 106); $this->assertEqual($result->network, 'twitter'); $this->assertTrue($result->is_image); }
public function testPlacePolygonPointCoords() { $item = $this->getJSONStringFromFile("place1.json"); $this->json_parser->parseJSON($item); // check post information $post = $this->post_dao->getPost('36573081459757056', 'twitter'); $this->assertEqual($post->post_id, '36573081459757056'); // check places table information $place_array = $this->place_dao->getPlaceByID('f4377e058bd5e6b0'); $this->assertEqual($place_array['bounding_box'], "POLYGON((-97.78447692 30.24380799,-97.75398312 30.24380799,-97.75398312 30.26775771," . "-97.78447692 30.26775771,-97.78447692 30.24380799))"); $this->assertEqual($place_array['place_id'], 'f4377e058bd5e6b0'); // check post_locations table information $post_loc_arr = $this->place_dao->getPostPlace('36573081459757056'); $this->assertEqual($post_loc_arr['post_id'], '36573081459757056'); $this->assertEqual($post_loc_arr['place_id'], 'f4377e058bd5e6b0'); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://twitpic.com/3z50uy'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://twitpic.com/3z50uy'); $this->assertEqual($result->expanded_url, 'http://twitpic.com/3z50uy'); $this->assertEqual($result->image_src, 'http://twitpic.com/show/thumb/3z50uy'); }
public function testProcessPostURLs() { $builders = array(); $network = 'twitter'; //Twitpic $post_id = 100; $post_text = "This is a Twitpic post http://twitpic.com/blah Yay!"; $builders[] = FixtureBuilder::build('posts', array('id' => $post_id, 'post_id' => $post_id, 'network' => 'twitter', 'post_text' => $post_text)); URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://twitpic.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://twitpic.com/blah'); $this->assertEqual($result->expanded_url, 'http://twitpic.com/blah'); $this->assertEqual($result->image_src, 'http://twitpic.com/show/thumb/blah'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_key, 100); //Yfrog $post_id = 101; $post_text = "This is a Yfrog post http://yfrog.com/blah Yay!"; $builders[] = FixtureBuilder::build('posts', array('id' => $post_id, 'post_id' => $post_id, 'network' => 'twitter', 'post_text' => $post_text)); URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://yfrog.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://yfrog.com/blah'); $this->assertEqual($result->expanded_url, 'http://yfrog.com/blah'); $this->assertEqual($result->image_src, 'http://yfrog.com/blah.th.jpg'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_key, 101); //Twitgoo $post_id = 102; $post_text = "This is a Twitgoo post http://twitgoo.com/blah Yay!"; $builders[] = FixtureBuilder::build('posts', array('id' => $post_id, 'post_id' => $post_id, 'network' => 'twitter', 'post_text' => $post_text)); URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://twitgoo.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://twitgoo.com/blah'); $this->assertEqual($result->expanded_url, 'http://twitgoo.com/blah'); $this->assertEqual($result->image_src, 'http://twitgoo.com/show/thumb/blah'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_key, 102); //Picplz $post_id = 103; $post_text = "This is a Picplz post http://picplz.com/blah Yay!"; $builders[] = FixtureBuilder::build('posts', array('id' => $post_id, 'post_id' => $post_id, 'network' => 'twitter', 'post_text' => $post_text)); URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://picplz.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://picplz.com/blah'); $this->assertEqual($result->expanded_url, 'http://picplz.com/blah'); $this->assertEqual($result->image_src, 'http://picplz.com/blah/thumb/'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_key, 103); // instagr.am // check first with ending slash in URL (which the URLs 'should' include) $post_id = 104; $post_text = "This is an instagram post http:/instagr.am/blah/ Yay!"; $builders[] = FixtureBuilder::build('posts', array('id' => $post_id, 'post_id' => $post_id, 'network' => 'twitter', 'post_text' => $post_text)); URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://instagr.am/blah/'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://instagr.am/blah/'); $this->assertEqual($result->expanded_url, 'http://instagr.am/blah/'); $this->assertEqual($result->image_src, 'http://instagr.am/blah/media/'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_key, 104); // check w/out ending slash also just in case $post_id = 105; $post_text = "This is an instagram post http:/instagr.am/blah Yay!"; $builders[] = FixtureBuilder::build('posts', array('id' => $post_id, 'post_id' => $post_id, 'network' => 'twitter', 'post_text' => $post_text)); URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $result = $link_dao->getLinkByUrl('http://instagr.am/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://instagr.am/blah'); $this->assertEqual($result->expanded_url, 'http://instagr.am/blah'); $this->assertEqual($result->image_src, 'http://instagr.am/blah/media/'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_key, 105); //Flic.kr $post_id = 106; $post_text = "This is a Flickr post http://flic.kr/blah Yay!"; $builders[] = FixtureBuilder::build('posts', array('id' => $post_id, 'post_id' => $post_id, 'network' => 'twitter', 'post_text' => $post_text)); URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://flic.kr/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://flic.kr/blah'); //still need to expand the flic.kr link $this->assertEqual($result->expanded_url, ''); $this->assertEqual($result->image_src, ''); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_key, 106); $post_id = 107; $post_text = "This is a post with a curly quote closing the link http://t.co/2JVSpi5 yo"; $builders[] = FixtureBuilder::build('posts', array('id' => $post_id, 'post_id' => $post_id, 'network' => 'twitter', 'post_text' => $post_text)); URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://t.co/2JVSpi5'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://t.co/2JVSpi5'); $this->assertEqual($result->expanded_url, ''); $this->assertEqual($result->image_src, ''); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_key, 107); //Lockerz $post_id = 108; $post_text = "This is a lockerz post http://lockerz.com/s/138376416 Yay!"; $builders[] = FixtureBuilder::build('posts', array('id' => $post_id, 'post_id' => $post_id, 'network' => 'twitter', 'post_text' => $post_text)); URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://lockerz.com/s/138376416'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://lockerz.com/s/138376416'); $this->assertEqual($result->expanded_url, 'http://lockerz.com/s/138376416'); $this->assertEqual($result->image_src, 'http://api.plixi.com/api/tpapi.svc/imagefromurl?url=http://plixi.com/p/138376416&size=thumbnail'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_key, 108); //test facebook $network = 'facebook'; }
public function testAddAndDeleteHashtagSearch() { $this->debug(__METHOD__); //Hashtag does not exist $hashtag_dao = new HashtagMySQLDAO(); $instance_hashtag_dao = new InstanceHashtagMySQLDAO(); $hashtag = $hashtag_dao->getHashtag($_POST['new_hashtag_name'], 'twitter'); $this->assertNull($hashtag); $instance_hashtag = $instance_hashtag_dao->getByInstance(1); $this->assertEqual(sizeof($instance_hashtag), 0); //Add hashtag $this->simulateLogin('*****@*****.**', true, true); $_POST['action'] = 'Save search'; $_POST['new_hashtag_name'] = '#Messi'; $_POST['instance_id'] = 1; $_POST['csrf_token'] = parent::CSRF_TOKEN; $controller = new AccountConfigurationController(true); $results = $controller->go(); $this->debug($results); $hashtag = $hashtag_dao->getHashtag($_POST['new_hashtag_name'], 'twitter'); $this->assertNotNull($hashtag); $this->assertEqual($hashtag->id, 1); $this->assertEqual($hashtag->hashtag, $_POST['new_hashtag_name']); $this->assertEqual($hashtag->network, 'twitter'); $this->assertEqual($hashtag->count_cache, 0); $instance_hashtag = $instance_hashtag_dao->getByInstance(1); $this->assertNotNull($instance_hashtag); $this->assertEqual(sizeof($instance_hashtag), 1); $this->assertEqual($instance_hashtag[0]->instance_id, 1); $this->assertEqual($instance_hashtag[0]->hashtag_id, 1); $this->assertEqual($instance_hashtag[0]->last_post_id, 0); $this->assertEqual($instance_hashtag[0]->earliest_post_id, 0); $v_mgr = $controller->getViewManager(); $success_msgs = $v_mgr->getTemplateDataItem('success_msgs'); $this->assertNotNull($success_msgs); $this->assertEqual($success_msgs['account'], 'Saved search for #Messi.'); $this->assertNull($v_mgr->getTemplateDataItem('error_msg')); //Search tweets //Saved search tweets do not exist $posts_dao = new PostMySQLDAO(); $links_dao = new LinkMySQLDAO(); $users_dao = new UserMySQLDAO(); $hashtagpost_dao = new HashtagPostMySQLDAO(); $hashtags_posts = $hashtagpost_dao->getHashtagsForPost(1, 'twitter'); $this->assertEqual(sizeof($hashtags_posts), 0); $posts = $posts_dao->getAllPostsByHashtagId(1, 'twitter', 20); $this->assertEqual(sizeof($posts), 0); $posts = $posts_dao->getAllPostsByUsername('vetcastellnou', 'twitter'); $this->assertEqual(sizeof($posts), 0); $links = $links_dao->getLinksForPost(1); $this->assertEqual(sizeof($links), 0); $this->assertFalse($users_dao->isUserInDB(100, 'twitter')); $this->assertFalse($users_dao->isUserInDB(101, 'twitter')); $builder = $this->buildSearchData(); //Saved search tweets do exist $hashtags_posts = $hashtagpost_dao->getHashtagsForPost(1, 'twitter'); $this->assertEqual(sizeof($hashtags_posts), 1); $posts = $posts_dao->getAllPostsByHashtagId(1, 'twitter', 20); $this->assertEqual(sizeof($posts), 2); $posts = $posts_dao->getAllPostsByUsername('vetcastellnou', 'twitter'); $this->assertEqual(sizeof($posts), 1); $links = $links_dao->getLinksForPost(1); $this->assertEqual(sizeof($links), 2); $this->assertTrue($users_dao->isUserInDB(100, 'twitter')); $this->assertTrue($users_dao->isUserInDB(101, 'twitter')); //Delete hashtag $new_hashtag_name = $_POST['new_hashtag_name']; unset($_POST['new_hashtag_name']); $_POST['action'] = 'Delete'; $_POST['instance_id'] = 1; $_POST['hashtag_id'] = 1; $_POST['csrf_token'] = parent::CSRF_TOKEN; $controller = new AccountConfigurationController(true); $controller->go(); $hashtags_posts = $hashtagpost_dao->getHashtagsForPost(1, 'twitter'); $this->assertEqual(sizeof($hashtags_posts), 0); $posts = $posts_dao->getAllPostsByHashtagId(1, 'twitter', 20); $this->assertEqual(sizeof($posts), 0); $posts = $posts_dao->getAllPostsByUsername('vetcastellnou', 'twitter'); $this->assertEqual(sizeof($posts), 1); $links = $links_dao->getLinksForPost(1); //Don't delete links $this->assertEqual(sizeof($links), 2); //Don't delete users $this->assertTrue($users_dao->isUserInDB(100, 'twitter')); $this->assertTrue($users_dao->isUserInDB(101, 'twitter')); $hashtag = $hashtag_dao->getHashtag($new_hashtag_name); $this->assertNull($hashtag); $instance_hashtag = $instance_hashtag_dao->getByInstance(1); $this->assertEqual(sizeof($instance_hashtag), 0); $v_mgr = $controller->getViewManager(); $success_msgs = $v_mgr->getTemplateDataItem('success_msgs'); $this->assertNotNull($success_msgs); $this->assertEqual($success_msgs['account'], 'Deleted saved search.'); $this->assertNull($v_mgr->getTemplateDataItem('error_msg')); }
public function testProcessPostURLs() { $network = 'twitter'; //Twitpic $post_id = 100; $post_text = "This is a Twitpic post http://twitpic.com/blah Yay!"; URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://twitpic.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://twitpic.com/blah'); $this->assertEqual($result->expanded_url, 'http://twitpic.com/blah'); $this->assertEqual($result->image_src, 'http://twitpic.com/show/thumb/blah'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 100); $this->assertEqual($result->network, 'twitter'); //Yfrog $post_id = 101; $post_text = "This is a Yfrog post http://yfrog.com/blah Yay!"; URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://yfrog.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://yfrog.com/blah'); $this->assertEqual($result->expanded_url, 'http://yfrog.com/blah'); $this->assertEqual($result->image_src, 'http://yfrog.com/blah.th.jpg'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 101); $this->assertEqual($result->network, 'twitter'); //Twitgoo $post_id = 102; $post_text = "This is a Twitgoo post http://twitgoo.com/blah Yay!"; URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://twitgoo.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://twitgoo.com/blah'); $this->assertEqual($result->expanded_url, 'http://twitgoo.com/blah'); $this->assertEqual($result->image_src, 'http://twitgoo.com/show/thumb/blah'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 102); $this->assertEqual($result->network, 'twitter'); //test facebook $network = 'facebook'; //Picplz $post_id = 103; $post_text = "This is a Picplz post http://picplz.com/blah Yay!"; URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://picplz.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://picplz.com/blah'); $this->assertEqual($result->expanded_url, 'http://picplz.com/blah'); $this->assertEqual($result->image_src, 'http://picplz.com/blah/thumb/'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 103); $this->assertEqual($result->network, 'facebook'); // instagr.am // check first with ending slash in URL (which the URLs 'should' include) $post_id = 104; $post_text = "This is an instagram post http:/instagr.am/blah/ Yay!"; URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://instagr.am/blah/'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://instagr.am/blah/'); $this->assertEqual($result->expanded_url, 'http://instagr.am/blah/'); $this->assertEqual($result->image_src, 'http://instagr.am/blah/media/'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 104); $this->assertEqual($result->network, 'facebook'); // check w/out ending slash also just in case $post_id = 105; $post_text = "This is an instagram post http:/instagr.am/blah Yay!"; URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $result = $link_dao->getLinkByUrl('http://instagr.am/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://instagr.am/blah'); $this->assertEqual($result->expanded_url, 'http://instagr.am/blah'); $this->assertEqual($result->image_src, 'http://instagr.am/blah/media/'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 105); $this->assertEqual($result->network, 'facebook'); //Flic.kr $post_id = 106; $post_text = "This is a Flickr post http://flic.kr/blah Yay!"; URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://flic.kr/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://flic.kr/blah'); //still need to expand the flic.kr link $this->assertEqual($result->expanded_url, ''); $this->assertEqual($result->image_src, ''); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 106); $this->assertEqual($result->network, 'facebook'); $post_id = 107; $post_text = "This is a post with a curly quote closing the link http://t.co/2JVSpi5Ó yo"; URLProcessor::processPostURLs($post_text, $post_id, $network, $this->logger); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://t.co/2JVSpi5'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://t.co/2JVSpi5'); $this->assertEqual($result->expanded_url, ''); $this->assertEqual($result->image_src, ''); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 107); $this->assertEqual($result->network, 'facebook'); }
public function testProcessTweetURLs() { //Twitpic $tweet["post_id"] = 100; $tweet['post_text'] = "This is a Twitpic post http://twitpic.com/blah Yay!"; URLProcessor::processTweetURLs($this->logger, $tweet); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://twitpic.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://twitpic.com/blah'); $this->assertEqual($result->expanded_url, 'http://twitpic.com/show/thumb/blah'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 100); $this->assertEqual($result->network, 'twitter'); $this->assertTrue($result->is_image); //Yfrog $tweet["post_id"] = 101; $tweet['post_text'] = "This is a Yfrog post http://yfrog.com/blah Yay!"; URLProcessor::processTweetURLs($this->logger, $tweet); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://yfrog.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://yfrog.com/blah'); $this->assertEqual($result->expanded_url, 'http://yfrog.com/blah.th.jpg'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 101); $this->assertEqual($result->network, 'twitter'); $this->assertTrue($result->is_image); //Twitgoo $tweet["post_id"] = 102; $tweet['post_text'] = "This is a Twitgoo post http://twitgoo.com/blah Yay!"; URLProcessor::processTweetURLs($this->logger, $tweet); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://twitgoo.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://twitgoo.com/blah'); $this->assertEqual($result->expanded_url, 'http://twitgoo.com/show/thumb/blah'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 102); $this->assertEqual($result->network, 'twitter'); $this->assertTrue($result->is_image); //Picplz $tweet["post_id"] = 103; $tweet['post_text'] = "This is a Picplz post http://picplz.com/blah Yay!"; URLProcessor::processTweetURLs($this->logger, $tweet); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://picplz.com/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://picplz.com/blah'); $this->assertEqual($result->expanded_url, 'http://picplz.com/blah/thumb/'); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 103); $this->assertEqual($result->network, 'twitter'); $this->assertTrue($result->is_image); //Flic.kr $tweet["post_id"] = 104; $tweet['post_text'] = "This is a Flickr post http://flic.kr/blah Yay!"; URLProcessor::processTweetURLs($this->logger, $tweet); $link_dao = new LinkMySQLDAO(); $result = $link_dao->getLinkByUrl('http://flic.kr/blah'); $this->assertIsA($result, "Link"); $this->assertEqual($result->url, 'http://flic.kr/blah'); $this->assertEqual($result->expanded_url, ''); $this->assertEqual($result->title, ''); $this->assertEqual($result->post_id, 104); $this->assertEqual($result->network, 'twitter'); $this->assertTrue($result->is_image); }
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); }