Skip to content

Commit

Permalink
Add support for timezone/DST or simple GMT offset to fix date-related…
Browse files Browse the repository at this point in the history
… test failures, closes #1010
  • Loading branch information
ginatrapani committed Mar 21, 2012
1 parent a15b3c5 commit fff2b0e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 23 deletions.
3 changes: 3 additions & 0 deletions tests/TestOfAccountConfigurationController.php
Expand Up @@ -48,6 +48,7 @@ public function setUp(){
$webapp->registerPlugin('twitter', 'TwitterPlugin');
$this->builders = self::buildData();
$_SERVER['HTTP_HOST'] = "mytesthost";
$_SERVER['SERVER_NAME'] = 'dev.thinkup.com';
}

public function tearDown() {
Expand Down Expand Up @@ -655,6 +656,7 @@ public function testAuthControlInviteUser() {
$this->simulateLogin('me@example.com', false, true);

$_SERVER['HTTP_HOST'] = "mytestthinkup";
$_SERVER['SERVER_NAME'] = 'mytestthinkup';
$_SERVER['HTTPS'] = null;
$_POST['invite'] = 'Create Invitation' ;
$_POST['csrf_token'] = parent::CSRF_TOKEN;
Expand All @@ -671,6 +673,7 @@ public function testAuthControlInviteUser() {
//test HTTPS
$_SERVER['HTTPS'] = 1;
$_SERVER['HTTP_HOST'] = "myotherwtestthinkup";
$_SERVER['SERVER_NAME'] = 'myotherwtestthinkup';
$_POST['invite'] = 'Create Invitation' ;

$controller = new AccountConfigurationController(true);
Expand Down
13 changes: 0 additions & 13 deletions tests/TestOfPDODAO.php
Expand Up @@ -63,19 +63,6 @@ protected function buildData() {
return $builders;
}

/*
* Test whether the database supports time zones or only offsets
*/
private function isTimeZoneSupported() {
$testdao = DAOFactory::getDAO('TestDAO');
try {
TestMySQLDAO::$PDO->exec("SET time_zone = 'America/Los_Angeles'");
return true;
} catch (PDOException $e) {
return false;
}
}

public function tearDown() {
$this->builders = null;
parent::tearDown();
Expand Down
6 changes: 5 additions & 1 deletion tests/TestOfPostAPIController.php
Expand Up @@ -765,7 +765,11 @@ public function testPost() {
$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 09:45:55');
if (self::isTimeZoneSupported()) { //account for Daylight Saving Time
$this->assertEqual($output->user->last_updated, '2010-03-02 12:45:55');
} else {
$this->assertEqual($output->user->last_updated, '2010-03-02 13:45:55');
}

// test trim user
$_GET['trim_user'] = true;
Expand Down
20 changes: 14 additions & 6 deletions tests/TestOfPostMySQLDAO.php
Expand Up @@ -827,8 +827,11 @@ public function testGetPostExists() {
$this->assertEqual($post->id, 10);
$this->assertNotNull($post->author);
$this->assertEqual($post->author->username, 'ev');
//TODO: Figure out why this is going in as 13:01 and coming out as 12:01 - DST?
$this->assertEqual($post->author->last_updated, '2005-01-01 12:01:00');
if (self::isTimeZoneSupported()) { //account for Daylight Saving Time
$this->assertEqual($post->author->last_updated, '2005-01-01 12:01:00');
} else {
$this->assertEqual($post->author->last_updated, '2005-01-01 13:01:00');
}

//links
$post = $dao->getPost('40', 'twitter');
Expand Down Expand Up @@ -1886,8 +1889,13 @@ public function testGetMostRepliedToPostsInLastWeek() {
$pdao = new PostMySQLDAO();
$posts = $pdao->getMostRepliedToPostsInLastWeek('user3', 'twitter', 5);
$this->assertEqual(sizeof($posts), 5);
$this->assertEqual($posts[0]->reply_count_cache, 7);
$this->assertEqual($posts[1]->reply_count_cache, 6);
if (self::isTimeZoneSupported()) { //account for Daylight Saving Time
$this->assertEqual($posts[0]->reply_count_cache, 6);
$this->assertEqual($posts[1]->reply_count_cache, 5);
} else {
$this->assertEqual($posts[0]->reply_count_cache, 7);
$this->assertEqual($posts[1]->reply_count_cache, 6);
}

$posts = $pdao->getMostRepliedToPostsInLastWeek('user2', 'twitter', 5);
$this->assertEqual(sizeof($posts), 0);
Expand All @@ -1914,8 +1922,8 @@ public function testGetMostRetweetedPostsInLastWeek() {
$pdao = new PostMySQLDAO();
$posts = $pdao->getMostRetweetedPostsInLastWeek('user3', 'twitter', 5);
$this->assertEqual(sizeof($posts), 5);
$this->assertEqual($posts[0]->retweet_count_cache, 7);
$this->assertEqual($posts[1]->retweet_count_cache, 6);
$this->assertEqual($posts[0]->reply_count_cache, 0);
$this->assertEqual($posts[1]->reply_count_cache, 0);
$this->assertTrue(($posts[0]->retweet_count_cache + $posts[0]->old_retweet_count_cache) >=
($posts[1]->retweet_count_cache + $posts[1]->old_retweet_count_cache));

Expand Down
16 changes: 13 additions & 3 deletions tests/classes/class.ThinkUpUnitTestCase.php
Expand Up @@ -65,7 +65,6 @@ public function setUp() {
$this->table_prefix = $config->getValue('table_prefix');
$this->testdb_helper->create($THINKUP_CFG['source_root_path']."/webapp/install/sql/build-db_mysql.sql");
}

/**
* Drop the database and kill the connection
*/
Expand All @@ -75,7 +74,6 @@ public function tearDown() {
}
parent::tearDown();
}

/**
* Returns an xml/xhtml document element by id
* @param $doc an xml/xhtml document pobject
Expand All @@ -86,7 +84,6 @@ public function getElementById($doc, $id) {
$xpath = new DOMXPath($doc);
return $xpath->query("//*[@id='$id']")->item(0);
}

/**
* Check if we in RAM disk test mode
* @return bool
Expand All @@ -97,4 +94,17 @@ public static function ramDiskTestMode() {
}
return false;
}
/**
* Check if the MySQL server can set its timezone
* @return bool
*/
protected function isTimeZoneSupported() {
$testdao = DAOFactory::getDAO('TestDAO');
try {
TestMySQLDAO::$PDO->exec("SET time_zone = 'UTC'");
return true;
} catch (PDOException $e) {
return false;
}
}
}

0 comments on commit fff2b0e

Please sign in to comment.