Skip to content

Commit

Permalink
Insights stream
Browse files Browse the repository at this point in the history
Add pluggable Insights Generator plugin
* Create insight baseline model and DAOs that plugin populates
* Abstract all the insights logic into individual "plugin" PHP files
* Set up hooks for the Insight Generator plugin to dynamically call the individual insight plugin files

Bootstrapify insights feed, login/register, web crawl
  • Loading branch information
ginatrapani committed Sep 10, 2012
1 parent 65d99e7 commit 41b8414
Show file tree
Hide file tree
Showing 98 changed files with 10,784 additions and 429 deletions.
18 changes: 9 additions & 9 deletions tests/TestOfAccountConfigurationController.php
Expand Up @@ -349,7 +349,7 @@ public function testAuthControlLoggedInNotAdmin() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 9);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand All @@ -372,7 +372,7 @@ public function testAuthControlLoggedInAdmin() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 9);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -463,7 +463,7 @@ public function testAuthControlLoggedInChangePasswordSuccess() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 9);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -498,7 +498,7 @@ public function testAuthControlLoggedInChangePasswordOldPwdDoesntMatch() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 9);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -527,7 +527,7 @@ public function testAuthControlLoggedInChangePasswordOldPwdEmpty() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 9);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -556,7 +556,7 @@ public function testAuthControlLoggedInChangePasswordNewPwdsDontMatch() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 9);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -586,7 +586,7 @@ public function testAuthControlLoggedInChangePasswordNewPwdTooShort() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 9);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -617,7 +617,7 @@ public function testAuthControlLoggedInChangePasswordNewPwdNotAlphanumeric() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 9);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -698,7 +698,7 @@ public function testResetAPIKey() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 9);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down
91 changes: 83 additions & 8 deletions tests/TestOfFavoritePostMySQLDAO.php
Expand Up @@ -101,10 +101,10 @@ protected function buildData() {
}
$is_protected = $counter == 18 ? 1 : 0; // post with id 18 is protected
$builders[] = FixtureBuilder::build('posts', array('post_id'=>$counter, 'author_user_id'=>13,
'author_username'=>'ev', 'author_fullname'=>'Ev Williams', 'author_avatar'=>'avatar.jpg',
'author_username'=>'ev', 'author_fullname'=>'Ev Williams', 'author_avatar'=>'avatar.jpg',
'post_text'=>'This is post '.$counter, 'source'=>$source, 'pub_date'=>'2006-01-01 00:'.
$pseudo_minute.':00', 'reply_count_cache'=>rand(0, 4), 'retweet_count_cache'=>5, 'network'=>'twitter',
'in_reply_to_post_id'=>null, 'in_retweet_of_post_id'=>null, 'is_geo_encoded'=>0,
'in_reply_to_post_id'=>null, 'in_retweet_of_post_id'=>null, 'is_geo_encoded'=>0,
'is_protected' => $is_protected));
$counter++;
}
Expand All @@ -122,17 +122,17 @@ protected function buildData() {
'is_protected' => $is_protected));

$builders[] = FixtureBuilder::build('links', array('url'=>'http://example.com/'.$counter,
'explanded_url'=>'http://example.com/'.$counter.'.html', 'title'=>'Link $counter', 'clicks'=>0,
'explanded_url'=>'http://example.com/'.$counter.'.html', 'title'=>'Link $counter', 'clicks'=>0,
'post_id'=>$post_id, 'image_src'=>''));

$counter++;
}

$builders[] = FixtureBuilder::build('posts', array('post_id'=>10822735852740608, 'author_user_id'=>23,
'author_username'=>'user3', 'author_fullname'=>'User 3', 'network'=>'twitter',
'author_username'=>'user3', 'author_fullname'=>'User 3', 'network'=>'twitter',
'post_text'=>'@nytimes has posted an interactive panoramic photo that shows how Times Square has changed over'.
' the last 20 years http://nyti.ms/hmTVzP',
'source'=>'web', 'pub_date'=>'-300s', 'reply_count_cache'=>0, 'retweet_count_cache'=>0,
' the last 20 years http://nyti.ms/hmTVzP',
'source'=>'web', 'pub_date'=>'-300s', 'reply_count_cache'=>0, 'retweet_count_cache'=>0,
'location'=>'New York City', 'is_geo_encoded'=>0, 'is_protected' => 0));

// have 'user1' favorite some of ev's posts
Expand Down Expand Up @@ -337,12 +337,87 @@ public function testGetFavdsOfPost() {
$this->assertEqual(count($res), 2);
}

