public function testGetOnThisDayFlashbackPosts() { // Generate the date string for 1 year ago today $year_ago_date = date(date('Y-m-d H:i:s', strtotime("today -1 year"))); // Add a post from a year ago that's not a reply or retweet $post_builder = FixtureBuilder::build('posts', array('post_id' => '148', 'author_user_id' => '20', 'author_username' => 'user1', 'author_fullname' => 'User 1', 'network' => 'foursquare', 'post_text' => 'I just checked in', 'source' => '', 'pub_date' => $year_ago_date, 'location' => 'England', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place' => 'The Park', 'place_id' => '12345a', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'foursquare', 'in_reply_to_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'geo' => '52.477192843264,-1.484333726346')); $post_key = $post_builder->columns['last_insert_id']; // Add a link for this post $link_builder = FixtureBuilder::build('links', array('post_key' => $post_key, 'url' => 'http://bit.ly/blah')); // Add a post from 2 years ago that's not a reply or retweet $two_years_ago_date = date(date('Y-m-d H:i:s', strtotime("today -2 year"))); $post_builder2 = FixtureBuilder::build('posts', array('post_id' => '149', 'author_user_id' => '20', 'author_username' => 'user1', 'author_fullname' => 'User 1', 'network' => 'foursquare', 'post_text' => 'I just checked in', 'source' => '', 'pub_date' => $two_years_ago_date, 'location' => 'England', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place' => 'The Park', 'place_id' => '12345a', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'foursquare', 'in_reply_to_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'geo' => '52.477192843264,-1.484333726346')); $post_key = $post_builder2->columns['last_insert_id']; // Add a link for this post $link_builder2 = FixtureBuilder::build('links', array('post_key' => $post_key, 'url' => 'http://bit.ly/blahb')); // Add a post from today that's not a reply or retweet $today_date = date(date('Y-m-d H:i:s', strtotime("today"))); $post_builder3 = FixtureBuilder::build('posts', array('post_id' => '150', 'author_user_id' => '20', 'author_username' => 'user1', 'author_fullname' => 'User 1', 'network' => 'foursquare', 'post_text' => 'I just checked in', 'source' => '', 'pub_date' => $today_date, 'location' => 'England', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place' => 'The Park', 'place_id' => '12345a', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'foursquare', 'in_reply_to_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'geo' => '52.477192843264,-1.484333726346')); $post_key = $post_builder3->columns['last_insert_id']; // Add a link for this post $link_builder3 = FixtureBuilder::build('links', array('post_key' => $post_key, 'url' => 'http://bit.ly/blahb')); /* Add the place information for future foursquare checkin test (We do it this way due to the fixture builder not being able to handle the MySQL point type // Set all possible fields $place['id'] = '12345a'; $place['place_type'] = "Park"; $place['name'] = "A Park"; $place['full_name'] = "The Greatest Park"; $place['country_code'] = "UK"; $place['country'] = "United Kingdom"; $place['icon'] = "http://www.iconlocation.com"; $place['lat_lng'] = 'POINT(51.514 -0.1167)'; // $place['bounding_box'] = 'POLYGON((-0.213503 51.512805,-0.105303 51.512805,-0.105303 51.572068,'. // '-0.213503 51.572068, -0.213503 51.512805)))'; $place['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), ) ) ); $place['map_image'] = "http://www.mapimage.com"; // Insert the place $place_dao = new PlaceMySQLDAO(); $place_dao->insertPlace($place, '148', 'foursquare'); */ //sleep(1000); // Query the database for last year's post $post_dao = new PostMySQLDAO(); // Get the year to query for $res = $post_dao->getOnThisDayFlashbackPosts(20, 'foursquare'); $this->debug(Utils::varDumpToString($res)); // Check only the 1 checkin we inserted is returned $this->assertEqual(sizeof($res), 2); // Check the author user id was set correctly $this->assertEqual($res[0]->author_user_id, '20'); // Check the username was set correctly $this->assertEqual($res[0]->author_username, 'user1'); // Check the author fullname was set correctly $this->assertEqual($res[0]->author_fullname, 'User 1'); // Check the network was set correctly $this->assertEqual($res[0]->network, 'foursquare'); // Check the post text was set correctly $this->assertEqual($res[0]->post_text, 'I just checked in'); // Check the pub date was set correctly $this->assertEqual($res[0]->pub_date, $two_years_ago_date); // Check the location was set correctly $this->assertEqual($res[0]->location, 'England'); // Check the place was set correctly $this->assertEqual($res[0]->place, 'The Park'); // Check the place id was set correctly $this->assertEqual($res[0]->place_id, '12345a'); // Check the geo co ordinates were set correctly $this->assertEqual($res[0]->geo, '52.477192843264,-1.484333726346'); /* // Check the place id was set correctly $this->assertEqual($res[0]->place_obj->place_id, '12345a'); // Check the place type was set correctly $this->assertEqual($res[0]->place_obj->place_type, 'Park'); // Check the place name was set correctly $this->assertEqual($res[0]->place_obj->name, 'A Park'); // Check the full name was set correctly $this->assertEqual($res[0]->place_obj->full_name, 'The Greatest Park'); // Check the country code was set correctly $this->assertEqual($res[0]->place_obj->country_code, 'UK'); // Check the country was set correctly $this->assertEqual($res[0]->place_obj->country, 'United Kingdom'); // Check the icon was set correctly $this->assertEqual($res[0]->place_obj->icon, 'http://www.iconlocation.com'); // Check the map image was set correctly $this->assertEqual($res[0]->place_obj->map_image, 'http://www.mapimage.com'); */ // Check the link URL was set correctly $this->assertEqual($res[0]->links[0]->url, 'http://bit.ly/blahb'); }
public function testGetOnThisDayFlashbackPostsWithoutPostTextOrPlace() { // Generate the date string for 1 year and 1 day ago today $year_and_day_ago_date = date(date('Y-m-d H:i:s', strtotime("today -1 day", strtotime("today -1 year")))); // Add a post from a year ago that's not a reply or retweet with empty post text and place $post_builder = FixtureBuilder::build('posts', array('post_id' => '150', 'author_user_id' => '20', 'author_username' => 'user1', 'author_fullname' => 'User 1', 'network' => 'foursquare', 'post_text' => '', 'source' => '', 'pub_date' => $year_and_day_ago_date, 'location' => 'England', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place' => '', 'place_id' => '12345a', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'foursquare', 'in_reply_to_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'geo' => '52.477192843264,-1.484333726346')); $post_key = $post_builder->columns['last_insert_id']; // Add a link for this post $link_builder = FixtureBuilder::build('links', array('post_key' => $post_key, 'url' => 'http://bit.ly/blah')); // Add a post from 2 years ago that's not a reply or retweet $two_years_and_day_ago_date = date('Y-m-d H:i:s', strtotime('today -1 day', strtotime("today -2 year"))); $post_builder2 = FixtureBuilder::build('posts', array('post_id' => '151', 'author_user_id' => '20', 'author_username' => 'user1', 'author_fullname' => 'User 1', 'network' => 'foursquare', 'post_text' => 'I just checked in', 'source' => '', 'pub_date' => $two_years_and_day_ago_date, 'location' => 'England', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place' => 'The Park', 'place_id' => '12345a', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'foursquare', 'in_reply_to_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'geo' => '52.477192843264,-1.484333726346')); $post_key = $post_builder2->columns['last_insert_id']; // Add a link for this post $link_builder2 = FixtureBuilder::build('links', array('post_key' => $post_key, 'url' => 'http://bit.ly/blahb')); // Add a post from today that's not a reply or retweet $yesterday_date = date(date('Y-m-d H:i:s', strtotime("today -1 day"))); $post_builder3 = FixtureBuilder::build('posts', array('post_id' => '152', 'author_user_id' => '20', 'author_username' => 'user1', 'author_fullname' => 'User 1', 'network' => 'foursquare', 'post_text' => 'I just checked in', 'source' => '', 'pub_date' => $yesterday_date, 'location' => 'England', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place' => 'The Park', 'place_id' => '12345a', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'foursquare', 'in_reply_to_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'geo' => '52.477192843264,-1.484333726346')); $post_key = $post_builder3->columns['last_insert_id']; // Add a link for this post $link_builder3 = FixtureBuilder::build('links', array('post_key' => $post_key, 'url' => 'http://bit.ly/blahb')); // Add the place information $place['place_id'] = '12345a'; $place['place_type'] = "Park"; $place['name'] = "A Park"; $place['full_name'] = "The Greatest Park"; $place['country_code'] = "UK"; $place['country'] = "United Kingdom"; $place['icon'] = "http://www.iconlocation.com"; $place['network'] = "foursquare"; $place['longlat'] = "GeometryFromText( 'Point(51.514 -0.1167)' )"; $place['bounding_box'] = "PolygonFromText( 'Polygon(-0.213503 51.512805,-0.105303 51.512805," . "-0.105303 51.572068,-0.213503 51.572068, -0.213503 51.512805)')"; $place['map_image'] = "http://www.mapimage.com"; // Insert the place $place_builder = FixtureBuilder::build('places', $place); // Query the database for last year's post $post_dao = new PostMySQLDAO(); // Get the year to query for $res = $post_dao->getOnThisDayFlashbackPosts(20, 'foursquare', $yesterday_date); // Check only the 1 checkin we inserted is returned $this->assertEqual(sizeof($res), 1); // Check the author user id was set correctly $this->assertEqual($res[0]->author_user_id, '20'); // Check the username was set correctly $this->assertEqual($res[0]->author_username, 'user1'); // Check the author fullname was set correctly $this->assertEqual($res[0]->author_fullname, 'User 1'); // Check the network was set correctly $this->assertEqual($res[0]->network, 'foursquare'); // Check the post text was set correctly $this->assertEqual($res[0]->post_text, 'I just checked in'); // Check the pub date was set correctly $this->assertEqual($res[0]->pub_date, $two_years_and_day_ago_date); // Check the location was set correctly $this->assertEqual($res[0]->location, 'England'); // Check the place was set correctly $this->assertEqual($res[0]->place, 'The Park'); // Check the place id was set correctly $this->assertEqual($res[0]->place_id, '12345a'); // Check the geo co ordinates were set correctly $this->assertEqual($res[0]->geo, '52.477192843264,-1.484333726346'); // Check the place id was set correctly $this->assertEqual($res[0]->place_obj->place_id, '12345a'); // Check the place type was set correctly $this->assertEqual($res[0]->place_obj->place_type, 'Park'); // Check the place name was set correctly $this->assertEqual($res[0]->place_obj->name, 'A Park'); // Check the full name was set correctly $this->assertEqual($res[0]->place_obj->full_name, 'The Greatest Park'); // Check the country code was set correctly $this->assertEqual($res[0]->place_obj->country_code, 'UK'); // Check the country was set correctly $this->assertEqual($res[0]->place_obj->country, 'United Kingdom'); // Check the icon was set correctly $this->assertEqual($res[0]->place_obj->icon, 'http://www.iconlocation.com'); // Check the map image was set correctly $this->assertEqual($res[0]->place_obj->map_image, 'http://www.mapimage.com'); // Check the link URL was set correctly $this->assertEqual($res[0]->links[0]->url, 'http://bit.ly/blahb'); }