예제 #1
0
 public function testInsertPlace()
 {
     $place1 = array('bounding_box' => array('type' => 'Polygon', 'coordinates' => array(array(array(-97.73818308, 30.29930703), array(-97.710741, 30.29930703), array(-97.710741, 30.31480602), array(-97.73818308, 30.31480602)))), 'country_code' => 'US', 'country' => 'United States', 'url' => 'http://api.twitter.com/1/geo/id/1a16a1d70500c27d.json', 'name' => 'Hyde Park', 'place_type' => 'neighborhood', 'attributes' => array(), 'id' => '1a16a1d70500c27d', 'full_name' => 'Hyde Park, Austin', 'point_coords' => array('type' => 'Point', 'coordinates' => array(-97.723366, 30.296095)));
     $place2 = array('bounding_box' => array('type' => 'Polygon', 'coordinates' => array(array(array(-97.73818308, 30.29930703), array(-97.710741, 30.29930703), array(-97.710741, 30.31480602), array(-97.73818308, 30.31480602)))), 'country_code' => 'US', 'country' => 'United States', 'url' => 'http://api.twitter.com/1/geo/id/1a16a1d70500c27d.json', 'name' => 'Hyde Park', 'place_type' => 'neighborhood', 'attributes' => array(), 'id' => '2a16a1d70500c27d', 'full_name' => 'Hyde Park 2, Austin', 'point_coords' => array('type' => 'Point', 'coordinates' => array(-97.723366, 30.296095)));
     $this->dao->insertPlace($place1, 123456, 'twitter');
     $this->dao->insertPlace($place2, 123457, 'twitter');
     $res = $this->dao->getPlaceByID('1a16a1d70500c27d');
     $this->assertEqual(sizeof($res), 10);
     $this->assertEqual($res['place_id'], '1a16a1d70500c27d');
     $this->assertEqual($res['name'], 'Hyde Park');
     $this->assertPattern('/POINT\\(-97.72446/', $res['longlat']);
     $this->assertPattern('/ 30.3070565/', $res['longlat']);
     $this->assertEqual($res['bounding_box'], 'POLYGON((-97.73818308 30.29930703,-97.710741 30.29930703,' . '-97.710741 30.31480602,-97.73818308 30.31480602,-97.73818308 30.29930703))');
     $res = $this->dao->getPlaceByID('2a16a1d70500c27d');
     $this->assertEqual($res['place_id'], '2a16a1d70500c27d');
     $res = $this->dao->getPostPlace(123456);
     $this->assertEqual(sizeof($res), 5);
     $this->assertEqual($res['post_id'], 123456);
     $this->assertEqual($res['place_id'], '1a16a1d70500c27d');
     $this->assertEqual($res['longlat'], 'POINT(-97.723366 30.296095)');
     $res = $this->dao->getPostPlace(123457);
     $this->assertEqual($res['post_id'], 123457);
 }
예제 #2
0
 public function testInsertGenericPlace()
 {
     // Set all possible fields
     $places['id'] = 123;
     $places['place_type'] = "Park";
     $places['name'] = "A Park";
     $places['full_name'] = "The Greatest Park";
     $places['country_code'] = "UK";
     $places['country'] = "United Kingdom";
     $places['icon'] = "http://www.iconlocation.com";
     $places['lat_lng'] = 'POINT(51.514 -0.1167)';
     $places['bounding_box'] = 'POLYGON((-0.213503 51.512805,-0.105303 51.512805,-0.105303 51.572068,' . '-0.213503 51.572068, -0.213503 51.512805)))';
     $places['map_image'] = "http://www.mapimage.com";
     // Insert the place
     $this->dao->insertGenericPlace($places, 1234, 'foursquare');
     // Get the place from the database
     $res = $this->dao->getPlaceByID('123');
     // Check all 12 fields were returned
     $this->assertEqual(sizeof($res), 12);
     // Check the place ID was set correctly
     $this->assertEqual($res['place_id'], '123');
     // Check the type was set correctly
     $this->assertEqual($res['place_type'], 'Park');
     // Check the name was set correctly
     $this->assertEqual($res['name'], 'A Park');
     // Check the fullname was set correctly
     $this->assertEqual($res['full_name'], 'The Greatest Park');
     // Check the country code was set correctly
     $this->assertEqual($res['country_code'], 'UK');
     // Check the country was set correctly
     $this->assertEqual($res['country'], 'United Kingdom');
     // Check the icon was set correctly
     $this->assertEqual($res['icon'], 'http://www.iconlocation.com');
     // Check the point was set correctly
     $this->assertPattern('/POINT\\(51.514/', $res['longlat']);
     $this->assertPattern('/ -0.1167/', $res['longlat']);
     // Check the bounding box was set correctly
     $this->assertEqual($res['bounding_box'], 'POLYGON((-0.213503 51.512805,-0.105303 51.512805,-0.105303 51.572068,' . '-0.213503 51.572068,-0.213503 51.512805))');
     // Check the map image was set correctly
     $this->assertEqual($res['map_image'], 'http://www.mapimage.com');
 }
예제 #3
0
 /**
  * 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);
 }
예제 #4
0
 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);
 }