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); }
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 testGenderAnalysisForFacebookLessThanThreeGenderDataBits() { // Get data ready that insight requires $builders = array(); // Build users $builders[] = FixtureBuilder::build('users', array('user_id' => '9654321', 'user_name' => 'Gloria Steinem', 'full_name' => 'Gloria Steinem', 'gender' => 'female', 'avatar' => 'avatar.jpg', 'is_protected' => 0, 'network' => $network)); $builders[] = FixtureBuilder::build('users', array('user_id' => '9654320', 'user_name' => 'Abraham Lincoln', 'full_name' => 'Abraham Lincoln', 'gender' => 'male', 'avatar' => 'avatar.jpg', 'is_protected' => 0, 'network' => $network)); // Posts $builders[] = FixtureBuilder::build('posts', array('id' => 333, 'post_id' => 333, 'author_user_id' => '9654321', 'author_username' => 'Gloria Steinem', 'author_fullname' => 'Gloria Steinem', 'author_avatar' => 'avatar.jpg', 'network' => $network, 'post_text' => 'This is a simple post.', 'pub_date' => '-1d', 'reply_count_cache' => 3, 'is_protected' => 0, 'favlike_count_cache' => 2)); $builders[] = FixtureBuilder::build('posts', array('id' => 334, 'post_id' => 334, 'author_user_id' => '9654321', 'author_username' => 'Gloria Steinem', 'author_fullname' => 'Gloria Steinem', 'author_avatar' => 'avatar.jpg', 'network' => $network, 'post_text' => 'This is a simple comment.', 'pub_date' => '-2h', 'reply_count_cache' => 0, 'is_protected' => 0, 'favlike_count_cache' => 0, 'in_reply_to_post_id' => 333)); $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); $this->assertNull($result); }