public function testAlternateText()
 {
     TimeHelper::setTime(3);
     // Get data ready that insight requires
     $builders = self::buildDataTeens();
     $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, 5);
     // 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, 'Teens said it all');
     $this->assertEqual($result->text, "Teens — people less than 18 years old — wrote 100% of the " . "comments on Teen Dude's Facebook posts this week.");
     $this->assertEqual($related_data['age_data']['18'], 2);
     $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'], 0);
     $result->id = 1;
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 public function testHelloThinkUpInsight()
 {
     $posts = array();
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_username = '******';
     $instance->network = 'facebook';
     $builders = self::setUpPublicInsight($instance);
     // We have three random options, so we'll check each one here.
     TimeHelper::setTime(3);
     $hello_thinkup_insight_plugin = new HelloThinkUpInsight();
     $hello_thinkup_insight_plugin->generateInsight($instance, null, $posts, 3);
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $result = $insight_dao->getInsight('my_test_insight_hello_thinkup', 1, date('Y-m-d'));
     $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);
     TimeHelper::setTime(4);
     $hello_thinkup_insight_plugin->generateInsight($instance, null, $posts, 3);
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $result = $insight_dao->getInsight('my_test_insight_hello_thinkup', 1, date('Y-m-d'));
     $this->assertEqual($result->headline, 'Hello');
     $this->assertEqual($result->text, 'Greetings, earthlings');
     TimeHelper::setTime(5);
     $hello_thinkup_insight_plugin->generateInsight($instance, null, $posts, 3);
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $result = $insight_dao->getInsight('my_test_insight_hello_thinkup', 1, date('Y-m-d'));
     $this->assertEqual($result->headline, 'Yo');
     $this->assertEqual($result->text, 'Greetings, peeps');
     /**
      * Use this code to output the individual insight's fully-rendered HTML to file.
      * Then, open the file in your browser to view.
      *
      * $ TEST_DEBUG=1 php webapp/plugins/insightsgenerator/tests/TestOfHelloThinkUpInsight.php
      * -t testHelloThinkUpInsight > webapp/insight.html
      */
     $controller = new InsightStreamController();
     $_GET['u'] = 'Katniss Everdeen';
     $_GET['n'] = 'facebook';
     $_GET['d'] = date('Y-m-d');
     $_GET['s'] = 'my_test_insight_hello_thinkup';
     $results = $controller->go();
     //Uncomment this out to see web view of insight
     //$this->debug($results);
     /**
      * Use this code to output the individual insight's fully-rendered email HTML to file.
      * Then, open the file in your browser to view.
      *
      * $ TEST_DEBUG=1 php webapp/plugins/insightsgenerator/tests/TestOfHelloThinkUpInsight.php
      * -t testHelloThinkUpInsight > webapp/insight_email.html
      */
     $email_insight = $this->getRenderedInsightInEmail($result);
     //Uncomment this out to see the email view of insight
     //$this->debug($email_insight);
 }
