Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove hardcoded table prefix in ShortLinkMySQLDAO, closes #1277
  • Loading branch information
ginatrapani committed Mar 20, 2012
1 parent e99dbd8 commit c796b88
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions tests/TestOfShortLinkMySQLDAO.php
Expand Up @@ -78,4 +78,37 @@ public function testSaveClickCount() {
$result = $dao->saveClickCount('http://bit.ly/12', 100);
$this->assertEqual($result, 1);
}

public function testGetRecentClickStats() {
//build posts and links
$counter = 1;
$pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
while ($counter < 14) {
$builders[] = FixtureBuilder::build('posts', array('id'=>$counter, 'post_id'=>$counter,
'author_user_id'=>13, 'author_username'=>'ev', 'author_fullname'=>'Ev Williams',
'author_avatar'=>'avatar.jpg', 'post_text'=>'This is post '.$counter,
'source'=>'web', 'pub_date'=>'2006-01-01 00:'. $pseudo_minute.':00',
'reply_count_cache'=>($counter==10)?0:rand(0, 4), 'is_protected'=>0,
'retweet_count_cache'=>floor($counter/2), 'network'=>'twitter',
'old_retweet_count_cache' => floor($counter/3), 'in_rt_of_user_id' => null,
'in_reply_to_post_id'=>null, 'in_retweet_of_post_id'=>null, 'is_geo_encoded'=>0));

$builders[] = FixtureBuilder::build('links', array('id'=>$counter, 'post_key'=>$counter,
'short_url'=>'http://bit.ly/blah', 'expanded_url'=>'http://expandedurl.com/asfasdfadsf/adsfa'
));

$builders[] = FixtureBuilder::build('links_short', array('id'=>$counter, 'link_id'=>$counter,
'short_url'=>'http://bit.ly/blah'.$counter, 'click_count'=>$counter+2
));
$counter++;
}
$instance = new Instance();
$instance->network_username = 'ev';
$instance->network = 'twitter';
$dao = DAOFactory::getDAO('ShortLinkDAO');
$result = $dao->getRecentClickStats($instance);
$this->assertNotNull($result);
$this->assertIsA($result, 'Array');
$this->assertEqual(sizeof($result), 10);
}
}
2 changes: 1 addition & 1 deletion webapp/_lib/model/class.ShortLinkMySQLDAO.php
Expand Up @@ -69,7 +69,7 @@ public function saveClickCount($short_url, $click_count) {
public function getRecentClickStats(Instance $instance, $limit = 10) {
$q = "SELECT p.post_text, l.expanded_url, ls.short_url, ls.click_count ";
$q .= "FROM #prefix#links_short ls INNER JOIN #prefix#links l ";
$q .= "ON l.id = ls.link_id INNER JOIN tu_posts p ON p.id = l.post_key ";
$q .= "ON l.id = ls.link_id INNER JOIN #prefix#posts p ON p.id = l.post_key ";
$q .= "WHERE p.author_username=:author_username AND p.network=:network ";
$q .= "AND ls.click_count > 0 AND p.in_retweet_of_post_id IS NULL ";
$q .= "GROUP BY short_url ORDER BY p.pub_date DESC LIMIT :limit";
Expand Down

0 comments on commit c796b88

Please sign in to comment.