public function authControl()
 {
     Session::logout();
     $controller = new InsightStreamController(true);
     $controller->addSuccessMessage("You have successfully logged out.");
     return $controller->go();
 }
 public function authControl()
 {
     Session::logout();
     if (!$this->redirectToThinkUpLLCEndpoint('logout.php')) {
         $controller = new InsightStreamController(true);
         $controller->addSuccessMessage("You have successfully logged out.");
         return $controller->go();
     }
 }
 /**
  * Bounce user to public page or to error page.
  * @TODO bounce back to original action once signed in
  */
 protected function bounce()
 {
     $config = Config::getInstance();
     if (get_class($this) == 'InsightStreamController' || get_class($this) == 'PostController') {
         $controller = new InsightStreamController(true);
         return $controller->go();
     } else {
         throw new ControllerAuthException('You must log in to access this controller: ' . get_class($this));
     }
 }
 public function control()
 {
     if ($this->isLoggedIn()) {
         $controller = new InsightStreamController(true);
         return $controller->go();
     } else {
         // register form validation
         $this->addHeaderCSS('assets/css/validate_password.css');
         $this->addHeaderJavaScript('assets/js/jquery.validate.min.js');
         $this->addHeaderJavaScript('assets/js/jquery.validate.password.js');
         $this->addHeaderJavaScript('assets/js/validate_password.js');
         $config = Config::getInstance();
         $is_registration_open = $config->getValue('is_registration_open');
         $this->disableCaching();
         $invite_dao = DAOFactory::getDAO('InviteDAO');
         if (isset($_GET['code'])) {
             $invite_code = $_GET['code'];
         } else {
             $invite_code = null;
         }
         $this->addToView('invite_code', $invite_code);
         $is_invite_code_valid = $invite_dao->isInviteValid($invite_code);
         if ($invite_code != null && $is_invite_code_valid) {
             $this->addSuccessMessage("Welcome, VIP! You've been invited to register on " . $config->getValue('app_title_prefix') . "ThinkUp.");
         }
         $has_been_registered = false;
         if (!$is_registration_open && !$is_invite_code_valid) {
             $this->addToView('closed', true);
             $disable_xss = true;
             $this->addErrorMessage('<p>Sorry, registration is closed on this installation of ' . $config->getValue('app_title_prefix') . "ThinkUp.</p>" . '<p><a href="http://thinkup.com" class="btn">Install ThinkUp on your own server.</a></p>', null, $disable_xss);
         } else {
             $owner_dao = DAOFactory::getDAO('OwnerDAO');
             $this->addToView('closed', false);
             $captcha = new Captcha();
             if (isset($_POST['Submit']) && $_POST['Submit'] == 'Register') {
                 foreach ($this->REQUIRED_PARAMS as $param) {
                     if (!isset($_POST[$param]) || $_POST[$param] == '') {
                         $this->addErrorMessage('Please fill out all required fields.');
                         $this->is_missing_param = true;
                     }
                 }
                 if (!$this->is_missing_param) {
                     $valid_input = true;
                     if (!Utils::validateEmail($_POST['email'])) {
                         $this->addErrorMessage("Incorrect email. Please enter valid email address.", 'email');
                         $valid_input = false;
                     }
                     if (strcmp($_POST['pass1'], $_POST['pass2']) || empty($_POST['pass1'])) {
                         $this->addErrorMessage("Passwords do not match.", 'password');
                         $valid_input = false;
                     } else {
                         if (!preg_match("/(?=.{8,})(?=.*[a-zA-Z])(?=.*[0-9])/", $_POST['pass1'])) {
                             $this->addErrorMessage("Password must be at least 8 characters and contain both numbers " . "and letters.", 'password');
                             $valid_input = false;
                         }
                     }
                     if (!$captcha->doesTextMatchImage()) {
                         $this->addErrorMessage("Entered text didn't match the image. Please try again.", 'captcha');
                         $valid_input = false;
                     }
                     if ($valid_input) {
                         if ($owner_dao->doesOwnerExist($_POST['email'])) {
                             $this->addErrorMessage("User account already exists.", 'email');
                         } else {
                             // Insert the details into the database
                             $activation_code = $owner_dao->create($_POST['email'], $_POST['pass2'], $_POST['full_name']);
                             if ($activation_code != false) {
                                 $es = new ViewManager();
                                 $es->caching = false;
                                 $es->assign('application_url', Utils::getApplicationURL(false));
                                 $es->assign('email', urlencode($_POST['email']));
                                 $es->assign('activ_code', $activation_code);
                                 $message = $es->fetch('_email.registration.tpl');
                                 Mailer::mail($_POST['email'], "Activate Your Account on " . $config->getValue('app_title_prefix') . "ThinkUp", $message);
                                 SessionCache::unsetKey('ckey');
                                 $this->addSuccessMessage("Success! Check your email for an activation link.");
                                 //delete invite code
                                 if ($is_invite_code_valid) {
                                     $invite_dao->deleteInviteCode($invite_code);
                                 }
                                 $has_been_registered = true;
                             } else {
                                 $this->addErrorMessage("Unable to register a new user. Please try again.");
                             }
                         }
                     }
                 }
                 if (isset($_POST["full_name"])) {
                     $this->addToView('name', $_POST["full_name"]);
                 }
                 if (isset($_POST["email"])) {
                     $this->addToView('mail', $_POST["email"]);
                 }
                 $this->addToView('has_been_registered', $has_been_registered);
             }
             $challenge = $captcha->generate();
             $this->addToView('captcha', $challenge);
         }
         $this->view_mgr->addHelp('register', 'userguide/accounts/index');
         return $this->generateView();
     }
 }
 public function testOscars2015WinnerAndLoserReference()
 {
     // 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' => 'Really glad Benedict Cumberbatch lost.', 'pub_date' => '2015-02-19', 'author_username' => $instance->network_username, 'network' => $instance->network));
     $builders[] = FixtureBuilder::build('posts', array('post_text' => 'Hope that Glory wins.', 'pub_date' => '2015-02-25', 'author_username' => $instance->network_username, 'network' => $instance->network));
     $builders[] = FixtureBuilder::build('posts', array('post_text' => 'Hope that Julianne Moore wins.', '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->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertEqual('Somebody was ready for the Oscars party!', $result->headline);
     $this->assertEqual('Cat Lady was talking about Julianne Moore before the Academy Award winners were ' . 'even announced! Looks like the Academy voters might have missed Cat Lady\'s status updates about ' . 'Benedict Cumberbatch, though.', $result->text);
     $controller = new InsightStreamController();
     $_GET['u'] = 'Cat Lady';
     $_GET['n'] = 'facebook';
     $_GET['d'] = date('Y-m-d');
     $_GET['s'] = 'oscars_2015';
     $results = $controller->go();
     //output this to an HTML file to see the insight fully rendered
     $this->debug($results);
 }
 public function testOfNotLoggedInIndividualInsightShareMode()
 {
     $builders = self::buildPublicAndPrivateInsights();
     $_GET['u'] = 'jack';
     $_GET['n'] = 'twitter';
     $_GET['d'] = '2012-05-01';
     $_GET['s'] = 'avg_replies_per_week';
     $controller = new InsightStreamController();
     $results = $controller->go();
     //do show public insight
     $this->assertPattern('/Hey these are some local followers!/', $results);
     //don't show no access message
     $this->assertNoPattern('/to see this insight/', $results);
     //do show footer
     $this->assertPattern('/It is nice to be nice./', $results);
     //do show tout
     $this->assertPattern('/Try ThinkUp for Free/', $results);
     $this->debug($results);
     // Turn on share mode
     $_GET['share'] = '1';
     $results = $controller->go();
     //do show public insight
     $this->assertPattern('/Hey these are some local followers!/', $results);
     //don't show no access message
     $this->assertNoPattern('/to see this insight/', $results);
     //don't show footer
     $this->assertNoPattern('/It is nice to be nice./', $results);
     //don't show tout
     $this->assertNoPattern('/Try ThinkUp for Free/', $results);
 }
 public function testOfNotLoggedInIndividualInsightWithAccess()
 {
     $builders = self::buildPublicAndPrivateInsights();
     $_GET['u'] = 'jack';
     $_GET['n'] = 'twitter';
     $_GET['d'] = '2012-05-01';
     $_GET['s'] = 'avg_replies_per_week';
     $controller = new InsightStreamController();
     $results = $controller->go();
     //do show public insight
     $this->assertPattern('/Retweet spike! Jack\'s post publicly got retweeted 110 times/', $results);
     //don't show no access message
     $this->assertNoPattern('/You don&#39;t have rights to view this service user/', $results);
     $this->debug($results);
 }
 public function control()
 {
     $this->setPageTitle('Log in');
     $this->setViewTemplate('session.login.tpl');
     $this->view_mgr->addHelp('login', 'userguide/accounts/index');
     $this->disableCaching();
     $config = Config::getInstance();
     $this->addToView('is_registration_open', $config->getValue('is_registration_open'));
     //don't show login form if already logged in
     if ($this->isLoggedIn()) {
         $controller = new InsightStreamController(true);
         return $controller->go();
     } else {
         $owner_dao = DAOFactory::getDAO('OwnerDAO');
         // set var for open registration
         $config = Config::getInstance();
         $is_registration_open = $config->getValue('is_registration_open');
         $this->addToView('is_registration_open', $is_registration_open);
         if (isset($_POST['Submit']) && $_POST['Submit'] == 'Log In' && isset($_POST['email']) && isset($_POST['pwd'])) {
             if ($_POST['email'] == '' || $_POST['pwd'] == '') {
                 if ($_POST['email'] == '') {
                     $this->addErrorMessage("Email must not be empty");
                     return $this->generateView();
                 } else {
                     $this->addErrorMessage("Password must not be empty");
                     return $this->generateView();
                 }
             } else {
                 $session = new Session();
                 $user_email = $_POST['email'];
                 if (get_magic_quotes_gpc()) {
                     $user_email = stripslashes($user_email);
                 }
                 $this->addToView('email', $user_email);
                 $owner = $owner_dao->getByEmail($user_email);
                 if (!$owner) {
                     $this->addErrorMessage("Incorrect email");
                     return $this->generateView();
                 } elseif (!$owner->is_activated) {
                     $error_msg = 'Inactive account. ';
                     if ($owner->failed_logins == 0) {
                         $error_msg .= '<a href="http://thinkup.com/docs/install/install.html#activate-your-account">' . 'You must activate your account.</a>';
                     } elseif ($owner->failed_logins == 10) {
                         $error_msg .= $owner->account_status . '. <a href="forgot.php">Reset your password.</a>';
                     }
                     $disable_xss = true;
                     $this->addErrorMessage($error_msg, null, $disable_xss);
                     return $this->generateView();
                     // If the credentials supplied by the user are incorrect
                 } elseif (!$owner_dao->isOwnerAuthorized($user_email, $_POST['pwd'])) {
                     $error_msg = 'Incorrect password';
                     if ($owner->failed_logins == 9) {
                         // where 9 represents the 10th attempt!
                         $owner_dao->deactivateOwner($user_email);
                         $status = 'Account deactivated due to too many failed logins';
                         $owner_dao->setAccountStatus($user_email, $status);
                         $error_msg = 'Inactive account. ' . $status . '. <a href="forgot.php">Reset your password.</a>';
                     }
                     $owner_dao->incrementFailedLogins($user_email);
                     $disable_xss = true;
                     $this->addErrorMessage($error_msg, null, $disable_xss);
                     return $this->generateView();
                 } else {
                     // user has logged in sucessfully this sets variables in the session
                     $session->completeLogin($owner);
                     $owner_dao->updateLastLogin($user_email);
                     $owner_dao->resetFailedLogins($user_email);
                     $owner_dao->clearAccountStatus($user_email);
                     if (!$this->redirect()) {
                         $controller = new InsightStreamController(true);
                         return $controller->go();
                     }
                 }
             }
         } else {
             return $this->generateView();
         }
     }
 }
 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);
 }