示例#3
0
 public function testSetClearTime()
 {
     $start = TimeHelper::getTime();
     $this->assertNotEqual($start, 4179);
     TimeHelper::setTime(4179);
     $now = TimeHelper::getTime();
     $this->assertEqual(4179, $now);
     TimeHelper::clearTime();
     $now = TimeHelper::getTime();
     $this->assertNotEqual(4179, $now);
 }
 public function setUp()
 {
     parent::setUp();
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_user_id = 42;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $this->instance = $instance;
     TimeHelper::setTime(1418947200);
     // Set it to the December 2014 words timeframe
 }
 public function setUp()
 {
     parent::setUp();
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_user_id = 42;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $this->instance = $instance;
     TimeHelper::setTime(1425329077);
     // Set it to the March 2015 words timeframe
 }
 public function setUp()
 {
     parent::setUp();
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_user_id = 42;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $this->instance = $instance;
     $this->insight_dao = DAOFactory::getDAO('InsightDAO');
     TimeHelper::setTime(2);
     // Force one headline for most tests
 }
 public function testAlternateHeadline2()
 {
     TimeHelper::setTime(3);
     $builders[] = FixtureBuilder::build('posts', array('id' => 135, 'post_id' => 135, 'author_user_id' => 1234, 'author_username' => $this->instance->network_username, 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => 'twitter', 'post_text' => 'This is a post http://t.co/B5LAotKMWY with a link.', 'source' => 'web', 'pub_date' => date('Y-m-d', strtotime('-8 days')), 'reply_count_cache' => 0, 'is_protected' => 0));
     $builders[] = FixtureBuilder::Build('links', array('post_key' => 135, 'url' => 'http://pic.twitter.com/vx4YL7Yz', 'image_src' => 'http://pic.twitter.com.foo.jpg', 'expanded_url' => ''));
     $insight_plugin = new PhotoPromptInsight();
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $posts = array();
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     $result = $insight_dao->getInsight('photoprompt', $this->instance->id, date('Y-m-d'));
     $this->assertNotNull($result);
     $this->assertEqual("A great time for a pic", $result->headline);
     $this->assertEqual("@anseladams hasn't posted a photo in 8 days. " . "It might be worth finding something to share.", $result->text);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 /**
  * This test will fail on PHP 5.3, which won't display the diff with the bullet point correctly in the rendered HTML
  */
 public function testDiffEncoding()
 {
     $builders = array();
     // User
     $builders[] = FixtureBuilder::build('users', array('user_id' => '1', 'user_name' => 'nosey', 'full_name' => 'Twitter User', 'follower_count' => 1, 'is_protected' => 1, 'id' => 1, 'avatar' => 'https://pbs.twimg.com/profile_images/476939811702718464/Qq0LPfRy_400x400.jpeg', 'network' => 'twitter', 'description' => 'A test Twitter User', 'location' => 'San Francisco, CA'));
     // Friend
     $builders[] = FixtureBuilder::build('users', array('user_id' => '2', 'user_name' => 'newlywed', 'post_count' => 101, 'follower_count' => 36000, 'is_protected' => 0, 'friend_count' => 1, 'full_name' => 'Popular Gal', 'avatar' => 'https://pbs.twimg.com/profile_images/476939811702718464/Qq0LPfRy_400x400.jpeg', 'id' => 2, 'network' => 'twitter', 'description' => 'Cofounder @thinkup & @activateinc • Writer @Medium', 'location' => 'San Francisco, CA', 'is_verified' => 0));
     // Follows
     $builders[] = FixtureBuilder::build('follows', array('user_id' => '2', 'follower_id' => '1', 'last_seen' => '-0d', 'first_seen' => '-0d', 'network' => 'twitter', 'active' => 1));
     // Change
     $builders[] = FixtureBuilder::build('user_versions', array('user_key' => 2, 'field_name' => 'description', 'field_value' => "Cofounder @thinkup & @activateinc • Writer @Medium & @Wired • " . 'Blog: http://t.co/5p9HDVJDna • anil@dashes.com • 646 833-8659 • Sign up: https://t.co/1m3JNdJKwy', 'crawl_time' => '-2d'));
     $builders[] = FixtureBuilder::build('user_versions', array('user_key' => 3, 'field_name' => 'description', 'field_value' => "Cofounder @thinkup & @activateinc • Writer @Medium & @Wired", 'crawl_time' => '-3d'));
     $user_dao = DAOFactory::getDAO('UserDAO');
     $user = $user_dao->getDetailsByUserKey(1);
     $insight_plugin = new BioTrackerInsight();
     $insight_dao = new InsightMySQLDAO();
     TimeHelper::setTime(1);
     $insight_plugin->generateInsight($this->instance, $user, $posts, 3);
     $result = $insight_dao->getInsight($insight_plugin->slug_bio, 10, $this->today);
     $this->assertNotNull($result);
     $rendered_html = $this->getRenderedInsightInHTML($result);
     $this->assertPattern('/Cofounder @thinkup & @activateinc • Writer /', $rendered_html);
     $this->debug($rendered_html);
 }
 public function testAlternateText()
 {
     TimeHelper::setTime(1);
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $post_builders = array();
     $post_builders[] = FixtureBuilder::build('posts', array('author_username' => 'testy', 'network' => 'twitter', 'post_text' => 'Thanks thank you thanks a lot!.', 'pub_date' => date('Y-m-d')));
     $insight_plugin = new ThanksCountInsight();
     $today = date('Y-m-d');
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today);
     $this->assertNotNull($result);
     $this->assertPattern('/\\@testy tweeted <strong>1 thank-you<\\/strong> last month./', $result->text);
     $post_builders[] = FixtureBuilder::build('posts', array('author_username' => 'testy', 'network' => 'twitter', 'post_text' => 'Thanks thank you thanks a lot!.', 'pub_date' => date('Y-m-d')));
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today);
     $this->assertNotNull($result);
     $this->assertPattern('/\\@testy tweeted <strong>2 thank-yous<\\/strong> last month./', $result->text);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 public function testBadJoinDate()
 {
     $insight_plugin = new TwitterBirthdayInsight();
     TimeHelper::setTime(1 + 365 * 24 * 60 * 60);
     $user = $this->makeUser('hbtome', date('r', 1));
     $insight_plugin->generateInsight($this->instance, $user, array(), 3);
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('twitterbirthday', 10, $today);
     $this->assertNull($result);
 }
 public function testPhotoSkipping()
 {
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $post_builders = array();
     $days_ago_3 = date('Y-m-d H:i:s', strtotime('-3 days'));
     $builders[] = FixtureBuilder::build('posts', array('id' => 444, 'post_id' => 444, 'author_user_id' => 7612345, 'author_username' => 'testeriffic', 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'in_reply_to_user_id' => NULL, 'in_retweet_of_post_id' => NULL, 'network' => 'twitter', 'post_text' => 'This is an old post http://www.aaa.com/1 with a link.', 'source' => 'web', 'pub_date' => $days_ago_3, 'reply_count_cache' => 0, 'is_protected' => 0));
     $builders[] = FixtureBuilder::build('links', array('url' => 'http://www.aaaa.com/', 'title' => 'Link 1', 'post_key' => 444, 'expanded_url' => 'http://www.aaaa.com/', 'error' => '', 'image_src' => 'http://photo.com/photo.jpg'));
     TimeHelper::setTime(2);
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_user_id = 7612345;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $insight_plugin = new DiversifyLinksInsight();
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('diversify_links_monthly', 10, $today);
     $this->assertNull($result);
     $builders[] = FixtureBuilder::build('posts', array('id' => 445, 'post_id' => 445, 'author_user_id' => 7612345, 'author_username' => 'testeriffic', 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'in_reply_to_user_id' => NULL, 'in_retweet_of_post_id' => NULL, 'network' => 'twitter', 'post_text' => 'This is an old post http://www.aaa.com/1 with a link.', 'source' => 'web', 'pub_date' => $days_ago_3, 'reply_count_cache' => 0, 'is_protected' => 0));
     $builders[] = FixtureBuilder::build('links', array('url' => 'http://www.aaaa.com/', 'title' => 'Link 1', 'post_key' => 445, 'expanded_url' => 'http://www.aaaa.com/', 'error' => '', 'image_src' => ''));
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     $result = $insight_dao->getInsight('diversify_links_monthly', 10, $today);
     $this->assertEqual($result->text, 'It was the best of tabs, it was the worst of tabs. @testeriffic tweeted ' . '1 link to aaaa.com this month.');
     $this->assertEqual("@testeriffic's most linked-to site this month", $result->headline);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 public function testHeadlines()
 {
     $posts = self::getTestPostObjects();
     $insight_plugin = new AllAboutYouInsight();
     $today = date('Y-m-d');
     $insight_plugin = new AllAboutYouInsight();
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $good_headlines = array(null, 'Sometimes it\'s all about @testeriffic', 'It\'s getting personal', 'A moment of self-reflection', 'Sometimes Twitter is a first-person story', 'A story about @testeriffic');
     for ($i = 1; $i <= 5; $i++) {
         TimeHelper::setTime($i);
         $insight_plugin->generateInsight($this->instance, null, $posts, 3);
         $result = $insight_dao->getInsight('all_about_you', 10, $today);
         $this->assertEqual($result->headline, $good_headlines[$i]);
     }
 }
 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, "");
 }
 public function testWeeklyBestsInsightWithRepliesAndFavorites()
 {
     // Get data ready that insight requires
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $builders = self::setUpPublicInsight($instance);
     $posts = array();
     $posts[] = new Post(array('reply_count_cache' => 4, 'retweet_count_cache' => 0, 'favlike_count_cache' => 5, 'post_text' => 'This is a really good post', 'author_username' => $instance->network_username, 'author_user_id' => 'abc', 'author_avatar' => 'http://example.com/example.jpg', 'network' => $instance->network, 'pub_date' => date('Y-m-d H:i:s', strtotime('-1 day'))));
     // popularity_index = 30
     TimeHelper::setTime(1);
     $insight_plugin = new WeeklyBestsInsight();
     $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('weekly_best', 10, $today);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertPattern('/\\@testeriffic\'s most popular tweet last week/', $result->headline);
     $this->assertPattern('/4 replies/', $result->text);
     $this->assertPattern('/5 favorites/', $result->text);
     $this->assertPattern('/and/', $result->text);
     /**
      * Use this code to output the individual insight's fully-rendered email HTML to file.
      * Then, open the file in your browser to view.
      *
      * $ TEST_DEBUG=1 php webapp/plugins/insightsgenerator/tests/TestOfHelloThinkUpInsight.php
      * -t testHelloThinkUpInsight > webapp/insight_email.html
      */
     $result->related_data = unserialize($result->related_data);
     $email_insight = $this->getRenderedInsightInEmail($result);
     //Uncomment this out to see the email view of insight
     $this->debug($email_insight);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->assertPattern('/This is a really good post/', $email_insight);
 }
 public function testAlternateHeadlines()
 {
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $post_builders = array();
     $post_builders[] = FixtureBuilder::build('posts', array('author_username' => 'screamy', 'network' => 'twitter', 'post_text' => 'Woo!', 'pub_date' => date('Y-m-d')));
     $insight_plugin = new ExclamationCountInsight();
     $today = date('Y-m-d');
     $headlines = array('', 'OMG @screamy is serious!', '30 days of !!!');
     for ($i = 1; $i < 3; $i++) {
         TimeHelper::setTime($i);
         $insight_plugin->generateInsight($this->instance, null, $posts, 3);
         $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today);
         $this->assertNotNull($result);
         $this->assertEqual($result->headline, $headlines[$i]);
         $this->assertNull($result->related_data);
     }
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
示例#16
0
 public function testFlashbackInsightForFacebookMoreThanAYearAgo()
 {
     // Get data ready that insight requires
     $builders = self::buildData();
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_user_id = '765432fc';
     $instance->network_username = '******';
     $instance->network = 'facebook';
     $insight_plugin = new FlashbackInsight();
     TimeHelper::setTime(2);
     $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('posts_on_this_day_popular_flashback', 10, $today);
     $fav_posts = unserialize($result->related_data);
     //$this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertPattern('/3 years ago today/', $result->headline);
     $last_year = date('Y') - 1;
     $this->assertEqual("On this day in 2013, this was testeriffic's most popular status update.", $result->text);
     $this->assertIsA($fav_posts, "array");
     $this->assertIsA($fav_posts["posts"][0], "Post");
     $this->assertEqual(count($fav_posts), 1);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 public function testEarlyAdopterV2()
 {
     TimeHelper::setTime(1399686338);
     $plugin = new TwitterAgeInsight();
     $plugin->generateInsight($this->instance, $this->makeUser('2009-09-12'), array(), 1);
     $result = $this->insight_dao->getInsight('twitter_age', $this->instance->id, date('Y-m-d'));
     $this->assertNotNull($result);
     $this->assertEqual('Somebody is an early bird!', $result->headline);
     // Don't assert exact number of years/months/weeks because they will change over time
     $this->assertPattern("/\\@princesspeach joined Twitter/", $result->text);
     $this->assertPattern("/That\\'s over/", $result->text);
     $this->assertPattern("/\\% of Twitter's lifetime\\!/", $result->text);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 public function testSingularV4()
 {
     TimeHelper::setTime(4);
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $post_builders = array();
     $post_builders[] = FixtureBuilder::build('posts', array('post_id' => 1, 'author_username' => 'friend1', 'network' => 'twitter', 'post_text' => 'I am getting married!', 'pub_date' => date('Y-m-d')));
     // 1 Congrat, 1 users, 1 available posts
     $post_builders[] = FixtureBuilder::build('posts', array('in_reply_to_user_id' => 9999, 'in_reply_to_post_id' => 1, 'author_username' => 'janesmith', 'network' => 'twitter', 'post_text' => 'Congrats!', 'pub_date' => date('Y-m-d')));
     $insight_plugin = new CongratsCountInsight();
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today);
     $this->assertNotNull($result);
     $this->assertEqual($result->headline, "A congrats-worthy tweet");
     $this->assertEqual($result->text, "1 tweet inspired @janesmith to congratulate someone this past month.");
     $data = unserialize($result->related_data);
     $this->assertEqual(count($data['posts']), 1);
     $this->assertEqual("I am getting married!", $data['posts'][0]->post_text);
     $this->assertEqual("friend1", $data['posts'][0]->author_username);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 public function testAlternateHeadlines()
 {
     $builders = array();
     for ($i = 0; $i < 1000; $i++) {
         $builders[] = FixtureBuilder::build('users', array('user_id' => 1000 + $i, 'follower_count' => 10 * $i));
         $builders[] = FixtureBuilder::build('follows', array('user_id' => 1000 + $i, 'follower_id' => 42, 'active' => 1, 'last_seen' => '-1d', 'network' => 'twitter'));
     }
     $user = new User(array('follower_count' => 8000, 'user_id' => 42, 'network' => 'twitter'));
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $insight_plugin = new FollowerComparisonInsight();
     for ($i = 2; $i <= 4; $i++) {
         TimeHelper::setTime($i);
         $insight_plugin->generateInsight($this->instance, $user, array(), 3);
         $today = date('Y-m-d');
         $result = $insight_dao->getInsight($this->slug, $this->instance->id, $today);
         $this->assertNotNull($result);
         $this->debug($this->getRenderedInsightInHTML($result));
         $this->debug($this->getRenderedInsightInEmail($result));
         if ($i == 2) {
             $this->assertEqual($result->headline, '@testy could lend a hand');
             $this->assertEqual($result->text, '@testy has more followers than 80% of the 1,000 people @testy ' . "follows. That means <strong>800</strong> of @testy's friends would reach a bigger audience if " . "@testy retweeted them.");
         } else {
             if ($i == 3) {
                 $this->assertEqual($result->headline, '@testy has it good');
                 $this->assertEqual($result->text, '@testy has more followers than 80% of the people @testy ' . "follows. That means <strong>800</strong> of @testy's friends would reach a bigger audience if " . "@testy retweeted them.");
             } else {
                 if ($i == 4) {
                     $this->assertEqual($result->headline, "A closer look at @testy's follower count");
                     $this->assertEqual($result->text, '@testy has more followers than 80% of the 1,000 people @testy ' . "follows. That means <strong>800</strong> of @testy's friends would reach a bigger audience " . "if @testy retweeted them.");
                 }
             }
         }
     }
 }
 public function testInsightV6WithFormattedNumber()
 {
     TimeHelper::setTime(34);
     $yesterday = date('Y-m-d', strtotime('-1 day'));
     $this->instance->network_user_id = 48;
     $posts = array();
     $posts[] = new Post(array('id' => 1, 'post_text' => 'A Post', 'author_user_id' => $this->instance->network_user_id, 'author_username' => 'lowfollowers', 'author_full_name' => 'The Retweetee', 'in_retweet_of_post_id' => 1, 'in_rt_of_user_id' => 47, 'network' => 'twitter', 'pub_date' => $yesterday));
     $insight_plugin = new AmplifierInsight();
     $insight_plugin->generateInsight($this->instance, self::makeUser(1000000), $posts, 3);
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $result = $insight_dao->getInsight('top_amplifier', $this->instance->id, date('Y-m-d'));
     $this->assertNotNull($result);
     $this->assertEqual($result->headline, '100,000x more people saw @tester\'s tweet thanks to @tester');
     $data = unserialize($result->related_data);
     $this->assertEqual(count($data['people']), 1);
     $this->assertEqual($data['people'][0]->username, 'tester');
     $this->assertEqual($data['people'][0]->user_id, 47);
     $this->assertEqual(count($data['posts']), 1);
     $this->assertEqual($data['posts'][0]->post_text, 'A Post');
     $this->debug($this->getRenderedInsightInEmail($result));
     $this->debug($this->getRenderedInsightInHTML($result));
 }
 public function testFrequencyInsightPriorSmallerBy1Baseline()
 {
     // Get data ready that insight requires
     $posts = self::getTestPostObjects();
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $insight_plugin = new FrequencyInsight();
     $user = new User();
     $user->avatar = 'https://farm7.staticflickr.com/6146/5976784449_4fe7c02760_q.jpg';
     // 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' => 'frequency', 'instance_id' => 10, 'value' => 4));
     // Assert that week-over-week comparison is correct
     $insight_dao = new InsightMySQLDAO();
     foreach (array(1, 2, 3) as $modded_time) {
         TimeHelper::setTime($modded_time);
         $insight_plugin->generateInsight($instance, $user, $posts, 3);
         $today = date('Y-m-d');
         $result = $insight_dao->getInsight('frequency', 10, $today);
         //$this->debug(Utils::varDumpToString($result));
         $this->assertNotNull($result);
         $this->assertIsA($result, "Insight");
         $this->assertNotNull($result->time_generated);
         if ($modded_time == 3) {
             $this->assertEqual('@testeriffic tweeted <strong>5 times</strong> in the past week', $result->headline);
         } else {
             $this->assertEqual('@testeriffic had <strong>5 tweets</strong> over the past week', $result->headline);
         }
         $this->assertPattern('/1 more tweet than the prior week/', $result->text);
         $this->debug($this->getRenderedInsightInHTML($result));
         $this->debug($this->getRenderedInsightInEmail($result));
     }
 }
 public function testVariableFuckCountInHeadline()
 {
     TimeHelper::setTime(3);
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $post_builders = array();
     $post_builders[] = FixtureBuilder::build('posts', array('author_username' => 'testy', 'network' => 'twitter', 'post_text' => 'f**k', 'pub_date' => date('Y-m-d')));
     $post_builders[] = FixtureBuilder::build('posts', array('author_username' => 'testy', 'network' => 'facebook', 'post_text' => 'f**k', 'pub_date' => date('Y-m-d')));
     $insight_plugin = new FBombCountInsight();
     $today = date('Y-m-d');
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today);
     $this->assertEqual($result->headline, '@testy really gave a f**k');
     $post_builders[] = FixtureBuilder::build('posts', array('author_username' => 'testy', 'network' => 'twitter', 'post_text' => 'f**k', 'pub_date' => date('Y-m-d')));
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today);
     $this->assertEqual($result->headline, 'F-bombs rain from the sky');
     TimeHelper::setTime(1);
 }
 public function testGetEmailMessageSubjectLine()
 {
     // High emphasis insights
     $insights = array();
     $insight_high = new Insight();
     $insight_high->headline = "This is a <strong>high emphasis</strong> insight for @joeuser&hellip;";
     $insight_high->emphasis = Insight::EMPHASIS_HIGH;
     $instance = new Instance();
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $insight_high->instance = $instance;
     $insights[] = $insight_high;
     $plugin = new InsightsGeneratorPlugin();
     //Get headline as subject line
     TimeHelper::setTime(1);
     $result = $plugin->getEmailMessageSubjectLine('weekly', $insights);
     $this->assertEqual($result, 'This is a high emphasis insight for you…');
     //Headlines as subject lines when med/high exist at all times now
     TimeHelper::setTime(2);
     $result = $plugin->getEmailMessageSubjectLine('weekly', $insights);
     $this->assertEqual($result, 'This is a high emphasis insight for you…');
     // Mediun and low emphasis insights
     $insights = array();
     $insight_med = new Insight();
     $insight_med->headline = "This is a medium emphasis&mdash;insight for @joeuser";
     $insight_med->emphasis = Insight::EMPHASIS_MED;
     $instance = new Instance();
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $insight_med->instance = $instance;
     $insights[] = $insight_med;
     $insight_low = new Insight();
     $insight_low->headline = "This is a medium emphasis insight for @joeuser";
     $insight_low->emphasis = Insight::EMPHASIS_LOW;
     $insights[] = $insight_low;
     TimeHelper::setTime(1);
     $result = $plugin->getEmailMessageSubjectLine('weekly', $insights);
     $this->assertEqual($result, 'This is a medium emphasis—insight for you');
     //No high or medium insights
     $insights = array();
     $insight_low_1 = new Insight();
     $insight_low_1->headline = "This is a low emphasis insight for @joeuser";
     $insight_low_1->emphasis = Insight::EMPHASIS_LOW;
     $insights[] = $insight_low_1;
     $insight_low_2 = new Insight();
     $insight_low_2->headline = "This is a low emphasis insight for @joeuser";
     $insight_low_2->emphasis = Insight::EMPHASIS_LOW;
     $insights[] = $insight_low_2;
     //Weekly
     $good_weekly_subjects = array(1 => "How did you do online this week? Here are your ThinkUp insights", 2 => "Your ThinkUp insights this week", 3 => "New ThinkUp insights are ready for you", 4 => "This week's ThinkUp insights", 5 => "This week was great! ThinkUp's got details", 6 => "How did you do online this week? Here are your ThinkUp insights");
     for ($i = 1; $i <= 6; $i++) {
         TimeHelper::setTime($i);
         $result = $plugin->getEmailMessageSubjectLine('Weekly', $insights);
         $this->assertEqual($result, $good_weekly_subjects[$i]);
     }
     //Daily
     $good_daily_subjects = array(1 => "You have new insights from ThinkUp", 2 => "Your new insights from ThinkUp", 3 => "New ThinkUp insights are ready for you", 4 => "These are your latest ThinkUp insights", 5 => "A few new ThinkUp insights for you", 6 => "New ThinkUp insights are waiting for you", 7 => "ThinkUp: Today's insights", 8 => "These are your ThinkUp insights for " . date('l', $plugin->current_timestamp), 9 => "ThinkUp found 2 insights for you today. Here's a look.", 10 => "You have 2 new insights from ThinkUp", 11 => "ThinkUp has new insights for you! Take a look");
     for ($i = 1; $i <= 11; $i++) {
         TimeHelper::setTime($i);
         $result = $plugin->getEmailMessageSubjectLine('Daily', $insights);
         $this->assertEqual($result, $good_daily_subjects[$i]);
     }
     //Daily with just one insight
     //No high or medium insights
     $insights = array();
     $insight_low_1 = new Insight();
     $insight_low_1->headline = "This is a low emphasis insight for @joeuser";
     $insight_low_1->emphasis = Insight::EMPHASIS_LOW;
     $insights[] = $insight_low_1;
     $good_daily_subjects = array(1 => "You have new insights from ThinkUp", 2 => "Your new insights from ThinkUp", 3 => "New ThinkUp insights are ready for you", 4 => "These are your latest ThinkUp insights", 5 => "A few new ThinkUp insights for you", 6 => "New ThinkUp insights are waiting for you", 7 => "ThinkUp: Today's insights", 8 => "These are your ThinkUp insights for " . date('l', $plugin->current_timestamp), 9 => "ThinkUp has new insights for you! Take a look", 10 => "You have new insights from ThinkUp", 11 => "Your new insights from ThinkUp");
     // Ensure we skip over the subjects involving the count to avoid pluralization issues
     for ($i = 1; $i <= 11; $i++) {
         TimeHelper::setTime($i);
         $result = $plugin->getEmailMessageSubjectLine('Daily', $insights);
         $this->assertEqual($result, $good_daily_subjects[$i]);
     }
 }
 public function testAlternateText()
 {
     TimeHelper::setTime(2);
     $instance = $this->createInstance('2012-01-01');
     $insight_plugin = new FacebookProfilePromptInsight();
     $insight_plugin->generateInsight($instance, new User(), array(), 3);
     $result = $this->insight_dao->getInsight('facebook_profile_prompt', $instance->id, date('Y-m-d'));
     $this->assertNotNull($result);
     $this->assertPattern("/Jon Snow's \\d+-month-old profile/", $result->headline);
     $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 testAlternateHeadlines()
 {
     TimeHelper::setTime(1);
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $post_builders = array();
     $post_builders[] = FixtureBuilder::build('posts', array('author_username' => 'testy', 'network' => 'twitter', 'post_text' => 'LOL', 'pub_date' => date('Y-m-d')));
     $insight_plugin = new LOLCountInsight();
     $today = date('Y-m-d');
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today);
     $this->assertNotNull($result);
     $this->assertEqual($result->headline, 'LOL activity detected');
     TimeHelper::setTime(2);
     $insight_plugin->generateInsight($this->instance, null, $posts, 3);
     $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today);
     $this->assertNotNull($result);
     $last_month = Date('F', strtotime(date('F') . " last month"));
     $this->assertEqual($result->headline, 'The LOLs of ' . $last_month);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 public function testAlternateHeadlinesFacebook()
 {
     $this->instance->network = 'facebook';
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $posts = array(new Post(array('post_text' => 'Behold my news feed and weep.')));
     $insight_plugin = new MetaPostsCountInsight();
     TimeHelper::setTime(1);
     $insight_plugin->generateInsight($this->instance, null, $posts, 7);
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today);
     $this->assertEqual($result->headline, "1 status update about Facebook");
     $this->assertEqual($result->text, "reflection used Facebook to talk about Facebook once this " . "week. That's 100% of reflection's status updates for the week.");
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
     TimeHelper::setTime(2);
     $insight_plugin->generateInsight($this->instance, null, $posts, 7);
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today);
     $this->assertEqual($result->headline, "It's Facebook all the way down");
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
     TimeHelper::setTime(3);
     $insight_plugin->generateInsight($this->instance, null, $posts, 7);
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today);
     $this->assertEqual($result->headline, "1 status update about Facebook");
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 public function testAlternateText()
 {
     TimeHelper::setTime(3);
     $builders = array();
     $builders[] = FixtureBuilder::build('users', array('user_id' => '13', 'user_name' => 'ev', 'full_name' => 'Ev Williams', 'avatar' => 'avatar.jpg', 'is_protected' => 0, 'follower_count' => 70, 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('groups', array('group_id' => 14, 'network' => 'twitter', 'is_active' => 1, 'first_seen' => '-2d', 'group_name' => '@listmaker/list2'));
     $builders[] = FixtureBuilder::build('group_members', array('group_id' => 14, 'member_user_id' => '13', 'network' => 'twitter', 'is_active' => 1, 'first_seen' => '-2d'));
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_user_id = '13';
     $instance->network = 'twitter';
     $instance->network_username = '******';
     $insight_plugin = new ListMembershipInsight();
     $insight_plugin->generateInsight($instance, null, array(), 3);
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     $result = $insight_dao->getInsight('new_group_memberships', 1, date('Y-m-d'));
     $this->assertNotNull($result);
     $this->assertEqual("A new list for @ev's collection", $result->headline);
     $this->assertEqual('@ev got added to a new list, <a href="http://twitter.com/listmaker/list2">list2</a>.', $result->text);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
     $builders[] = FixtureBuilder::build('groups', array('group_id' => 13, 'network' => 'twitter', 'is_active' => 1, 'first_seen' => '-3d', 'group_name' => '@listmaker/list1'));
     $builders[] = FixtureBuilder::build('group_members', array('group_id' => 13, 'member_user_id' => '13', 'network' => 'twitter', 'is_active' => 1, 'first_seen' => '-3d'));
     $deleted = $insight_dao->deleteInsightsBySlug('new_group_memberships', 1);
     $insight_plugin->generateInsight($instance, null, array(), 3);
     $result = $insight_dao->getInsight('new_group_memberships', 1, date('Y-m-d'));
     $this->assertNotNull($result);
     $this->assertEqual("2 new lists for @ev's collection", $result->headline);
     $this->assertEqual('@ev is on 2 new lists: <a href="http://twitter.com/listmaker/list2">list2</a> ' . 'and <a href="http://twitter.com/listmaker/list1">list1</a>.', $result->text);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 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);
 }
 public function testGenderAnalysisForFacebookEqualReactionV3()
 {
     TimeHelper::setTime(3);
     // Get data ready that insight requires
     $builders = self::buildData('all');
     $instance = new Instance();
     $instance->id = 100;
     $instance->network_user_id = '8654321';
     $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 GenderAnalysisInsight();
     $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('gender_analysis', 100, $today);
     $gender_data = unserialize($result->related_data);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertEqual($result->headline, 'Both genders reacted to Gloria Steinem\'s status updates equally');
     $this->assertEqual($result->text, 'This past week, people who identify as male and female liked and ' . 'commented on Gloria Steinem\'s status updates at the same rate.');
     $this->assertIsA($gender_data, "array");
     $this->assertEqual(count($gender_data), 1);
     $this->assertEqual($gender_data['pie_chart']['female'], 4);
     $this->assertEqual($gender_data['pie_chart']['male'], 4);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }