Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tests of the added date ranges for some API calls

Tests of API date range calls for: user_mentions, user_questions, user_replies and post_replies.

Following up on your comments from (ThinkUpLLC#1378)

Contains the tests that were not included for the added calls in the previous pull request on 'tests/PostMySQLDAO'.
Code is pretty straightforward and tries to follow existing style.

Please let me know if all is correct.

Thanks!

Powered by Televisi� de Catalunya - SOCIALMEDIA PROJECT - CEN-20101037 - This contribution has been kindly sponsored by the Centro para el Desarrollo Tecnol�gico Industrial within the Programa de Investigaci�n Nacional Espa�ol CENIT. - http://www.cenitsocialmedia.es/
  • Loading branch information...
commit 250ee097e02e9231d9ea4394f2e61a69383655de 1 parent 35e44d2
@danipena authored
Showing with 446 additions and 78 deletions.
  1. +446 −78 tests/TestOfPostMySQLDAO.php
View
524 tests/TestOfPostMySQLDAO.php
@@ -330,6 +330,23 @@ protected function buildData() {
$builders[] = FixtureBuilder::build('links', array('post_key'=>$post_key, 'url'=>'http://alink1.com'));
$builders[] = FixtureBuilder::build('links', array('post_key'=>$post_key, 'url'=>'http://alink2.com'));
+ // Add a foursquare checkin
+ $builders[] = FixtureBuilder::build('posts', array('post_id'=>'147', 'author_user_id'=>'20',
+ 'author_username'=>'user1', 'author_fullname'=>'User 1', 'network'=>'foursquare',
+ 'post_text'=>'I just checked in', 'source'=>'', 'pub_date'=>'2011-02-21 09:50:00', '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' =>'23', 'in_reply_to_post_id' => null,
+ 'geo'=>'52.477192843264,-1.484333726346'));
+
+ $builders[] = FixtureBuilder::build('posts', array('post_id'=>'149', 'author_user_id'=>'21',
+ 'author_username'=>'user1', 'author_fullname'=>'User 1', 'network'=>'foursquare',
+ 'post_text'=>'I just checked in again', 'source'=>'', 'pub_date'=>'2011-02-21 22:00:00', 'location'=>'England',
+ 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place'=>'The Garage', 'place_id'=>'12346',
+ 'reply_count_cache'=>0, 'retweet_count_cache'=>0, 'network'=>'foursquare',
+ 'in_reply_to_user_id' =>'23', 'in_reply_to_post_id' => null,
+ 'geo'=>'52.477192843264,-1.484333726346'));
+
return $builders;
}
@@ -572,31 +589,34 @@ public function testGetMostRetweetedPosts() {
*/
public function testGetAllReplies() {
$dao = new PostMySQLDAO();
- $replies = $dao->getAllReplies(13, 'twitter', 10);
+ $replies = $dao->getAllReplies('13', 'twitter', 10);
$this->assertEqual(sizeof($replies), 1);
$this->assertEqual($replies[0]->post_text, "@ev When will Twitter have a business model?");
// test paging
- $replies = $dao->getAllReplies(13, 'twitter', $count = 1, $page = 1);
+ $replies = $dao->getAllReplies('13', 'twitter', $count = 1, $page = 1);
$this->assertEqual(sizeof($replies), 1);
$this->assertEqual($replies[0]->post_text, "@ev When will Twitter have a business model?");
// this query doesn't have a second page, so this should return nothing
- $replies = $dao->getAllReplies(13, 'twitter', $count = 1, $page = 2);
+ $replies = $dao->getAllReplies('13', 'twitter', $count = 1, $page = 2);
$this->assertEqual(sizeof($replies), 0);
// test count
- $replies = $dao->getAllReplies(13, 'twitter', $count = 0, $page = 1);
+ $replies = $dao->getAllReplies('13', 'twitter', $count = 0, $page = 1);
$this->assertEqual(sizeof($replies), 0);
- $replies = $dao->getAllReplies(13, 'twitter', $count = 1, $page = 1);
+ $replies = $dao->getAllReplies('13', 'twitter', $count = 1, $page = 1);
$this->assertEqual(sizeof($replies), 1);
- $replies = $dao->getAllReplies(18, 'twitter', 10);
+ $replies = $dao->getAllReplies('18', 'twitter', 10);
+ if (sizeof($replies)>0) {
+ print_r($replies);
+ }
$this->assertEqual(sizeof($replies), 0);
// test default order_by
- $replies = $dao->getAllReplies(13, 'twitter', 10, 1, "';-- SELECT");
+ $replies = $dao->getAllReplies('13', 'twitter', 10, 1, "';-- SELECT");
$this->assertEqual(sizeof($replies), 1);
$this->assertEqual($replies[0]->post_text, "@ev When will Twitter have a business model?");
}
@@ -1646,7 +1666,7 @@ public function testAddPost() {
$vals['is_protected'] = 1;
//add post with insufficient location data
- $this->assertEqual($dao->addPost($vals), 20020);
+ $this->assertEqual($dao->addPost($vals), 20022);
$post = $dao->getPost(2904, 'twitter');
$this->assertEqual($post->post_id, 2904);
$this->assertEqual($post->location, NULL);
@@ -1661,7 +1681,7 @@ public function testAddPost() {
$vals['in_reply_to_post_id']= '';
//test add straight post that doesn't exist
- $this->assertEqual($dao->addPost($vals), 20021);
+ $this->assertEqual($dao->addPost($vals), 20023);
$post = $dao->getPost(250, 'twitter');
$this->assertEqual($post->post_id, 250);
$this->assertEqual($post->author_user_id, 22);
@@ -1691,7 +1711,7 @@ public function testAddPost() {
//test add reply, check cache count
$vals['post_id']=251;
$vals['in_reply_to_post_id']= 129;
- $this->assertEqual($dao->addPost($vals), 20022);
+ $this->assertEqual($dao->addPost($vals), 20024);
$post = $dao->getPost(129, 'twitter');
$this->assertEqual($post->reply_count_cache, 1, "reply count got updated");
@@ -1699,7 +1719,7 @@ public function testAddPost() {
$vals['post_id']=252;
$vals['in_reply_to_post_id']= '';
$vals['in_retweet_of_post_id']= 128;
- $this->assertEqual($dao->addPost($vals), 20023);
+ $this->assertEqual($dao->addPost($vals), 20025);
$post = $dao->getPost(128, 'twitter');
$this->assertEqual($post->old_retweet_count_cache, 1, "old-style retweet count got updated");
$this->assertEqual($post->retweet_count_cache, 0);
@@ -1721,7 +1741,7 @@ public function testAddPostNotProtected() {
$vals['network']= 'twitter';
$vals['is_protected'] = 0;
- $this->assertEqual($dao->addPost($vals), 20020);
+ $this->assertEqual($dao->addPost($vals), 20022);
$post = $dao->getPost(2904, 'twitter');
$this->assertEqual($post->post_id, 2904);
$this->assertEqual($post->location, NULL);
@@ -1746,7 +1766,7 @@ public function testAddPostProtected() {
$vals['network']= 'twitter';
$vals['is_protected'] = 1;
- $this->assertEqual($dao->addPost($vals), 20020);
+ $this->assertEqual($dao->addPost($vals), 20022);
$post = $dao->getPost(2904, 'twitter');
$this->assertEqual($post->post_id, 2904);
$this->assertEqual($post->location, NULL);
@@ -2277,7 +2297,7 @@ public function testCatchOldStyleRT() {
public function testGetPoststoGeoencode() {
$dao = new PostMySQLDAO();
$posts = $dao->getPoststoGeoencode();
- $this->assertEqual(count($posts), 142);
+ $this->assertEqual(count($posts), 144);
$this->assertIsA($posts, "array");
}
@@ -2384,7 +2404,7 @@ public function testUniqueConstraint1() {
*/
public function testUniqueConstraint2() {
$counter = 1002;
- $pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
+ $pseudo_minute = str_pad(($counter-1000), 2, "0", STR_PAD_LEFT);
$source = '<a href="http://twitter.com" rel="nofollow">Tweetie for Mac</a>';
$builders[] = FixtureBuilder::build('posts', array('post_id'=>$counter, 'author_user_id'=>13,
'author_username'=>'ev', 'author_fullname'=>'Ev Williams', 'author_avatar'=>'avatar.jpg',
@@ -2766,7 +2786,8 @@ private function buildStreamPostArray1() {
'joined' => '2010-04-25 05:04:38',
'url' => 'http://www.facebook.com/jacqueline.dey',
'network' => 'twitter',
- 'last_post' => '2011-02-19 22:27:00'
+ 'last_post' => '2011-02-19 22:27:00',
+ 'last_post_id'=>'abc'
)
),
'in_retweet_of_post_id' => '39088587140108288'
@@ -2791,7 +2812,7 @@ private function buildStreamPostArray1() {
'place' => null
);
$user_array = array (
- 'user_id' => 1106501,
+ 'user_id' => '1106501',
'user_name' => 'joanwalsh',
'full_name' => 'Joan Walsh',
'avatar' => 'http://a3.twimg.com/profile_images/1190090715/JW_1_inch_high_normal.png',
@@ -2804,9 +2825,10 @@ private function buildStreamPostArray1() {
'joined' => '2007-03-13 18:38:05',
'url' => 'http://www.salon.com/opinion/walsh/',
'network' => 'twitter',
- 'last_post' => '2011-02-19 22:30:19'
- );
- return array($post, $entities, $user_array);
+ 'last_post' => '2011-02-19 22:30:19',
+ 'last_post_id'=>'abc'
+ );
+ return array($post, $entities, $user_array);
}
/**
@@ -2892,7 +2914,8 @@ private function buildStreamPostArray2() {
'joined' => '2010-10-12 13:12:48',
'url' => 'http://www.therainforestsite.com',
'network' => 'twitter',
- 'last_post' => '2011-02-20 22:28:06'
+ 'last_post' => '2011-02-20 22:28:06',
+ 'last_post_id'=>'abc'
);
return array($post, $entities, $user_array);
}
@@ -2942,7 +2965,7 @@ private function buildStreamPostArray3() {
'place' => null
);
$user_array = array (
- 'user_id' => 140955302,
+ 'user_id' => '140955302',
'user_name' => 'DAaronovitch',
'full_name' => 'David Aaronovitch',
'avatar' => 'http://a2.twimg.com/profile_images/1145463210/75.manchester_normal.jpg',
@@ -2955,7 +2978,8 @@ private function buildStreamPostArray3() {
'joined' => '2010-05-06 20:12:34',
'url' => 'http://www.davidaaronovitch.com/',
'network' => 'twitter',
- 'last_post' => '2011-02-19 22:24:50'
+ 'last_post' => '2011-02-19 22:24:50',
+ 'last_post_id'=>'abc'
);
return array($post, $entities, $user_array);
}
@@ -3044,12 +3068,12 @@ public function testUpdatePostText() {
$this->assertEqual($post->post_text, 'This is updated post 10');
}
- public function testGetOnThisDayFlashbackPosts(){
+ public function testGetOnThisDayFlashbackPostsNoFromDate(){
// 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',
+ $post_builder = 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'=>$year_ago_date, 'location'=>'England',
'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place'=>'The Park', 'place_id'=>'12345a',
@@ -3063,7 +3087,7 @@ public function testGetOnThisDayFlashbackPosts(){
// 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',
+ $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_ago_date, 'location'=>'England',
'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place'=>'The Park', 'place_id'=>'12345a',
@@ -3078,7 +3102,7 @@ public function testGetOnThisDayFlashbackPosts(){
// 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',
+ $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'=>$today_date, 'location'=>'England',
'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place'=>'The Park', 'place_id'=>'12345a',
@@ -3090,44 +3114,28 @@ public function testGetOnThisDayFlashbackPosts(){
// 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);
+ // 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');
- $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
@@ -3151,26 +3159,386 @@ public function testGetOnThisDayFlashbackPosts(){
// 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 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 testGetOnThisDayFlashbackPostsWithFromDate(){
+ // 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
+ $post_builder = 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'=>$year_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_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), 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_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');
}
+
+ public function testGetAllCheckins(){
+ // Add place information for foursquare checkins
+ $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);
+
+ // Add A link for this checkin
+ $checkin_builder[] = FixtureBuilder::build('links', array('post_key'=>'20020', 'url'=>'http://bit.ly/blah'));
+
+ // Query the database for the checkin and check its returned
+ $post_dao = new PostMySQLDAO();
+ $res = $post_dao->getAllCheckins(20, 'foursquare');
+
+ // Check only the 2 checkins we inserted are 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');
+ // We use relative dates so we need to work out how manys are between the checkin date and the date the test
+ // is run
+
+ $this->assertEqual($res[0]->pub_date, "2011-02-21 09:50:00");
+ // 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 URL was set correctly
+ $this->assertEqual($res[0]->links[0]->url, 'http://bit.ly/blah');
+ }
+
+ public function testCountCheckinsToPlaceTypes(){
+ // Add place information for checkins
+ $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 the number of checkins per type of place
+ $post_dao = new PostMySQLDAO();
+ $res = $post_dao->countCheckinsToPlaceTypes('20', 'foursquare');
+
+ $valid_json = '{"rows":[{"c":[{"v":"Park","f":"Park"},{"v":1}]}],"cols":[{"type":"string","label":"Place Type"';
+ $valid_json .= '},{"type":"number","label":"Number of Checkins to this place type"}]}';
+
+ $this->assertEqual($res, $valid_json);
+ }
+
+ public function testCountCheckinsToPlaceTypesLastWeek(){
+ // Build the pub_date string which needs to be a date within the last week
+ $pub1 = date(date( 'Y-m-d H:i:s' , strtotime("now")));
+ $pub2 = date(date( 'Y-m-d H:i:s' , strtotime("now +1 hour")));
+
+ $hour1 = date('H', strtotime("now") );
+ $hour2 = date('H', strtotime("now +1 hour") );
+
+ // Add some foursquare checkins (done here due to time dependenacy of test)
+ $checkin_builder[] = FixtureBuilder::build('posts', array('post_id'=>'1000', 'author_user_id'=>'31',
+ 'author_username'=>'user1', 'author_fullname'=>'User 1', 'network'=>'foursquare',
+ 'post_text'=>'I just checked in', 'source'=>'', 'pub_date'=>$pub1, 'location'=>'England',
+ 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place'=>'The Park', 'place_id'=>'12345b',
+ 'reply_count_cache'=>0, 'retweet_count_cache'=>0, 'network'=>'foursquare',
+ 'in_reply_to_user_id' =>null, 'in_reply_to_post_id' => null,
+ 'geo'=>'52.477192843264,-1.484333726346'));
+
+ $checkin_builder[] = FixtureBuilder::build('posts', array('post_id'=>'999', 'author_user_id'=>'31',
+ 'author_username'=>'user1', 'author_fullname'=>'User 1', 'network'=>'foursquare',
+ 'post_text'=>'I just checked in again', 'source'=>'', 'pub_date'=>$pub2, 'location'=>'England',
+ 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place'=>'The Garage', 'place_id'=>'12345c',
+ 'reply_count_cache'=>0, 'retweet_count_cache'=>0, 'network'=>'foursquare',
+ 'in_reply_to_user_id' =>null, 'in_reply_to_post_id' => null,
+ 'geo'=>'52.477192843264,-1.484333726346'));
+
+ // Add place information
+ $place1['place_id'] = '12345b';
+ $place1['place_type'] = "Park";
+ $place1['name'] = "A Park";
+ $place1['full_name'] = "The Greatest Park";
+ $place1['country_code'] = "UK";
+ $place1['country'] = "United Kingdom";
+ $place1['icon'] = "http://www.iconlocation.com";
+ $place1['network'] = "foursquare";
+ $place1['longlat'] = "GeometryFromText( 'Point(51.514 -0.1167)' )";
+ $place1['bounding_box'] = "PolygonFromText( 'Polygon(-0.213503 51.512805,-0.105303 51.512805,".
+ "-0.105303 51.572068,-0.213503 51.572068, -0.213503 51.512805)')";
+ $place1['map_image'] = "http://www.mapimage.com";
+
+ // Insert the place
+ $place_builder1 = FixtureBuilder::build('places', $place1);
+
+ // Set all possible fields
+ $place2['place_id'] = '12345c';
+ $place2['place_type'] = "Garage";
+ $place2['network'] = "foursquare";
+ $place2['name'] = "A Garage";
+ $place2['full_name'] = "The Greatest Garage";
+ $place2['country_code'] = "UK";
+ $place2['country'] = "United Kingdom";
+ $place2['icon'] = "http://www.iconlocation.com";
+ $place2['longlat'] = "GeometryFromText( 'Point(51.514 -0.1167)' )";
+ $place2['bounding_box'] = "PolygonFromText( 'Polygon((-0.213503 51.512805,-0.105303 51.512805,".
+ "-0.105303 51.572068,-0.213503 51.572068, -0.213503 51.512805)))')";
+
+ // Insert the place
+ $place_builder2 = FixtureBuilder::build('places', $place2);
+
+ // Query the database for the number of checkins per type of place in the last week
+ $post_dao = new PostMySQLDAO();
+ $res = $post_dao->countCheckinsToPlaceTypes('31', 'foursquare');
+
+ $valid_json = '{"rows":[{"c":[{"v":"Garage","f":"Garage"},{"v":1}]},{"c":[{"v":"Park","f":"Park"},{"v":1}]}],';
+ $valid_json .= '"cols":[{"type":"string","label":"Place Type"},{"type":"number","label":"Number of Checkins to';
+ $valid_json .= ' this place type"}]}';
+
+ $this->assertEqual($res, $valid_json);
+ }
+
+ public function testGetPostsPerHourDataVis(){
+ $pub1 = date(date( 'Y-m-d H:i:s' , strtotime("now")));
+ $pub2 = date(date( 'Y-m-d H:i:s' , strtotime("now +1 hour")));
+
+ $hour1 = date('G', strtotime("now") );
+ $hour2 = date('G', strtotime("now +1 hour") );
+
+ // Add some foursquare checkins (done here due to time dependency of test)
+ $checkin_builder[] = FixtureBuilder::build('posts', array('post_id'=>'998', 'author_user_id'=>'30',
+ 'author_username'=>'user1', 'author_fullname'=>'User 1', 'network'=>'foursquare',
+ 'post_text'=>'I just checked in', 'source'=>'', 'pub_date'=>$pub1, '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,
+ 'geo'=>'52.477192843264,-1.484333726346'));
+
+ $checkin_builder[] = FixtureBuilder::build('posts', array('post_id'=>'999', 'author_user_id'=>'30',
+ 'author_username'=>'user1', 'author_fullname'=>'User 1', 'network'=>'foursquare',
+ 'post_text'=>'I just checked in again', 'source'=>'', 'pub_date'=>$pub2, 'location'=>'England',
+ 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place'=>'The Garage', 'place_id'=>'12346',
+ 'reply_count_cache'=>0, 'retweet_count_cache'=>0, 'network'=>'foursquare',
+ 'in_reply_to_user_id' =>null, 'in_reply_to_post_id' => null,
+ 'geo'=>'52.477192843264,-1.484333726346'));
+
+ // Query the database for the number of checkins per hour
+ $post_dao = new PostMySQLDAO();
+ $result = $post_dao->getPostsPerHourDataVis('30', 'foursquare');
+
+ $valid_json = '{"rows":[';
+ $i = 0;
+ while ($i < 24) {
+ if ( $i == $hour1 || $i == $hour2 ) {
+ $valid_json .= '{"c":[{"v":'.$i.'},{"v":1},{"v":1}]}';
+ } else {
+ $valid_json .= '{"c":[{"v":'.$i.'},{"v":0},{"v":0}]}';
+ }
+ if ($i < 23 ) {
+ $valid_json .= ',';
+ } else {
+ $valid_json .= '],"cols":[{"type":"string","label":"Hour of Day"},{"type":"number","label":'.
+ '"Checkins Last Week"},{"type":"number","label":"Checkins All Time"}]}';
+ }
+ $i++;
+ }
+ $this->assertEqual($result, $valid_json);
+ }
+
+ public function testGetAllCheckinsInLastWeekAsGoogleMap() {
+ // Build the pub_date string which needs to be a date within the last week
+ $pub1 = date(date( 'Y-m-d H:i:s' , strtotime("now")));
+ $pub2 = date(date( 'Y-m-d H:i:s' , strtotime("now +1 hour")));
+
+ $hour1 = date('H', strtotime("now") );
+ $hour2 = date('H', strtotime("now +1 hour") );
+
+ // Add some foursquare checkins (done here due to time dependenacy of test)
+ $checkin_builder[] = FixtureBuilder::build('posts', array('post_id'=>'1001', 'author_user_id'=>'30',
+ 'author_username'=>'user1', 'author_fullname'=>'User 1', 'network'=>'foursquare',
+ 'post_text'=>'I just checked in', 'source'=>'', 'pub_date'=>$pub1, '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,
+ 'geo'=>'52.477192843264,-1.484333726346'));
+
+ $checkin_builder[] = FixtureBuilder::build('posts', array('post_id'=>'1000', 'author_user_id'=>'30',
+ 'author_username'=>'user1', 'author_fullname'=>'User 1', 'network'=>'foursquare',
+ 'post_text'=>'I just checked in again', 'source'=>'', 'pub_date'=>$pub2, 'location'=>'England',
+ 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place'=>'The Garage', 'place_id'=>'12346',
+ 'reply_count_cache'=>0, 'retweet_count_cache'=>0, 'network'=>'foursquare',
+ 'in_reply_to_user_id' =>null, 'in_reply_to_post_id' => null,
+ 'geo'=>'52.477192843264,-1.484333726346'));
+
+ // Query the database for the number of checkins per hour
+ $post_dao = new PostMySQLDAO();
+ $res = $post_dao->GetAllCheckinsInLastWeekAsGoogleMap('30', 'foursquare');
+
+ $valid_url = 'http://maps.googleapis.com/maps/api/staticmap?size=708x500&maptype=roadmap&markers=color:';
+ $valid_url .= 'blue%7C|52.477192843264,-1.484333726346|52.477192843264,-1.484333726346&sensor=false';
+
+ $this->assertEqual($res, $valid_url);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.