Skip to content

Commit

Permalink
Adjust TestOfPostAPIController for wider range of MySQL server setups
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani committed Dec 26, 2013
1 parent a2d3c60 commit 3c053c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
17 changes: 10 additions & 7 deletions tests/TestOfPostAPIController.php
Expand Up @@ -35,7 +35,6 @@ class TestOfPostAPIController extends ThinkUpUnitTestCase {

public function setUp() {
parent::setUp();
$config = Config::getInstance();
$this->builders = self::buildData();
}

Expand Down Expand Up @@ -840,9 +839,6 @@ protected static function buildData() {
}

public function testPost() {
$config = Config::getInstance();
$config->setValue('timezone', 'utc');

$_GET['type'] = 'post';
$_GET['post_id'] = '137';
$_GET['network'] = 'twitter';
Expand All @@ -859,13 +855,20 @@ public function testPost() {
$this->assertEqual($output->id, '137', "Incorrect post fetched.");

$this->assertEqual(sizeof($output->coordinates->coordinates), 2,
"Size of coordinates is too big or too small. Is " . sizeof($output->coordinates->coordinates) .
" when it should be 2.");
"Size of coordinates is too big or too small. Is " . sizeof($output->coordinates->coordinates) .
" when it should be 2.");

$this->assertEqual($output->thinkup->is_geo_encoded, 1);
$this->assertEqual($output->coordinates, $output->geo, "Geo and coordinates are meant to be exactly the same.");

$this->assertEqual($output->user->last_updated, '2010-03-02 13:45:55');
//This date is stored in storage as 2010-03-02 08:45:55
/**
* This assertion evaluates differently depending on whether your MySQL server supports
* SET timezone statement in PDODAO::connect function
* $this->assertEqual($output->user->last_updated, '2010-03-02 13:45:55');
*/
$this->assertTrue(strtotime($output->user->last_updated) > strtotime('2010-03-02 00:00:00'));
$this->assertTrue(strtotime($output->user->last_updated) < strtotime('2010-03-03 00:00:00'));

// test trim user
$_GET['trim_user'] = true;
Expand Down
13 changes: 6 additions & 7 deletions webapp/_lib/controller/class.PostAPIController.php
Expand Up @@ -118,7 +118,7 @@ class PostAPIController extends ThinkUpController {
* The keyword to use. No default value. In requests that require hashtag data must be set.
* @var str
*/
public $keyword;
public $keyword;
/**
* A User object set when either the user_id or username variables are set. If you are using User data at any point
* in this class, you should use this object.
Expand All @@ -145,7 +145,7 @@ class PostAPIController extends ThinkUpController {
*
* @var HashtagDAO
*/
private $hashtag_dao;
private $hashtag_dao;
/**
* Constructor
*
Expand Down Expand Up @@ -218,7 +218,7 @@ public function __construct($session_started=false) {
if (isset($_GET['keyword'])) {
$this->keyword = $_GET['keyword'];
}

/*
* END READ IN OF QUERY STRING VARS
*/
Expand Down Expand Up @@ -312,7 +312,7 @@ public function control() {
} else {
$this->user = null;
}

/*
* Use the information gathered from the query string to retrieve a
* Hashtag object. This will be the standard object with which to get
Expand All @@ -323,7 +323,7 @@ public function control() {
} else {
$this->hashtag = null;
}

//Privacy checks
if (substr($this->type, 0, 4)=='user') { //user-related API call
if (is_null($this->user)) {
Expand Down Expand Up @@ -622,7 +622,7 @@ public function control() {
$data = $this->post_dao->getAllRepliesInRange($this->user->user_id, $this->network, $this->count,
$this->from, $this->until, $this->page, $this->order_by, $this->direction, $this->is_public);
break;

/*
* Gets posts that contains a Keyword.
*
Expand Down Expand Up @@ -755,7 +755,6 @@ private function convertPostToTweet($post) {
$post->thinkup->is_geo_encoded = $post->is_geo_encoded;

$user = $this->user_dao->getUserByName($post->author_username, $post->network);

/*
* Occasionally you run into users you haven't fetched yet. Bypass this code if you find one of them.
*/
Expand Down

0 comments on commit 3c053c4

Please sign in to comment.