示例#1
0
 public function test30DayAverage()
 {
     $insight_dao = new InsightMySQLDAO();
     $post1 = FixtureBuilder::build('posts', array('id' => 1, 'post_id' => '1', 'author_username' => 'ev', 'post_text' => 'My Great Video 1', 'pub_date' => '-85d', 'network' => 'youtube', 'in_reply_to_post_id' => null, 'in_reply_to_user_id' => null));
     $video1 = FixtureBuilder::build('videos', array('id' => 1, 'post_key' => '1', 'views' => 800));
     $post2 = FixtureBuilder::build('posts', array('id' => 2, 'post_id' => '2', 'author_username' => 'ev', 'post_text' => 'My Great Video 2', 'pub_date' => '-2d', 'network' => 'youtube', 'in_reply_to_post_id' => null, 'in_reply_to_user_id' => null));
     $video2 = FixtureBuilder::build('videos', array('id' => 2, 'post_key' => '2', 'views' => 40));
     $post3 = FixtureBuilder::build('posts', array('id' => 3, 'post_id' => '3', 'author_username' => 'ev', 'post_text' => 'My Great Video 3', 'pub_date' => '-3d', 'network' => 'youtube', 'in_reply_to_post_id' => null, 'in_reply_to_user_id' => null));
     $video3 = FixtureBuilder::build('videos', array('id' => 3, 'post_key' => '3', 'views' => 30));
     $post4 = FixtureBuilder::build('posts', array('id' => 4, 'post_id' => '4', 'author_username' => 'ev', 'post_text' => 'My Great Video 4', 'pub_date' => '-1d', 'network' => 'youtube', 'in_reply_to_post_id' => null, 'in_reply_to_user_id' => null));
     $video4 = FixtureBuilder::build('videos', array('id' => 4, 'post_key' => '4', 'views' => 400));
     $posts[] = new Post($post2->columns);
     $posts[] = new Post($post3->columns);
     $posts[] = new Post($post4->columns);
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_user_id = '1';
     $instance->network = 'youtube';
     $instance->network_username = '******';
     $view_spike_insight = new ViewSpikeInsight();
     $view_spike_insight->generateInsight($instance, $posts, 7);
     // Check the insight was created
     $check = $insight_dao->getInsight('view_spike_30_day_4', 1, date('Y-m-d', strtotime('-1 day')));
     $this->assertNotNull($check);
     $this->assertEqual($check->slug, 'view_spike_30_day_4');
     $this->assertEqual($check->headline, 'Viral video:');
     $text = "<strong>400 people</strong> viewed <a href=http://plus.google.com/1>ev</a>'s video <a href=http://www";
     $text .= ".youtube.com/watch?v=4>My Great Video 4</a>, more than <strong>double</strong> the 30-day average.";
     $this->assertEqual($check->text, $text);
     $this->assertEqual($check->emphasis, 0);
     $this->assertEqual($check->filename, 'viewspike');
 }
 public function test30DayAverage()
 {
     $insight_dao = new InsightMySQLDAO();
     $post1 = FixtureBuilder::build('posts', array('id' => 1, 'post_id' => '1', 'author_username' => 'ev', 'post_text' => 'My Great Video 1', 'pub_date' => '-85d', 'network' => 'youtube', 'in_reply_to_post_id' => null, 'in_reply_to_user_id' => null));
     $video1 = FixtureBuilder::build('videos', array('id' => 1, 'post_key' => '1', 'views' => 800));
     $post2 = FixtureBuilder::build('posts', array('id' => 2, 'post_id' => '2', 'author_username' => 'ev', 'post_text' => 'My Great Video 2', 'pub_date' => '-2d', 'network' => 'youtube', 'in_reply_to_post_id' => null, 'in_reply_to_user_id' => null));
     $video2 = FixtureBuilder::build('videos', array('id' => 2, 'post_key' => '2', 'views' => 40));
     $post3 = FixtureBuilder::build('posts', array('id' => 3, 'post_id' => '3', 'author_username' => 'ev', 'post_text' => 'My Great Video 3', 'pub_date' => '-3d', 'network' => 'youtube', 'in_reply_to_post_id' => null, 'in_reply_to_user_id' => null));
     $video3 = FixtureBuilder::build('videos', array('id' => 3, 'post_key' => '3', 'views' => 30));
     $post4 = FixtureBuilder::build('posts', array('id' => 4, 'post_id' => '4', 'author_username' => 'ev', 'post_text' => 'My Great Video 4', 'pub_date' => '-1d', 'network' => 'youtube', 'in_reply_to_post_id' => null, 'in_reply_to_user_id' => null));
     $video4 = FixtureBuilder::build('videos', array('id' => 4, 'post_key' => '4', 'views' => 400));
     $posts[] = new Post($post2->columns);
     $posts[] = new Post($post3->columns);
     $posts[] = new Post($post4->columns);
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_user_id = '1';
     $instance->network = 'youtube';
     $instance->network_username = '******';
     $view_spike_insight = new ViewSpikeInsight();
     $view_spike_insight->generateInsight($instance, null, $posts, 7);
     // Check the insight was created
     $check = $insight_dao->getInsight('view_spike_30_day_4', 1, date('Y-m-d', strtotime('-1 day')));
     $this->assertNotNull($check);
     $this->assertEqual($check->slug, 'view_spike_30_day_4');
     $headline = "<strong>400 people</strong> viewed My Great Video 4";
     $headline .= " &mdash; looks like it's doing pretty well.";
     $this->assertEqual($check->headline, $headline);
     $this->assertEqual($check->emphasis, 0);
     $this->assertEqual($check->filename, 'viewspike');
 }