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); }