Example #1
0
 public function testInsertPlacePointCoordsOnly()
 {
     $place = array('point_coords' => array('type' => 'Point', 'coordinates' => array(-97.723366, 30.296095)));
     $this->dao->insertPlace($place, 123456, 'twitter');
     $res = $this->dao->getPostPlace(123456);
     $this->assertEqual(sizeof($res), 5);
     $this->assertEqual($res['post_id'], 123456);
     $this->assertEqual($res['place_id'], null);
     $this->assertEqual($res['longlat'], 'POINT(-97.723366 30.296095)');
 }
 /**
  * Same as above, but no point coord info
  */
 public function testAddPostAndAssociatedInfoPlaceBBOnly()
 {
     list($post, $entities, $user_array) = $this->buildStreamPostArray2();
     // remove the point coord info-- post data now has just bounding box info
     unset($entities['place']['point_coords']);
     $dao = new PostMySQLDAO();
     $dao->addPostAndAssociatedInfo($post, $entities, $user_array);
     $post = $dao->getPost('39451255650648064', 'twitter');
     $this->assertEqual($post->place_id, '1a16a1d70500c27d');
     $p_dao = new PlaceMySQLDAO();
     $pinfo = $p_dao->getPlaceByID('1a16a1d70500c27d');
     $this->assertEqual($pinfo['bounding_box'], 'POLYGON((-97.73818308 30.29930703,-97.710741 30.29930703,-97.710741 30.31480602,-97.73818308 ' . '30.31480602,-97.73818308 30.29930703))');
     // $this->assertEqual($pinfo['longlat'], 'POINT(-97.72446204 30.307056525)');
     // due to rounding diffs, do 'contains' tests rather than string equality.
     // The result should be approx that of above
     $this->assertPattern('/POINT\\(-97.72446/', $pinfo['longlat']);
     $this->assertPattern('/ 30.3070565/', $pinfo['longlat']);
     $this->assertEqual($pinfo['place_id'], '1a16a1d70500c27d');
     $ploc = $p_dao->getPostPlace('39451255650648064');
     $this->assertEqual($ploc, null);
 }
 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);
 }