public function testGetFavoritesFromOneYearAgo() {
//build post published one year ago today
$builders[] = FixtureBuilder::build('posts', array('post_id'=>'abadadfd1212', 'author_user_id'=>'19',
'author_username'=>'linkbaiter', 'author_fullname'=>'Link Baiter', 'is_geo_encoded'=>0,
'post_text'=>'This is link post '.$counter, 'source'=>'web', 'pub_date'=>'-366d',
'reply_count_cache'=>0, 'retweet_count_cache'=>0, 'network'=>'twitter',
'is_protected' => 0));

//build favorite of that post by test user ev
$builders[] = FixtureBuilder::build('favorites', array('post_id'=>'abadadfd1212', 'author_user_id'=>'19',
'fav_of_user_id'=>'13', 'network'=>'twitter'));

//get favorites from one year ago today
$result = $this->dao->getFavoritesFromOneYearAgo('13', 'twitter');

//assert post is returned
$this->assertEqual(sizeof($result), 1);
$this->assertEqual($result[0]->post_id, 'abadadfd1212');

//build post published one year and 4 days ago today
$builders[] = FixtureBuilder::build('posts', array('post_id'=>'abadadfd1213', 'author_user_id'=>'19',
'author_username'=>'linkbaiter', 'author_fullname'=>'Link Baiter', 'is_geo_encoded'=>0,
'post_text'=>'This is link post '.$counter, 'source'=>'web', 'pub_date'=>'-370d',
'reply_count_cache'=>0, 'retweet_count_cache'=>0, 'network'=>'twitter',
'is_protected' => 0));

//build favorite of that post by test user ev
$builders[] = FixtureBuilder::build('favorites', array('post_id'=>'abadadfd1213', 'author_user_id'=>'19',
'fav_of_user_id'=>'13', 'network'=>'twitter'));

$since_date = date("Y-m-d", strtotime("-4 day"));
//get favorites from one year ago today
$result = $this->dao->getFavoritesFromOneYearAgo('13', 'twitter', $since_date);

//assert post is returned
$this->assertEqual(sizeof($result), 1);
$this->assertEqual($result[0]->post_id, 'abadadfd1213');
}

public function testGetUsersWhoFavoritedMostOfYourPosts() {
//build post published 3 days ago
$builders[] = FixtureBuilder::build('posts', array('post_id'=>'abadadfd1212', 'author_user_id'=>'19',
'author_username'=>'linkbaiter', 'author_fullname'=>'Link Baiter', 'is_geo_encoded'=>0,
'post_text'=>'This is link post '.$counter, 'source'=>'web', 'pub_date'=>'-3d',
'reply_count_cache'=>0, 'retweet_count_cache'=>0, 'network'=>'twitter',
'is_protected' => 0));

//build post published 4 days ago
$builders[] = FixtureBuilder::build('posts', array('post_id'=>'abadadfd1213', 'author_user_id'=>'19',
'author_username'=>'linkbaiter', 'author_fullname'=>'Link Baiter', 'is_geo_encoded'=>0,
'post_text'=>'This is link post '.$counter, 'source'=>'web', 'pub_date'=>'-4d',
'reply_count_cache'=>0, 'retweet_count_cache'=>0, 'network'=>'twitter',
'is_protected' => 0));

//build favorite of those posts by test user ev
$builders[] = FixtureBuilder::build('favorites', array('post_id'=>'abadadfd1212', 'author_user_id'=>'19',
'fav_of_user_id'=>'13', 'network'=>'twitter'));

$builders[] = FixtureBuilder::build('favorites', array('post_id'=>'abadadfd1213', 'author_user_id'=>'19',
'fav_of_user_id'=>'13', 'network'=>'twitter'));

//build favorite of that post by test user user1
$builders[] = FixtureBuilder::build('favorites', array('post_id'=>'abadadfd1212', 'author_user_id'=>'19',
'fav_of_user_id'=>'20', 'network'=>'twitter'));

//build favorite of that post by test user user2
$builders[] = FixtureBuilder::build('favorites', array('post_id'=>'abadadfd1212', 'author_user_id'=>'19',
'fav_of_user_id'=>'21', 'network'=>'twitter'));

$result = $this->dao->getUsersWhoFavoritedMostOfYourPosts('19', 'twitter', 7);
$this->debug(Utils::varDumpToString($result));
$this->assertEqual(sizeof($result), 1);
$this->assertEqual($result[0]->username, 'ev');
}

/**
* helper method to build a post
*/
private function buildPostArray1() {
$vals = array();
$vals['post_id']=2904;
$vals['post_id']='2904';
$vals['author_username']='quoter';
$vals['author_fullname']="Quoter of Quotables";
$vals['author_avatar']='avatar.jpg';
Expand All @@ -360,7 +435,7 @@ private function buildPostArray1() {
*/
private function buildPostArray2() {
$vals = array();
$vals['post_id']=10822735852740608;
$vals['post_id']='10822735852740608';
$vals['author_username']='user3';
$vals['author_fullname']="User 3";
$vals['author_avatar']='avatar.jpg';
Expand Down

0 comments on commit 41b8414

Please sign in to comment.