Exemplo n.º 1
0
 public function testLongLostContactsInsight()
 {
     // Get data ready that insight requires
     $builders = self::buildData();
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_user_id = 7612345;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $insight_plugin = new LongLostContactsInsight();
     $insight_plugin->generateInsight($instance, $last_week_of_posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('long_lost_contacts', 10, $today);
     $contacts = unserialize($result->related_data);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertPattern('/\\@twitteruser hasn\'t replied to /', $result->text);
     $this->assertPattern('/<strong>2 contacts<\\/strong> /', $result->text);
     $this->assertPattern('/in over a year: /', $result->text);
     $this->assertNoPattern('/a contact/', $result->text);
     $this->assertIsA($contacts, "array");
     $this->assertIsA($contacts[0], "User");
     $this->assertEqual(count($contacts), 2);
 }
 public function test7DayClickHigh()
 {
     // Assert that insight doesn't exist
     $insight_dao = new InsightMySQLDAO();
     $yesterday = date('Y-m-d', strtotime('-1 day'));
     $result = $insight_dao->getInsight('click_high_7_day_28', 1, $yesterday);
     $this->assertNull($result);
     $builders = self::buildData();
     // Add post with a link that has lots of clicks
     $post1_builder = FixtureBuilder::build('posts', array('id' => 28, 'post_id' => '28', 'author_user_id' => '13', 'author_username' => 'ev', 'author_fullname' => 'Ev Williams', 'author_avatar' => 'avatar.jpg', 'post_text' => 'This is post 28', 'source' => 'web', 'pub_date' => '-1d', 'reply_count_cache' => 0, 'is_protected' => 0, 'retweet_count_cache' => 0, 'network' => 'twitter', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'is_geo_encoded' => 0));
     $link1_builder = FixtureBuilder::build('links', array('id' => 28, 'post_key' => '28', 'short_url' => 'http://bit.ly/blah', 'expanded_url' => 'http://expandedurl.com/asfasdfadsf/adsfa'));
     $builders[] = FixtureBuilder::build('links_short', array('id' => 28, 'link_id' => '28', 'short_url' => 'http://bit.ly/blah' . $counter, 'click_count' => 7609));
     $builders[] = FixtureBuilder::build('insights', array('slug' => 'ShortLinkMySQLDAO::getRecentClickStats', 'date' => $yesterday, 'instance_id' => 1, 'related_data' => serialize('sample click spike data')));
     // Get data ready that insight requires
     $post1_object = new Post($post1_builder->columns);
     $link1_object = new Link($link1_builder->columns);
     $post1_object->links = array($link1_object);
     $posts = array();
     $posts[] = $post1_object;
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_user_id = '13';
     $instance->network = 'twitter';
     $instance->network_username = '******';
     $clickspike_insight_plugin = new ClickSpikeInsight();
     $clickspike_insight_plugin->generateInsight($instance, null, $posts, 3);
     //sleep(1000);
     // Assert that insight got generated
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('click_high_7_day_28', 1, $yesterday);
     $this->assertNotNull($result);
     $this->assertEqual($result->slug, 'click_high_7_day_28');
     $this->assertEqual($result->filename, 'clickspike');
     $this->assertPattern('/Viewers clicked \\@ev\'s link \\<strong\\>7,609 times\\<\\/strong\\>/', $result->headline);
 }
 public function testStyleStats()
 {
     // Assert that insight doesn't exist
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('style_stats', 1, date('Y-m-d'));
     $this->assertNull($result);
     $builders = self::buildData();
     // Add post that's not a photo, link, quotation, or question
     $post1_builder = FixtureBuilder::build('posts', array('id' => 28, 'post_id' => '28', 'author_user_id' => '13', 'author_username' => 'ev', 'author_fullname' => 'Ev Williams', 'author_avatar' => 'avatar.jpg', 'post_text' => 'This is post 28', 'source' => 'web', 'pub_date' => '-1d', 'reply_count_cache' => 0, 'is_protected' => 0, 'retweet_count_cache' => 0, 'network' => 'twitter', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'is_geo_encoded' => 0));
     $link1_builder = FixtureBuilder::build('links', array('id' => 28, 'post_key' => '28', 'short_url' => 'http://bit.ly/blah', 'expanded_url' => 'http://expandedurl.com/asfasdfadsf/adsfa'));
     $builders[] = FixtureBuilder::build('links_short', array('id' => 28, 'link_id' => '28', 'short_url' => 'http://bit.ly/blah' . $counter, 'click_count' => 7609));
     $builders[] = FixtureBuilder::build('insights', array('slug' => 'PostMySQLDAO::getHotPosts', 'date' => date('Y-m-d'), 'instance_id' => 1));
     // Add a question
     $post2_builder = FixtureBuilder::build('posts', array('id' => 29, 'post_id' => '29', 'author_user_id' => '13', 'author_username' => 'ev', 'author_fullname' => 'Ev Williams', 'author_avatar' => 'avatar.jpg', 'post_text' => 'Is this post 29?', 'source' => 'web', 'pub_date' => '-1d', 'reply_count_cache' => 0, 'is_protected' => 0, 'retweet_count_cache' => 0, 'network' => 'twitter', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'is_geo_encoded' => 0));
     $post_dao = new PostMySQLDAO();
     $last_week_of_posts = $post_dao->getAllPostsByUsernameOrderedBy('ev', 'twitter', $count = 0, $order_by = "pub_date", $in_last_x_days = 7, $iterator = false, $is_public = false);
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_user_id = '13';
     $instance->network = 'twitter';
     $instance->network_username = '******';
     $stylestats_insight_plugin = new StyleStatsInsight();
     $stylestats_insight_plugin->generateInsight($instance, null, $last_week_of_posts, 3);
     // Assert that insight got generated
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('style_stats', 1, date('Y-m-d'));
     $this->assertNotNull($result);
     $this->assertEqual($result->slug, 'style_stats');
     $this->assertEqual($result->filename, 'stylestats');
     $this->assertEqual("7 of @ev's posts this week were photos and 1 was a question", $result->headline);
     //sleep(1000);
 }
Exemplo n.º 4
0
 public function testHelloThinkUpInsight()
 {
     $posts = array();
     $instance = new Instance();
     $hello_thinkup_insight_plugin = new HelloThinkUpInsight();
     $hello_thinkup_insight_plugin->generateInsight($instance, $posts, 3);
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('my_test_insight_hello_thinkup', 1, '2013-12-21');
     $this->assertEqual($result->headline, 'Ohai');
     $this->assertEqual($result->text, 'Greetings humans');
     $this->assertEqual($result->filename, 'hellothinkupinsight');
     $this->assertNull($result->related_data);
     $this->assertEqual($result->emphasis, Insight::EMPHASIS_MED);
 }
 public function testSavedSearchResults()
 {
     // Assert that insight doesn't exist
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('saved_search_results_102', 1, date('Y-m-d'));
     $this->assertNull($result);
     $builders = self::buildData();
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_user_id = '13';
     $instance->network = 'facebook';
     $instance->network_username = '******';
     $stylestats_insight_plugin = new SavedSearchResultsInsight();
     $stylestats_insight_plugin->generateInsight($instance, null, $last_week_of_posts, 3);
     // Assert that insight got generated
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('saved_search_results_102', 1, date('Y-m-d'));
     $this->assertNotNull($result);
     $this->assertEqual($result->slug, 'saved_search_results_102');
     $this->assertEqual($result->filename, 'savedsearchresults');
     $this->assertEqual('7 new posts contain "<strong>#thinkupsavedsearch</strong>".', $result->headline);
 }
 public function testSavedSearchResults()
 {
     // Assert that insight doesn't exist
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('saved_search_results_102', 1, date('Y-m-d'));
     $this->assertNull($result);
     $builders = self::buildData();
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_user_id = '13';
     $instance->network = 'facebook';
     $instance->network_username = '******';
     $stylestats_insight_plugin = new SavedSearchResultsInsight();
     $stylestats_insight_plugin->generateInsight($instance, $last_week_of_posts, 3);
     // Assert that insight got generated
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('saved_search_results_102', 1, date('Y-m-d'));
     $this->assertNotNull($result);
     $this->assertEqual($result->slug, 'saved_search_results_102');
     $this->assertEqual($result->headline, 'New search results:');
     $this->assertEqual($result->filename, 'savedsearchresults');
     $this->assertEqual('7 new posts contain <b><a href="search.php?u=ev&n=facebook&c=searches&k=%23' . 'thinkupsavedsearch&q=%23thinkupsavedsearch">#thinkupsavedsearch</a></b>.', $result->text);
 }
 public function testTimeGeneratedDoesntUpdate()
 {
     $today = date('Y-m-d');
     $baseline_dao = DAOFactory::getDAO('InsightBaselineDAO');
     foreach (array('fave', 'reply', 'retweet') as $act) {
         $baseline_dao->insertInsightBaseline("avg_{$act}_count_last_7_days", $this->instance->id, 2, $today);
         $baseline_dao->insertInsightBaseline("high_{$act}_count_last_7_days", $this->instance->id, 2, $today);
     }
     // We add an old baseline so that 7 day checks
     $baseline_dao->insertInsightBaseline('high_fave_count_last_365_days', $this->instance->id, $avg = 2, date('Y-m-d', time() - 8 * 24 * 60 * 60));
     $posts = array($this->makePost($replies = 1, $retweets = 10, $faves = 50));
     $insight_plugin = new ActivitySpikeInsight();
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('fave_high_7_day_1', 10, $today);
     $this->assertNotNull($result);
     $this->assertEqual('@buffy really got some likes', $result->headline);
     $generated = $result->time_generated;
     $date = $result->date;
     sleep(1);
     // force timestamp to change
     $posts = array($this->makePost($replies = 1, $retweets = 10, $faves = 100));
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     $result = $insight_dao->getInsight('fave_high_7_day_1', 10, $today);
     $this->assertNotNull($result);
     $this->assertEqual('@buffy really got some likes', $result->headline);
     $this->assertEqual($result->time_generated, $generated);
     $this->assertEqual($result->date, $date);
 }
 public function testSingleLongLostContact()
 {
     // Get data ready that insight requires
     $builders = self::buildData($multiple = false);
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_user_id = 7612345;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $insight_plugin = new LongLostContactsInsight();
     $insight_plugin->generateInsight($instance, null, $last_week_of_posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('long_lost_contacts', 10, $today);
     $contacts = unserialize($result->related_data);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertPattern('/\\@twitteruser hasn\'t replied to /', $result->headline);
     $this->assertPattern('/Twitter Follower One /', $result->headline);
     $this->assertPattern('/in over a year/', $result->headline);
     $this->assertPattern('/avatar.jpg/', $result->header_image);
     $this->assertNoPattern('/people/', $result->headline);
     $this->assertIsA($contacts, "array");
     $this->assertIsA($contacts["people"][0], "User");
     $this->assertEqual(count($contacts["people"]), 1);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 public function testAlternateHeadline()
 {
     TimeHelper::setTime(3);
     // Get data ready that insight requires
     $builders = self::buildData();
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_user_id = 7612345;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $insight_plugin = new FavoritedLinksInsight();
     $insight_plugin->generateInsight($instance, null, $last_week_of_posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('favorited_links', 10, $today);
     $fav_posts = unserialize($result->related_data);
     $this->assertNotNull($result);
     $this->assertEqual('1 link @testeriffic liked', $result->headline);
     $this->assertEqual(count($fav_posts), 1);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
     $builders[] = FixtureBuilder::build('posts', array('id' => 999, 'post_id' => 999, 'author_user_id' => 7654321, 'author_username' => 'twitteruser', 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => 'twitter', 'post_text' => 'This is an old post http://t.co/aMHh5XHGfS with a link.', 'source' => 'web', 'pub_date' => $yesterday, 'reply_count_cache' => 0, 'is_protected' => 0));
     $builders[] = FixtureBuilder::build('links', array('post_key' => 999, 'url' => 'http://t.co/aMHh5XHGfS', 'expanded_url' => 'http://techcrunch.com/2013/04/28/disrupt-ny-hackathon-gets-hacked-man-' . 'takes-stage-and-uses-his-60-seconds-to-disrupt-capitalism/'));
     $builders[] = FixtureBuilder::build('favorites', array('post_id' => 999, 'author_user_id' => 7654321, 'fav_of_user_id' => 7612345, 'network' => 'twitter', 'fav_timestamp' => $today));
     $insight_plugin->generateInsight($instance, null, $last_week_of_posts, 3);
     $result = $insight_dao->getInsight('favorited_links', 10, $today);
     $fav_posts = unserialize($result->related_data);
     $this->assertNotNull($result);
     $this->assertEqual('2 links @testeriffic liked', $result->headline);
     $this->assertEqual(count($fav_posts), 1);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 public function testInsightTextsFacebook()
 {
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_username = '******';
     $instance->network = 'facebook';
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $insight_plugin = new WeeklyGraphInsight();
     $posts = array();
     $posts[] = new Post(array('reply_count_cache' => 3, 'retweet_count_cache' => 0, 'favlike_count_cache' => 0, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 3, 'retweet_count_cache' => 0, 'favlike_count_cache' => 0, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 3, 'retweet_count_cache' => 0, 'favlike_count_cache' => 0, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 3, 'retweet_count_cache' => 0, 'favlike_count_cache' => 0, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     TimeHelper::setTime(1);
     //set headline to expect
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     $result = $insight_dao->getInsight('weekly_graph', 10, $today);
     $this->assertEqual("Jo ThinkUp really inspired conversations", $result->headline);
     $this->assertEqual('In the past week, comments to Jo ThinkUp outnumbered likes or reshares.', $result->text);
     $this->dumpRenderedInsight($result, $instance, "");
     $posts = array();
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 3, 'favlike_count_cache' => 0, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 3, 'favlike_count_cache' => 0, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 3, 'favlike_count_cache' => 0, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 3, 'favlike_count_cache' => 0, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     TimeHelper::setTime(2);
     //set headline to expect
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     $result = $insight_dao->getInsight('weekly_graph', 10, $today);
     $this->assertEqual("Jo ThinkUp shared lots of things people wanted to amplify", $result->headline);
     $this->assertEqual("This past week, Jo ThinkUp's reshares outnumbered comments by 12 and likes by 12.", $result->text);
     $this->dumpRenderedInsight($result, $instance, "");
     $posts = array();
     $posts[] = new Post(array('reply_count_cache' => 3, 'retweet_count_cache' => 3, 'favlike_count_cache' => 0, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 3, 'retweet_count_cache' => 3, 'favlike_count_cache' => 0, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 3, 'retweet_count_cache' => 3, 'favlike_count_cache' => 0, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 3, 'retweet_count_cache' => 3, 'favlike_count_cache' => 0, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     TimeHelper::setTime(3);
     //set headline to expect
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     $result = $insight_dao->getInsight('weekly_graph', 10, $today);
     $this->assertEqual("Jo ThinkUp really inspired conversations", $result->headline);
     $this->assertEqual('In the past week, comments to Jo ThinkUp outnumbered likes.', $result->text);
     $this->dumpRenderedInsight($result, $instance, "");
     $posts = array();
     $posts[] = new Post(array('reply_count_cache' => 3, 'retweet_count_cache' => 3, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 3, 'retweet_count_cache' => 3, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 3, 'retweet_count_cache' => 3, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 3, 'retweet_count_cache' => 3, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     TimeHelper::setTime(4);
     //set headline to expect
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     $result = $insight_dao->getInsight('weekly_graph', 10, $today);
     $this->assertEqual("Jo ThinkUp really inspired conversations", $result->headline);
     $this->assertEqual('Jo ThinkUp got more comments than anything else.', $result->text);
     $this->dumpRenderedInsight($result, $instance, "");
     $posts = array();
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 2, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 2, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 2, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 2, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     TimeHelper::setTime(5);
     //set headline to expect
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     $result = $insight_dao->getInsight('weekly_graph', 10, $today);
     $this->assertEqual("Whatever Jo ThinkUp said must have been memorable", $result->headline);
     $this->assertEqual('In the past week, Jo ThinkUp got 12 likes, beating out 8 reshares.', $result->text);
     $this->dumpRenderedInsight($result, $instance, "");
     $posts = array();
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 3, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 3, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 3, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 3, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     $result = $insight_dao->getInsight('weekly_graph', 10, $today);
     $this->assertEqual("Whatever Jo ThinkUp said must have been memorable", $result->headline);
     $this->assertEqual('In the past week, Jo ThinkUp got 12 likes.', $result->text);
     $this->dumpRenderedInsight($result, $instance, "");
     $posts = array();
     $posts[] = new Post(array('reply_count_cache' => 1, 'retweet_count_cache' => 2, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 1, 'retweet_count_cache' => 2, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 1, 'retweet_count_cache' => 2, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $posts[] = new Post(array('reply_count_cache' => 1, 'retweet_count_cache' => 2, 'favlike_count_cache' => 3, 'pub_date' => date('Y-m-d H:i:s', strtotime('-' . $days . ' day'))));
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     $result = $insight_dao->getInsight('weekly_graph', 10, $today);
     $this->assertEqual("Whatever Jo ThinkUp said must have been memorable", $result->headline);
     $this->assertEqual('In the past week, Jo ThinkUp got 12 likes, beating out 4 comments and 8 reshares.', $result->text);
     $this->dumpRenderedInsight($result, $instance, "");
 }
Exemplo n.º 11
0
 public function testAllAboutYouInsightPriorEqualBaseline()
 {
     // Get data ready that insight requires
     $posts = self::getTestPostObjects();
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $insight_plugin = new AllAboutYouInsight();
     // Add a baseline from prior week
     $last_week = date('Y-m-d', strtotime('-7 day'));
     $builder = FixtureBuilder::build('insight_baselines', array('date' => $last_week, 'slug' => 'all_about_you', 'instance_id' => 10, 'value' => 9));
     $insight_plugin->generateInsight($instance, $posts, 3);
     // Assert that week-over-week comparison is correct
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('all_about_you', 10, $today);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertPattern('/\\@testeriffic\'s posts contained the words/', $result->text);
     $this->assertPattern('/9 times/', $result->text);
     //assert no comparison to prior week
     $this->assertNoPattern('/prior week/', $result->text);
     $this->assertNoPattern('/prior week/', $result->text);
 }
Exemplo n.º 12
0
 public function testWordInWord()
 {
     $year = date('Y');
     $builders = array();
     $builders[] = FixtureBuilder::build('posts', array('pub_date' => $year . '-02-26', 'post_id' => 1, 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'network' => $this->instance->network, 'post_text' => 'Radarscotusthoughts is not a real word.'));
     $post->author_username = $this->instance->network_username;
     $post->author_user_id = $this->instance->network_user_id;
     $insight_plugin = new LoveWinsInsight();
     $insight_dao = new InsightMySQLDAO();
     $insight_plugin->generateInsight($this->instance, new User(), array($post), 3);
     $result = $insight_dao->getInsight($insight_plugin->slug, $this->instance->id, date('Y-m-d'));
     $this->assertNull($result);
 }
Exemplo n.º 13
0
 public function testNormalFacebookIncompleteData()
 {
     $this->instance = new Instance();
     $this->instance->id = 1;
     $this->instance->network_username = '******';
     $this->instance->network_user_id = '30';
     $this->instance->network = 'facebook';
     $builders = self::buildTruckloadOfFacebookData();
     //User fixtures set up in buildTruckloadOfFacebookData
     /*
             $ub1 = FixtureBuilder::build('users', array('user_id'=>30, 'user_name'=>'fbuser1',
             'full_name'=>'Facebook User 1', 'is_protected'=>0, 'network'=>'facebook'));
             array_push($builders, $ub1);
     
             $ub2 = FixtureBuilder::build('users', array('user_id'=>31, 'user_name'=>'fbuser2',
             'full_name'=>'Facebook User 2', 'is_protected'=>0, 'network'=>'facebook'));
             array_push($builders, $ub2);
     
             $ub3 = FixtureBuilder::build('users', array('user_id'=>32, 'user_name'=>'fbuser3',
             'full_name'=>'Facebook User 3', 'is_protected'=>0, 'network'=>'facebook'));
             array_push($builders, $ub3);
     */
     //Add replies to friends
     $counter = 1;
     while ($counter < 10) {
         if ($counter % 2 == 1) {
             $in_reply_to_user_id = 31;
             //fbuser2
         } else {
             $in_reply_to_user_id = 32;
             //fbuser3
         }
         $builders[] = FixtureBuilder::build('posts', array('post_id' => $counter + 34358, 'author_user_id' => '30', 'author_username' => 'fbuser1', 'author_avatar' => 'avatar.jpg', 'post_text' => 'This is post ' . $counter, 'source' => $source, 'pub_date' => '-12d' . $pseudo_minute . ':00', 'reply_count_cache' => $counter == 10 ? 0 : rand(0, 4), 'is_protected' => 0, 'retweet_count_cache' => floor($counter / 2), 'network' => 'facebook', 'in_reply_to_user_id' => $in_reply_to_user_id, '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));
         $counter++;
     }
     //Add replies from friends
     $counter = 1;
     while ($counter < 10) {
         if ($counter % 2 == 1) {
             $author_user_id = 31;
             $author_username = '******';
         } else {
             $author_user_id = 32;
             $author_username = '******';
         }
         $builders[] = FixtureBuilder::build('posts', array('post_id' => $counter + 5467, 'author_user_id' => $author_user_id, 'author_username' => $author_username, 'author_avatar' => 'avatar.jpg', 'post_text' => 'This is post ' . $counter, 'source' => $source, 'pub_date' => '-15d' . $pseudo_minute . ':00', 'reply_count_cache' => $counter == 10 ? 0 : rand(0, 4), 'is_protected' => 0, 'retweet_count_cache' => floor($counter / 2), 'network' => 'facebook', 'in_reply_to_user_id' => '30', '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));
         $counter++;
     }
     $posts = array();
     $insight_plugin = new EOYBestieInsight();
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $year = date('Y');
     $result = $insight_dao->getInsight($insight_plugin->slug, $this->instance->id, $year . '-' . $insight_plugin->run_date);
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertEqual("fbuser1's Facebook bestie of 2015", $result->headline);
     $this->assertEqual("Everyone loves getting comments from their friends. In 2015, fbuser2 commented on " . "fbuser1's status updates <strong>5 times</strong>, more than anyone else (at least since November). " . "Best friends forever!", $result->text);
     $this->dumpRenderedInsight($result, $this->instance, "No bestie incomplete data, Twitter");
 }
 public function testFacebookNormalCase()
 {
     $this->instance->network_username = '******';
     $this->instance->network = 'facebook';
     $builders = self::setUpPublicInsight($this->instance);
     $year = date('Y');
     $user_id = $this->instance->network_user_id;
     $counter = 12;
     $days = 0;
     // set up most links
     while ($counter != 0) {
         $post_key = $counter + 1760;
         $days++;
         $builders[] = FixtureBuilder::build('posts', array('id' => $post_key, 'post_id' => $post_key, 'network' => $this->instance->network, 'author_user_id' => $user_id, 'author_username' => 'Mark Zuckerberg', 'in_reply_to_user_id' => NULL, 'in_retweet_of_post_id' => NULL, 'in_reply_to_post_id' => 0, 'is_protected' => 0, 'author_fullname' => 'User', 'retweet_count_cache' => $days, 'reply_count_cache' => $days, 'favlike_count_cache' => $days, 'post_text' => 'Link post #' . $counter . ' http://lifehacker.com/' . $counter, 'pub_date' => '2015-10-01'));
         $builders[] = FixtureBuilder::build('links', array('url' => 'http://lifehacker.com/' . $counter, 'title' => 'Link ' . $counter, 'post_key' => $post_key, 'expanded_url' => 'http://lifehacker.com/' . $counter, 'error' => '', 'image_src' => ''));
         $counter--;
     }
     // set up fewer links
     $counter = 10;
     $days = 0;
     while ($counter != 0) {
         $post_key = $counter + 1860;
         $days++;
         $builders[] = FixtureBuilder::build('posts', array('id' => $post_key, 'post_id' => $post_key, 'network' => $this->instance->network, 'author_user_id' => $user_id, 'author_username' => 'Mark Zuckerberg', 'in_reply_to_user_id' => NULL, 'in_retweet_of_post_id' => NULL, 'in_reply_to_post_id' => 0, 'is_protected' => 0, 'author_fullname' => 'User', 'post_text' => 'Link post http://nytimes.com/' . $counter, 'pub_date' => '2015-10-01'));
         $builders[] = FixtureBuilder::build('links', array('url' => 'http://nytimes.com/' . $counter, 'title' => 'Link ' . $counter, 'post_key' => $post_key, 'expanded_url' => 'http://nytimes.com/' . $counter, 'error' => '', 'image_src' => ''));
         $counter--;
     }
     $posts = array();
     $insight_plugin = new EOYMostLinksInsight();
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('eoy_most_links', $this->instance->id, $year . '-' . $insight_plugin->run_date);
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $year = date('Y');
     $this->assertEqual("Mark Zuckerberg's most-shared site of {$year}", $result->headline);
     $this->assertEqual("Looks like <strong>lifehacker.com</strong> owes Mark Zuckerberg a thank you. " . "In {$year}, Mark Zuckerberg directed friends to <strong>lifehacker.com</strong> more than to " . "any other site. Here are the posts with links to <strong>lifehacker.com</strong>.", $result->text);
     $this->dumpRenderedInsight($result, $this->instance, "Normal case, Facebook");
 }
 public function testOlympic2014InsightRegeneration()
 {
     // Get data ready that insight requires
     $instance = new Instance();
     $instance->id = 3;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $builders = self::setUpPublicInsight($instance);
     $builders[] = FixtureBuilder::build('posts', array('post_text' => 'These were amazing opening ceremonies in sochi!', 'pub_date' => '2014-02-07', 'author_username' => $instance->network_username, 'network' => $instance->network));
     $builders[] = FixtureBuilder::build('posts', array('post_text' => 'The olympic closing ceremony is the greatest global event since Beyonce\'s album', 'pub_date' => '2014-02-07', 'author_username' => $instance->network_username, 'network' => $instance->network));
     $builders[] = FixtureBuilder::build('posts', array('post_text' => 'Hope nothing else goes wrong! #sochi2014', 'pub_date' => '2014-02-19', 'author_username' => $instance->network_username, 'network' => $instance->network));
     $posts = array();
     $insight_plugin = new Olympics2014Insight();
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('olympics_2014', 3, $today);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertEqual('Do they give out medals for tweets?', $result->headline);
     $this->assertEqual('@catlady99 mentioned the Olympics 5 times since they started. That\'s kind of like ' . 'winning 5 gold medals in Twitter, right?', $result->text);
     //Add a new post that should update the insight with 2 more mentions
     $builders[] = FixtureBuilder::build('posts', array('post_text' => 'Great closing ceremony! #sochi2014', 'pub_date' => '2014-02-21', 'author_username' => $instance->network_username, 'network' => $instance->network));
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     // Assert that insight got updated
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('olympics_2014', 3, $today);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertEqual('@catlady99 mentioned the Olympics 7 times since they started. That\'s kind of like ' . 'winning 7 gold medals in Twitter, right?', $result->text);
     $controller = new InsightStreamController();
     $_GET['u'] = 'catlady99';
     $_GET['n'] = 'twitter';
     $_GET['d'] = date('Y-m-d');
     $_GET['s'] = 'olympics_2014';
     $results = $controller->go();
     //output this to an HTML file to see the insight fully rendered
     //$this->debug($results);
     //Test email rendering
     $email_insight = $this->getRenderedInsightInEmail($result);
     //$this->debug($email_insight);
 }
Exemplo n.º 16
0
 public function testInteractionsInsightMentionCasesIgnored()
 {
     // Get data ready that insight requires
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $builders = array();
     $builders[] = FixtureBuilder::build('users', array('user_id' => '7612345', 'user_name' => 'TwitterTestUser', 'full_name' => 'Twitter Test User', 'avatar' => 'avatar.jpg', 'follower_count' => 36000, 'is_protected' => 0, 'network' => 'twitter', 'description' => 'A test Twitter user'));
     $posts = array();
     $posts[] = new Post(array('post_text' => "Blah blah bleh @TwitterTestUser blah", 'pub_date' => date("Y-m-d H:i:s", strtotime('-2 days'))));
     $posts[] = new Post(array('post_text' => "Blah blah bleh @Twittertestuser blah blah", 'pub_date' => date("Y-m-d H:i:s", strtotime('-2 days'))));
     $posts[] = new Post(array('post_text' => "Blah blah @twitterTestUser blah", 'pub_date' => date("Y-m-d H:i:s", strtotime('-2 days'))));
     $posts[] = new Post(array('post_text' => "Blah blah @tWiTTerTeSTusEr blah bleh", 'pub_date' => date("Y-m-d H:i:s", strtotime('-2 days'))));
     $insight_plugin = new InteractionsInsight();
     $insight_plugin->generateInsight($instance, $posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight("interactions", 10, $today);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $dataset = unserialize($result->related_data);
     $this->assertIsA($result, "Insight");
     $this->assertPattern('/\\@testeriffic mentioned /', $result->text);
     $this->assertPattern('/\\@TwitterTestUser <strong>4 times/', $result->text);
     $this->assertEqual($dataset[0]['mention'], '@TwitterTestUser');
     $this->assertEqual($dataset[0]['count'], 4);
     $this->assertEqual($dataset[0]['user']->full_name, "Twitter Test User");
 }
 public function testLowDecrease()
 {
     $user = self::buildData();
     // Insert a video that would have lowered the subscriber count by >= 50%
     $post_builder = FixtureBuilder::build('posts', array('id' => 1, 'post_id' => '1', 'author_username' => 'ev', 'post_text' => 'My Great Video', 'pub_date' => '-1d', 'network' => 'youtube'));
     $video_builder = FixtureBuilder::build('videos', array('id' => 1, 'post_key' => '1', 'subscribers_gained' => 0, 'subscribers_lost' => 4, 'average_view_percentage' => 10));
     $instance = new Instance();
     $instance->id = 1;
     $instance->network = 'youtube';
     $instance->network_username = '******';
     $instance->network_user_id = 1;
     $insight = new SubscriberChangeInsight();
     $posts[] = new Post($post_builder->columns);
     $insight->generateInsight($instance, $this->getUser(), $posts, 7);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('subscriber_change1', 1, date('Y-m-d', strtotime('-1 day')));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $headline = "My Great Video decreased ev's subscriber count by <strong>16.67%</strong>.";
     $this->assertEqual($result->headline, $headline);
     $this->assertEqual($result->emphasis, 0);
 }
Exemplo n.º 18
0
 public function testAgeAnalysisForFacebookSeniors()
 {
     // Get data ready that insight requires
     $builders = self::buildDataSeniors();
     $instance = new Instance();
     $instance->id = 100;
     $instance->network_user_id = 1;
     $instance->network_username = '******';
     $instance->network = 'facebook';
     $post_dao = new PostMySQLDAO();
     $last_week_of_posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $network = $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = $number_days, $iterator = false, $is_public = false);
     $insight_plugin = new AgeAnalysisInsight();
     $insight_plugin->generateInsight($instance, null, $last_week_of_posts, 1);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('age_analysis', 100, $today);
     $related_data = unserialize($result->related_data);
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertEqual($result->headline, 'Old Man resonated with Baby Boomers');
     $this->assertEqual($result->text, "Baby Boomers — people 45+ years old — had the most to say in response " . "to Old Man's posts on Facebook this week.");
     $this->assertEqual($related_data['age_data']['18'], 1);
     $this->assertEqual($related_data['age_data']['18_25'], 0);
     $this->assertEqual($related_data['age_data']['25_35'], 0);
     $this->assertEqual($related_data['age_data']['35_45'], 0);
     $this->assertEqual($related_data['age_data']['45'], 2);
     $result->id = 5;
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 public function testFacebookNormalCase()
 {
     $this->instance->network_username = '******';
     $this->instance->network = 'facebook';
     $builders = self::setUpPublicInsight($this->instance);
     $year = date('Y');
     for ($i = 3; $i < 3; $i++) {
         for ($j = 0; $j < 4; $j++) {
             $builders[] = FixtureBuilder::build('posts', array('post_text' => 'This is a post that I did!', 'pub_date' => "{$year}-0{$i}-07", 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'network' => $this->instance->network, 'in_retweet_of_post_id' => null));
         }
     }
     // one more post in February
     $builders[] = FixtureBuilder::build('posts', array('post_text' => 'This is a post that I did!', 'pub_date' => "{$year}-02-07", 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'network' => $this->instance->network, 'in_retweet_of_post_id' => null));
     $posts = array();
     $insight_plugin = new EOYWordCountInsight();
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $year = date('Y');
     $result = $insight_dao->getInsight('eoy_word_count', $this->instance->id, $year . '-' . $insight_plugin->run_date);
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertEqual("Mark Zuckerberg had a word or two (or 7) for Facebook in 2015", $result->headline);
     $this->assertEqual("In 2015, Mark Zuckerberg typed and tapped <strong>7 words</strong> into Facebook's " . "status update or comment box (at least since February), topping out with 7 words in February. " . "Here's a breakdown by month.", $result->text);
     $this->dumpRenderedInsight($result, $this->instance, "Normal case, Facebook");
 }
Exemplo n.º 20
0
 public function testNoWords()
 {
     $insight_plugin = new EOYTopWordsInsight();
     $insight_dao = new InsightMySQLDAO();
     $year = date('Y');
     $day = $year . '-' . $insight_plugin->run_date;
     $insight_plugin->generateInsight($this->instance, new User(), array(), 3);
     $result = $insight_dao->getInsight($insight_plugin->slug, $this->instance->id, $day);
     $this->assertNull($result);
 }
 public function testOverMax()
 {
     $a = $this->buildAmpee(10, 'Elaine', 'http://deecrowseer.files.wordpress.com/2013/06/seinfeld5-jld01.jpg', 'J. Peterman Catalog editor', 12, 'March 1');
     $b = $this->buildAmpee(8, 'Kramer', 'http://upload.wikimedia.org/wikipedia/en/b/b7/Cosmo_Kramer.jpg', 'Entrepeneur, Shower Chef', 9999, 'June 1');
     $c = $this->buildAmpee(7, 'George', 'http://upload.wikimedia.org/wikipedia/en/7/70/George_Costanza.jpg', 'Shrimp Lover', 4, 'July 1');
     $d = $this->buildAmpee(1, 'Newman', '...', 'Postal Worked', 4, 'July 1');
     $this->instance->last_post_id = '99999';
     $e = FixtureBuilder::build('posts', array('post_id' => '99999', 'post_text' => 'This is least liked', 'pub_date' => date('Y-m-d', strtotime('January 1, 2011')), 'author_username' => $this->instance->network_username, 'network' => $this->instance->network, 'favlike_count_cache' => 25));
     $this->instance->last_post_id = '99999';
     $insight_plugin = new EOYWhoYouAmplifiedInsight();
     $insight_plugin->generateInsight($this->instance, new User(), array(), 3);
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y') . '-' . $insight_plugin->run_date;
     $result = $insight_dao->getInsight($insight_plugin->slug, $this->instance->id, $today);
     $this->assertNotNull($result);
     $this->assertEqual($result->headline, "Who @jerryseinfeld amplified most on Twitter, 2015");
     $this->assertEqual($result->text, "Let's turn this tweet up to 11! In 2015, @jerryseinfeld retweeted " . "these users more than any others.");
     $data = unserialize($result->related_data);
     $this->assertEqual(count($data['people']), 3);
     $this->assertEqual($data['people'][0]->username, 'Elaine');
     $this->assertEqual($data['people'][1]->username, 'Kramer');
     $this->assertEqual($data['people'][2]->username, 'George');
     $this->dumpRenderedInsight($result, $this->instance, "Four Retweetees, Three Shown");
 }
 public function testFacebookNoMatch()
 {
     $this->instance->network_username = '******';
     $this->instance->network = 'facebook';
     $year = date('Y');
     $builders = self::setUpPublicInsight($this->instance);
     // post with no pic
     $builders[] = FixtureBuilder::build('posts', array('id' => 10, 'post_id' => 10, 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'author_fullname' => 'Facebook User', 'author_avatar' => 'avatar.jpg', 'network' => $this->instance->network, 'post_text' => 'This is a post with no link', 'source' => 'web', 'pub_date' => "{$year}-01-01", 'reply_count_cache' => 10, 'is_protected' => false));
     $posts = array();
     $insight_plugin = new EOYPopularLinkInsight();
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('eoy_popular_link', $this->instance->id, $year . '-' . $insight_plugin->run_date);
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertEqual("No links on Facebook?", $result->headline);
     $this->assertEqual("Mark Zuckerberg didn't link to anything on Facebook in {$year}. " . "The internet promises to try harder, next year.", $result->text);
     $this->dumpRenderedInsight($result, $this->instance, "No matches, Facebook");
 }
Exemplo n.º 23
0
 public function testTwitterCompleteDataOnlyUnderMinimumReplies()
 {
     $this->instance = new Instance();
     $this->instance->id = 1;
     $this->instance->network_user_id = '13';
     $this->instance->network_username = '******';
     $this->instance->network = 'twitter';
     //User fixtures set up in buildTruckloadOfTwitterData
     $builders = self::buildTruckloadOfTwitterData();
     //Add 5 replies to friends
     $counter = 1;
     while ($counter < 7) {
         if ($counter % 2 == 1) {
             $in_reply_to_user_id = 18;
             //shutterbug
         } else {
             $in_reply_to_user_id = 19;
             //linkbaiter
         }
         $builders[] = FixtureBuilder::build('posts', array('post_id' => $counter + 34358, 'author_user_id' => '13', 'author_username' => 'ev', 'author_fullname' => 'Ev Williams', 'author_avatar' => 'avatar.jpg', 'post_text' => 'This is post ' . $counter, 'source' => $source, 'pub_date' => '-12d' . $pseudo_minute . ':00', 'reply_count_cache' => $counter == 10 ? 0 : rand(0, 4), 'is_protected' => 0, 'retweet_count_cache' => floor($counter / 2), 'network' => 'twitter', 'in_reply_to_user_id' => $in_reply_to_user_id, '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));
         $counter++;
     }
     //Add replies from friends
     $counter = 1;
     while ($counter < 5) {
         if ($counter % 2 == 1) {
             $author_user_id = 19;
             $author_username = '******';
         } else {
             $author_user_id = 20;
             $author_username = '******';
         }
         $avatar = "https://farm7.staticflickr.com/6146/5976784449_4fe7c02760_q.jpg";
         $builders[] = FixtureBuilder::build('posts', array('post_id' => $counter + 5467, 'author_user_id' => $author_user_id, 'author_username' => $author_username, 'author_avatar' => $avatar, 'post_text' => 'This is post ' . $counter, 'source' => $source, 'pub_date' => '-15d' . $pseudo_minute . ':00', 'reply_count_cache' => $counter == 10 ? 0 : rand(0, 4), 'is_protected' => 0, 'retweet_count_cache' => floor($counter / 2), 'network' => 'twitter', 'in_reply_to_user_id' => '13', '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));
         $counter++;
     }
     $posts = array();
     $insight_plugin = new BestieInsight();
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight($insight_plugin->slug, $this->instance->id, $today);
     $this->assertNull($result);
 }
Exemplo n.º 24
0
 public function testSingleBigReshareWithLessThan2xFollowers()
 {
     // Assert that insight doesn't exist
     $insight_dao = new InsightMySQLDAO();
     $yesterday = date('Y-m-d', strtotime('-1 day'));
     $result = $insight_dao->getInsight('big_reshare_1345', 10, $yesterday);
     $this->assertNull($result);
     //original post
     $post1_builder = FixtureBuilder::build('posts', array('id' => 1345, 'post_id' => '134', 'author_user_id' => 22, 'author_username' => 'quoter', 'author_fullname' => 'Quoter of Quotables', 'network' => 'twitter', 'post_text' => 'Be liberal in what you accept and conservative in what you send', 'source' => 'web', 'pub_date' => '-1d', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'is_protected' => 0, 'location' => 'New Delhi, Delhi, India', 'geo' => '28.635308,77.22496', 'is_geo_encoded' => 1));
     $post1_object = new Post($post1_builder->columns);
     $builders = self::buildData();
     //retweet author has less than 2x more followers
     $builders[] = FixtureBuilder::build('users', array('user_id' => '20', 'user_name' => 'user1', 'full_name' => 'User 1', 'description' => 'I am a user', 'avatar' => 'avatar.jpg', 'is_protected' => 0, 'follower_count' => 100, 'network' => 'twitter'));
     // Get data ready that insight requires
     $posts = array();
     $posts[] = $post1_object;
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_user_id = '22';
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $bigreshare_insight_plugin = new BigReshareInsight();
     $bigreshare_insight_plugin->generateInsight($instance, $this->getUser(), $posts, 3);
     // Assert that insight got generated
     $insight_dao = new InsightMySQLDAO();
     $yesterday = date('Y-m-d', strtotime('-1 day'));
     $result = $insight_dao->getInsight('big_reshare_1345', 10, $yesterday);
     $this->assertNotNull($result);
     $this->assertEqual($result->slug, 'big_reshare_1345');
     $this->assertEqual($result->filename, 'bigreshare');
     $this->assertEqual($result->text, '20 more people saw @tester\'s tweet.');
     $this->assertPattern('/User 1 retweeted/', $result->headline);
     $sharers = unserialize($result->related_data . people);
     $retweet_user = $sharers["people"][0];
     $this->assertEqual($retweet_user->description, 'I am a user');
     $this->debug($this->getRenderedInsightInHTML($result));
 }
 public function test2LocalFollowersInsightWith1Verified()
 {
     // Get data ready that insight requires
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_user_id = 9654000768;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $builders = array();
     // User
     $builders[] = FixtureBuilder::build('users', array('user_id' => '9654000768', 'user_name' => 'testuser', 'full_name' => 'Twitter User', 'avatar' => 'avatar.jpg', 'follower_count' => 360, 'is_protected' => 1, 'network' => 'twitter', 'description' => 'A test Twitter User', 'location' => 'San Francisco, CA', 'friend_count' => 360, 'is_verified' => 0));
     // Followers
     $builders[] = FixtureBuilder::build('users', array('user_id' => '9654000769', 'user_name' => 'testfollower1', 'full_name' => 'Twitter Follower One', 'avatar' => 'avatar.jpg', 'follower_count' => 3600000, 'is_protected' => 0, 'network' => 'twitter', 'description' => 'A test Twitter Folower', 'location' => 'San Francisco, CA', 'friend_count' => 360, 'is_verified' => 0));
     $builders[] = FixtureBuilder::build('users', array('user_id' => '9654000770', 'user_name' => 'testfollower2', 'full_name' => 'Twitter Follower Two', 'avatar' => 'avatar.jpg', 'follower_count' => 360, 'is_protected' => 0, 'network' => 'twitter', 'description' => 'A test Twitter Folower', 'location' => 'San Francisco, CA', 'friend_count' => 360, 'is_verified' => 1));
     $builders[] = FixtureBuilder::build('users', array('user_id' => '9654000771', 'user_name' => 'testfollower3', 'full_name' => 'Twitter Follower Three', 'avatar' => 'avatar.jpg', 'follower_count' => 360, 'is_protected' => 0, 'network' => 'twitter', 'description' => 'A test Twitter Folower', 'location' => 'San Diego, CA', 'friend_count' => 360, 'is_verified' => 0));
     // Follows
     $builders[] = FixtureBuilder::build('follows', array('user_id' => '9654000768', 'follower_id' => '9654000769', 'last_seen' => '-0d', 'first_seen' => '-0d', 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => '9654000768', 'follower_id' => '9654000770', 'last_seen' => '-0d', 'first_seen' => '-0d', 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => '9654000768', 'follower_id' => '9654000771', 'last_seen' => '-0d', 'first_seen' => '-0d', 'network' => 'twitter'));
     // Initialize and run the insight
     $insight_plugin = new InterestingFollowersInsight();
     $insight_plugin->generateInsight($instance, $this->getUser(), $posts = array(), 3);
     //sleep(1000);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('local_followers', 10, $today);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertPattern('/@testuser got a new follower in San Francisco, CA/', $result->headline);
     $this->assertPattern('/avatar.jpg/', $result->header_image);
 }
Exemplo n.º 26
0
 public function test1NewListMembershipWithHistory()
 {
     // Assert that insight doesn't exist
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('new_group_memberships', 1, date('Y-m-d'));
     $this->assertNull($result);
     $builders = self::buildData($total_lists = 1, $build_history = true, $history_ceiling = 5);
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_user_id = '13';
     $instance->network = 'twitter';
     $instance->network_username = '******';
     $stylestats_insight_plugin = new ListMembershipInsight();
     $stylestats_insight_plugin->generateInsight($instance, array(), 3);
     // Assert that insight got generated
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('new_group_memberships', 1, date('Y-m-d'));
     $this->assertNotNull($result);
     $this->assertEqual($result->slug, 'new_group_memberships');
     $this->assertEqual($result->headline, 'Made the list:');
     $this->assertEqual($result->filename, 'listmembership');
     $this->assertPattern('/\\@ev is on a new list,/', $result->text);
     $this->assertPattern('/bringing the total to \\<strong\\>6 lists\\<\\/strong\\>./', $result->text);
 }
Exemplo n.º 27
0
 public function testOscars2015OnlyALoserReference()
 {
     // Get data ready that insight requires
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_username = '******';
     $instance->network = 'facebook';
     $builders = self::setUpPublicInsight($instance);
     $builders[] = FixtureBuilder::build('posts', array('post_text' => 'That Jonah Hill sucks.', 'pub_date' => '2015-02-19', 'author_username' => $instance->network_username, 'network' => $instance->network));
     $posts = array();
     $insight_plugin = new Oscars2015Insight();
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('oscars_2015', 1, $today);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNull($result);
 }
 public function testFacebookNoMatch()
 {
     $this->instance->network_username = '******';
     $this->instance->network = 'facebook';
     $year = date('Y');
     $builders = self::setUpPublicInsight($this->instance);
     // post with no pic
     $builders[] = FixtureBuilder::build('posts', array('id' => 10, 'post_id' => 10, 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'author_fullname' => 'Facebook User', 'author_avatar' => 'avatar.jpg', 'network' => $this->instance->network, 'post_text' => 'This is a post http://t.co/B5LAotKMWY with a v popular pic', 'source' => 'web', 'pub_date' => "{$year}-01-01", 'reply_count_cache' => 10, 'is_protected' => false));
     $posts = array();
     $insight_plugin = new EOYPopularPicInsight();
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('eoy_popular_pic', $this->instance->id, $year . '-' . $insight_plugin->run_date);
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $year = date('Y');
     $this->assertEqual("No photos on Facebook?", $result->headline);
     $this->assertEqual("Mark Zuckerberg didn't share any pics on Facebook this year. " . "Bummer! On the plus side: " . "Mark Zuckerberg probably doesn't need to worry about leaked nudes!", $result->text);
     $this->dumpRenderedInsight($result, $this->instance, "No matches, Facebook");
 }
Exemplo n.º 29
0
 public function testNoHealthyShareLikes()
 {
     // Get data ready that insight requires
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $posts = array();
     $posts[] = new Post(array('reply_count_cache' => 5, 'retweet_count_cache' => 15, 'favlike_count_cache' => 3));
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 5, 'favlike_count_cache' => 15));
     $posts[] = new Post(array('reply_count_cache' => 2, 'retweet_count_cache' => 5, 'favlike_count_cache' => 1));
     $insight_dao = new InsightMySQLDAO();
     $insight_plugin = new ResponseTimeInsight();
     TimeHelper::setTime(2);
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     $result = $insight_dao->getInsight('response_time', 10, date('Y-m-d'));
     $this->assertEqual("That's a healthy share of the 21 million tweets each hour.", $result->text);
     $posts = array();
     $posts[] = new Post(array('reply_count_cache' => 5, 'retweet_count_cache' => 15, 'favlike_count_cache' => 13));
     $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 5, 'favlike_count_cache' => 15));
     $posts[] = new Post(array('reply_count_cache' => 2, 'retweet_count_cache' => 5, 'favlike_count_cache' => 15));
     TimeHelper::setTime(2);
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     $result = $insight_dao->getInsight('response_time', 10, date('Y-m-d'));
     $this->assertNotEqual("That's a healthy share of the 21 million tweets each hour.", $result->text);
 }
Exemplo n.º 30
0
 public function testDeleteInsightsBySlug()
 {
     $builders = array();
     $time_now = date("Y-m-d H:i:s");
     $builders[] = FixtureBuilder::build('insights', array('date' => '2012-05-02', 'slug' => 'avg_replies_per_week', 'instance_id' => '1', 'text' => 'Retweet spike! Your post got retweeted 110 times', 'emphasis' => Insight::EMPHASIS_HIGH, 'time_generated' => $time_now));
     $builders[] = FixtureBuilder::build('insights', array('date' => '2012-05-01', 'slug' => 'avg_replies_per_week', 'instance_id' => '2', 'text' => 'Retweet spike! Your post got retweeted 110 times', 'emphasis' => Insight::EMPHASIS_HIGH, 'time_generated' => $time_now));
     $builders[] = FixtureBuilder::build('insights', array('date' => '2012-05-01', 'slug' => 'another_slug', 'instance_id' => '1', 'text' => 'Retweet spike! Your post got retweeted 110 times', 'emphasis' => Insight::EMPHASIS_HIGH, 'time_generated' => $time_now));
     $dao = new InsightMySQLDAO();
     //delete all insights for slug/instance
     $result = $dao->deleteInsightsBySlug('avg_replies_per_week', 1);
     $this->assertTrue($result);
     //check that insights for that slug and instance were deleted
     $result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-01');
     $this->assertNull($result);
     $result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-02');
     $this->assertNull($result);
     //check that insight with that slug but not for another instance were NOT deleted
     $result = $dao->getInsight('avg_replies_per_week', 2, '2012-05-01');
     $this->assertNotNull($result);
     //delete nonexistent slug
     $result = $dao->deleteInsightsBySlug('avg_replies_per_week_another_slug', 1);
     $this->assertFalse($result);
 }