Exemple #10
0
<?php

/**
 *
 * ThinkUp/webapp/insights.php
 *
 * Copyright (c) 2012-2013 Gina Trapani
 *
 * LICENSE:
 *
 * This file is part of ThinkUp (http://thinkup.com).
 *
 * ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
 * later version.
 *
 * ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with ThinkUp.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 *
 * @author Gina Trapani <ginatrapani[at]gmail[dot]com>
 * @license http://www.gnu.org/licenses/gpl.html
 * @copyright 2012-2013 Gina Trapani
 */
require_once 'init.php';
$controller = new InsightStreamController();
echo $controller->go();
 public function testFourChangesInStream()
 {
     $this->instance = new Instance();
     $this->instance->id = 1;
     $this->instance->network_username = '******';
     $this->instance->network = 'twitter';
     $builders = self::buildPublicStreamInsights();
     // 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'));
     // Friends
     $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' => 'Not Anil', 'avatar' => 'https://pbs.twimg.com/profile_images/476939811702718464/Qq0LPfRy_400x400.jpeg', 'id' => 2, 'network' => 'twitter', 'description' => 'I am a father, woodworker, sandwich, bird, and pushover. ' . 'RTs != endorsements', 'location' => 'San Francisco, CA', 'is_verified' => 0));
     $builders[] = FixtureBuilder::build('users', array('user_id' => '3', 'user_name' => 'movingperson', 'post_count' => 101, 'follower_count' => 36000, 'is_protected' => 0, 'friend_count' => 1, 'full_name' => 'Maybe Anil', 'avatar' => 'https://pbs.twimg.com/profile_images/476939811702718464/Qq0LPfRy_400x400.jpeg', 'id' => 3, 'network' => 'twitter', 'description' => 'I live in France.', 'location' => 'San Francisco, CA', 'is_verified' => 0));
     $builders[] = FixtureBuilder::build('users', array('user_id' => '4', 'user_name' => 'typodude', 'post_count' => 101, 'follower_count' => 36000, 'is_protected' => 0, 'friend_count' => 1, 'full_name' => 'Typer', 'avatar' => 'https://pbs.twimg.com/profile_images/476939811702718464/Qq0LPfRy_400x400.jpeg', 'id' => 4, 'network' => 'twitter', 'description' => 'I am a wrighter', 'location' => 'San Francisco, CA', 'is_verified' => 0));
     $builders[] = FixtureBuilder::build('users', array('user_id' => '5', 'user_name' => 'typodude', 'post_count' => 101, 'follower_count' => 36000, 'is_protected' => 0, 'friend_count' => 1, 'full_name' => 'Typer', 'avatar' => 'https://pbs.twimg.com/profile_images/476939811702718464/Qq0LPfRy_400x400.jpeg', 'id' => 5, 'network' => 'twitter', 'description' => 'I am a wrighter', '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));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => '3', 'follower_id' => '1', 'last_seen' => '-0d', 'first_seen' => '-0d', 'network' => 'twitter', 'active' => 1));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => '4', 'follower_id' => '1', 'last_seen' => '-0d', 'first_seen' => '-0d', 'network' => 'twitter', 'active' => 1));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => '5', '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' => "I am a father, matchmaker, sandwich, bird, and pushover.", 'crawl_time' => '-2d'));
     $builders[] = FixtureBuilder::build('user_versions', array('user_key' => '3', 'field_name' => 'description', 'field_value' => "I use Google+", 'crawl_time' => '-3d'));
     $builders[] = FixtureBuilder::build('user_versions', array('user_key' => '4', 'field_name' => 'description', 'field_value' => "I am a writer", 'crawl_time' => '-3d'));
     $builders[] = FixtureBuilder::build('user_versions', array('user_key' => '5', 'field_name' => 'description', 'field_value' => "I am a writer", 'crawl_time' => '-3d'));
     $user_dao = DAOFactory::getDAO('UserDAO');
     $user = $user_dao->getDetailsByUserKey(1);
     $insight_plugin = new BioTrackerInsight();
     $insight_plugin->generateInsight($this->instance, $user, $posts, 3);
     $controller = new InsightStreamController();
     $results = $controller->go();
     $this->debug($results);
     //TODO Add assertions here
 }
 public function testMonthlyBestInsightForTwitterV2()
 {
     // Get data ready that insight requires
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $builders = self::setUpPublicInsight($instance);
     $builders[] = FixtureBuilder::build('posts', array('reply_count_cache' => 5, 'retweet_count_cache' => 1, 'favlike_count_cache' => 3, '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' => '-1d'));
     $builders[] = FixtureBuilder::build('posts', array('reply_count_cache' => 0, 'retweet_count_cache' => 1, 'favlike_count_cache' => 15, 'post_text' => 'This is an even better post', 'author_username' => $instance->network_username, 'author_user_id' => 'abc', 'author_avatar' => 'http://example.com/example.jpg', 'network' => $instance->network, 'pub_date' => '-1d'));
     $builders[] = FixtureBuilder::build('posts', array('reply_count_cache' => 2, 'retweet_count_cache' => 5, 'favlike_count_cache' => 1, 'post_text' => 'This is THE BEST post', 'author_username' => $instance->network_username, 'author_user_id' => 'abc', 'author_avatar' => 'http://example.com/example.jpg', 'network' => $instance->network, 'pub_date' => '-1d'));
     TimeHelper::setTime(2);
     $insight_plugin = new WeeklyBestsInsight();
     $insight_plugin->generateInsight($instance, null, array(), 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('monthly_best', 10, $today);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertPattern('/@testeriffic\'s best of May/', $result->headline);
     $last_month_time = strtotime('first day of last month');
     $this->assertPattern('/This was @testeriffic\'s most popular tweet of ' . date('F', $last_month_time) . ' ' . date('Y', $last_month_time) . './', $result->text);
     $controller = new InsightStreamController();
     $_GET['u'] = 'testeriffic';
     $_GET['n'] = 'twitter';
     $_GET['d'] = $today;
     $_GET['s'] = 'monthly_best';
     $results = $controller->go();
     //Uncomment this out to see web view of insight
     //$this->debug($results);
     $this->assertPattern('/This is a really good post/', $results);
     $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);
     //Test alternate headline/body
     TimeHelper::setTime(2);
     $insight_plugin = new WeeklyBestsInsight();
     $insight_plugin->generateInsight($instance, null, array(), 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('monthly_best', 10, $today);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertPattern('/@testeriffic\'s best of May/', $result->headline);
     $last_month_time = strtotime('first day of last month');
     $this->assertPattern('/This was @testeriffic\'s most popular tweet of ' . date('F', $last_month_time) . ' ' . date('Y', $last_month_time) . './', $result->text);
     $controller = new InsightStreamController();
     $_GET['u'] = 'testeriffic';
     $_GET['n'] = 'twitter';
     $_GET['d'] = $today;
     $_GET['s'] = 'monthly_best';
     $results = $controller->go();
     //Uncomment this out to see web view of insight
     //$this->debug($results);
     $this->assertPattern('/This is a really good post/', $results);
     $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 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);
 }
 public function __construct($session_started = false, $since = null)
 {
     parent::__construct($session_started);
     $this->since = $since;
     $_GET['since'] = $since;
 }