Ejemplo n.º 1
0
 public function testLongLostContactsInsight()
 {
     // Get data ready that insight requires
     $builders = self::buildData();
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_user_id = 7612345;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $insight_plugin = new LongLostContactsInsight();
     $insight_plugin->generateInsight($instance, $last_week_of_posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('long_lost_contacts', 10, $today);
     $contacts = unserialize($result->related_data);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertPattern('/\\@twitteruser hasn\'t replied to /', $result->text);
     $this->assertPattern('/<strong>2 contacts<\\/strong> /', $result->text);
     $this->assertPattern('/in over a year: /', $result->text);
     $this->assertNoPattern('/a contact/', $result->text);
     $this->assertIsA($contacts, "array");
     $this->assertIsA($contacts[0], "User");
     $this->assertEqual(count($contacts), 2);
 }
Ejemplo n.º 2
0
 public function testSingleBigReshareBy2xFollowers()
 {
     // Assert that insight doesn't exist
     $insight_dao = new InsightMySQLDAO();
     $yesterday = date('Y-m-d', strtotime('-1 day'));
     $result = $insight_dao->getInsight('big_reshare_1345', 10, $yesterday);
     $this->assertNull($result);
     //original post
     $post1_builder = FixtureBuilder::build('posts', array('id' => 1345, 'post_id' => '134', 'author_user_id' => 22, 'author_username' => 'quoter', 'author_fullname' => 'Quoter of Quotables', 'network' => 'twitter', 'post_text' => 'Be liberal in what you accept and conservative in what you send', 'source' => 'web', 'pub_date' => '-1d', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'is_protected' => 0, 'location' => 'New Delhi, Delhi, India', 'geo' => '28.635308,77.22496', 'is_geo_encoded' => 1));
     $post1_object = new Post($post1_builder->columns);
     $builders = self::buildData();
     //retweet author has 2x more followers
     $builders[] = FixtureBuilder::build('users', array('user_id' => '20', 'user_name' => 'user1', 'full_name' => 'User 1', 'description' => 'I am a user', 'avatar' => 'avatar.jpg', 'is_protected' => 0, 'follower_count' => 160, 'network' => 'twitter'));
     // Get data ready that insight requires
     $posts = array();
     $posts[] = $post1_object;
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_user_id = '22';
     $instance->network = 'twitter';
     $instance->network_username = '******';
     $bigreshare_insight_plugin = new BigReshareInsight();
     $bigreshare_insight_plugin->generateInsight($instance, $this->getUser(), $posts, 3);
     // Assert that insight got generated
     $insight_dao = new InsightMySQLDAO();
     $yesterday = date('Y-m-d', strtotime('-1 day'));
     $result = $insight_dao->getInsight('big_reshare_1345', 10, $yesterday);
     $this->assertNotNull($result);
     $this->debug(Utils::varDumpToString($result));
     $this->assertEqual($result->slug, 'big_reshare_1345');
     $this->assertEqual($result->filename, 'bigreshare');
     $this->assertPattern('/Someone with \\<strong\\>2x\\<\\/strong\\> more followers retweeted \\@testeriffic/', $result->headline);
     $this->assertEqual('80 more people saw @testeriffic\'s tweet.', $result->text);
     $this->debug($this->getRenderedInsightInHTML($result));
 }
Ejemplo n.º 3
0
 public function testGetPhotoExists()
 {
     $dao = new PhotoMySQLDAO();
     $result = $dao->getPhoto("507648000295407216_180890738", 'instagram');
     $this->debug(Utils::varDumpToString($result));
     $this->assertTrue(isset($result));
     $this->assertEqual($result->post_id, '507648000295407216_180890738');
     $this->assertEqual($result->author_user_id, '180890738');
     $this->assertEqual($result->author_username, 'nilakshdas');
     $this->assertEqual($result->author_fullname, 'Nilaksh Das');
     $avatar = 'http://images.ak.instagram.com/profiles/profile_180890738_75sq_1374737148.jpg';
     $this->assertEqual($result->author_avatar, $avatar);
     $this->assertEqual($result->post_text, '#LoseYourself, as usual.');
     $this->assertEqual($result->is_protected, false);
     $this->assertEqual($result->source, 'undefined');
     $this->assertEqual($result->pub_date, '2013-07-25 12:42:59');
     $this->assertEqual($result->network, 'instagram');
     $this->assertEqual($result->post_key, 5);
     $this->assertEqual($result->filter, 'Lo-fi');
     $srurl = 'http://distilleryimage0.s3.amazonaws.com/a2e8b5f0f4f911e2af6f22000a1f9a09_7.jpg';
     $this->assertEqual($result->standard_resolution_url, $srurl);
     $lrurl = 'http://distilleryimage0.s3.amazonaws.com/a2e8b5f0f4f911e2af6f22000a1f9a09_6.jpg';
     $this->assertEqual($result->low_resolution_url, $lrurl);
     $tnurl = 'http://distilleryimage0.s3.amazonaws.com/a2e8b5f0f4f911e2af6f22000a1f9a09_5.jpg';
     $this->assertEqual($result->thumbnail_url, $tnurl);
 }
Ejemplo n.º 4
0
 public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $filename = basename(__FILE__, ".php");
     // Follower count history milestone
     $insight_date = new DateTime();
     $insight_day_of_week = (int) $insight_date->format('w');
     $insight_day_of_month = (int) $insight_date->format('j');
     if ($insight_day_of_month == 1) {
         //it's the first day of the month
         $count_dao = DAOFactory::getDAO('CountHistoryDAO');
         //by month
         $follower_count_history_by_month = $count_dao->getHistory($instance->network_user_id, $instance->network, 'MONTH', 15, $this->insight_date);
         $insight_text = "<strong>";
         if (isset($follower_count_history_by_month['milestone']) && $follower_count_history_by_month["milestone"]["will_take"] > 0 && $follower_count_history_by_month["milestone"]["next_milestone"] > 0) {
             $insight_text .= $follower_count_history_by_month['milestone']['will_take'] . ' month';
             if ($follower_count_history_by_month['milestone']['will_take'] > 1) {
                 $insight_text .= 's';
             }
             $insight_text .= "</strong> till {$this->username} reaches <strong>" . number_format($follower_count_history_by_month['milestone']['next_milestone']);
             $insight_text .= '</strong> followers at the current growth rate.';
             $this->insight_dao->insertInsightDeprecated('follower_count_history_by_month_milestone', $instance->id, $this->insight_date, "Upcoming milestone:", $insight_text, $filename, Insight::EMPHASIS_LOW, serialize($follower_count_history_by_month));
         }
     } else {
         if ($insight_day_of_week == 0) {
             //it's Sunday
             $count_dao = DAOFactory::getDAO('CountHistoryDAO');
             //by week
             $follower_count_history_by_week = $count_dao->getHistory($instance->network_user_id, $instance->network, 'WEEK', 15, $this->insight_date);
             $this->logger->logInfo($this->insight_date . " is Sunday; Count by week stats are " . Utils::varDumpToString($follower_count_history_by_week), __METHOD__ . ',' . __LINE__);
             $insight_text = "<strong>";
             if (isset($follower_count_history_by_week['milestone']) && $follower_count_history_by_week["milestone"]["will_take"] > 0 && $follower_count_history_by_week["milestone"]["next_milestone"] > 0) {
                 $insight_text .= $follower_count_history_by_week['milestone']['will_take'] . ' week';
                 if ($follower_count_history_by_week['milestone']['will_take'] > 1) {
                     $insight_text .= 's';
                 }
                 $insight_text .= "</strong> till {$this->username} reaches <strong>" . number_format($follower_count_history_by_week['milestone']['next_milestone']);
                 $insight_text .= '</strong> followers at the current growth rate.';
                 $this->logger->logInfo("Storing insight " . $insight_text, __METHOD__ . ',' . __LINE__);
                 $this->insight_dao->insertInsightDeprecated('follower_count_history_by_week_milestone', $instance->id, $this->insight_date, "Upcoming milestone:", $insight_text, $filename, Insight::EMPHASIS_LOW, serialize($follower_count_history_by_week));
             }
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
 public function testSetPopularPostPosts()
 {
     $year = date('Y');
     $builders = self::setUpPublicInsight($this->instance);
     // set up posts
     // 2nd most popular post January
     $builders[] = FixtureBuilder::build('posts', array('id' => 11, 'post_id' => 11, 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => $this->instance->network, 'post_text' => 'This is a post that is less popular', 'source' => 'web', 'pub_date' => "{$year}-01-01", 'reply_count_cache' => 5, 'is_protected' => false));
     // 3rd most popular post January
     $builders[] = FixtureBuilder::build('posts', array('id' => 12, 'post_id' => 12, 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => $this->instance->network, 'post_text' => 'This is the least popular post', 'source' => 'web', 'pub_date' => "{$year}-01-01", 'reply_count_cache' => 1, 'is_protected' => false));
     // most popular post January
     $builders[] = FixtureBuilder::build('posts', array('id' => 10, 'post_id' => 10, 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => $this->instance->network, 'post_text' => 'This is the most popular post', 'source' => 'web', 'pub_date' => "{$year}-01-01", 'reply_count_cache' => 10, 'retweet_count_cache' => 20, 'favlike_count_cache' => 30));
     // 2nd most popular post Sept
     $builders[] = FixtureBuilder::build('posts', array('id' => 13, 'post_id' => 13, 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => $this->instance->network, 'post_text' => 'This is a post that is less popular', 'source' => 'web', 'pub_date' => "{$year}-09-15", 'reply_count_cache' => 5, 'is_protected' => false));
     // 3rd most popular post Sept
     $builders[] = FixtureBuilder::build('posts', array('id' => 14, 'post_id' => 14, 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => $this->instance->network, 'post_text' => 'This is the least popular post', 'source' => 'web', 'pub_date' => "{$year}-09-20", 'reply_count_cache' => 1, 'is_protected' => false));
     // most popular post Sept
     $builders[] = FixtureBuilder::build('posts', array('id' => 15, 'post_id' => 15, 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => $this->instance->network, 'post_text' => 'This is the most popular post', 'source' => 'web', 'pub_date' => "{$year}-09-30", 'reply_count_cache' => 10, 'retweet_count_cache' => 20, 'favlike_count_cache' => 30));
     $post_dao = DAOFactory::getDAO('PostDAO');
     $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $this->instance->network_user_id, $network = $this->instance->network);
     $insight_plugin = new EOYMostPopularPerMonthInsight();
     $scored_posts = $insight_plugin->setScoredPosts($last_year_of_posts);
     $this->debug(Utils::varDumpToString($insight_plugin->posts_per_month));
 }
Ejemplo n.º 6
0
 /**
  *  Parse the JSON returned from foursquare and store them in the database
  *  @param JSON $checkins
  */
 private function parseResults($checkins)
 {
     $post_dao = DAOFactory::getDAO('PostDAO');
     $place_dao = DAOFactory::getDAO('PlaceDAO');
     $link_dao = DAOFactory::getDAO('LinkDAO');
     $number_stored = 0;
     // Check we actually got a set of checkins
     if (isset($checkins->response->checkins->items) && sizeof($checkins->response->checkins->items) > 0) {
         // Make a query out to the API for this users details, like name etc.
         $user = $this->api_accessor->apiRequest('users/self', $this->access_token);
         // For each checkin store it in the database
         foreach ($checkins->response->checkins->items as $item) {
             // The post ID, is the checkin ID foursquare provides
             $post['post_id'] = $item->id;
             // The post text is the text they enter when checking in
             $post['post_text'] = isset($item->shout) ? $item->shout : " ";
             // The author username is the users foursquare email address
             $post['author_username'] = $user->response->user->contact->email;
             // The author full name is the name they gave foursquare
             $post['author_fullname'] = $user->response->user->firstName . " " . $user->response->user->lastName;
             // The avatar is the one they have set on foursquare
             $post["author_avatar"] = $user->response->user->photo->prefix . "100x100" . $user->response->user->photo->suffix;
             // The author user id is there foursquare user ID
             $post['author_user_id'] = $user->response->user->id;
             // The date they checked in
             $post['pub_date'] = date('Y-m-d H:i:s', $item->createdAt);
             // Source of the checkin
             $post['source'] = $item->source->name;
             // Check if the checkin was marked as private
             if (isset($item->private)) {
                 $post['is_protected'] = true;
             } else {
                 $post['is_protected'] = false;
             }
             // Set the network to foursquare
             $post['network'] = 'foursquare';
             // Set place to the name of the place their checking into
             $post['place'] = $item->venue->name;
             // There are a few parameters that may or may not be set for location so let the method figure it out
             $post['location'] = $this->getLocation($item);
             //$post['location'] = $item->location->postalCode;
             // Place ID is an ID foursquare provides
             $post['place_id'] = $item->venue->id;
             // Set geo to the lat,lng that foursquare provides
             $post['geo'] = $item->venue->location->lat . "," . $item->venue->location->lng;
             // These parameters cant be null but we don't need them for our plugin so set them to any empty string
             $post['reply_count_cache'] = '';
             $post['favlike_count_cache'] = '';
             $post['retweet_count_cache'] = '';
             $post['author_follower_count'] = '';
             // Store the checkin details in the database
             $done = $post_dao->addPost($post);
             if ($done != null) {
                 $number_stored++;
             }
             // Check if any photos are attached to this checkin
             if ($item->photos->count > 0 && $done != null) {
                 foreach ($item->photos->items as $photo) {
                     $photo_store = new Link(array('url' => $photo->url, 'expanded_url' => $photo->url, 'title' => ' ', 'description' => ' ', 'image_src' => $photo->url, 'caption' => ' ', 'clicks' => 0, 'post_key' => $done, 'error' => 'none'));
                     // Insert the photo into the database
                     $link_dao->insert($photo_store);
                     // Delete the current photo info ready for the next one
                     $photo_store = null;
                 }
             }
             // If there are any comments on this checkin capture them
             if ($item->comments->count > 0) {
                 // Make a query out for the comments
                 $comments = $this->api_accessor->apiRequest('checkins/' . $item->id, $this->access_token);
                 foreach ($comments->response->checkin->comments->items as $comment) {
                     // The post ID, is the comment ID foursquare provides
                     $comment_store['post_id'] = $comment->id;
                     // The post text is the comment they made
                     $comment_store['post_text'] = $comment->text;
                     // The author username is the users foursquare email address (which we need to query for)
                     $name = $this->api_accessor->apiRequest('users/' . $comment->user->id, $this->access_token);
                     $user_name = $name->response->user->contact->email;
                     $comment_store['author_username'] = isset($user_name) ? $user_name : 'email address withheld';
                     // The author full name is the name they gave foursquare
                     $comment_store['author_fullname'] = $comment->user->firstName . " " . $comment->user->lastName;
                     // The avatar is the one they have set on foursquare
                     $comment_store["author_avatar"] = $comment->user->photo->prefix . "100x100" . $comment->user->photo->suffix;
                     // The author user id is there foursquare user ID
                     $comment_store['author_user_id'] = $comment->user->id;
                     // The date they posted the comment
                     $comment_store['pub_date'] = date('Y-m-d H:i:s', $comment->createdAt);
                     // Source of the comment
                     $comment_store['source'] = "";
                     // Comments can not be private
                     $comment_store['is_protected'] = false;
                     // Set the network to foursquare
                     $comment_store['network'] = 'foursquare';
                     // Set place to the name of the place the comment is about
                     $comment_store['place'] = $comments->response->checkin->venue->name;
                     // A few parameters may or may not be set for location so let the method do the work
                     $comment_store['location'] = $this->getLocation($item);
                     // Place ID is an ID foursquare provides
                     $comment_store['place_id'] = $comments->response->checkin->venue->id;
                     // Set geo to the lat,lng that foursquare provides
                     $comment_store['geo'] = $item->venue->location->lat . "," . $item->venue->location->lng;
                     // The ID of the author of the checkin
                     $comment_store['in_reply_to_user_id'] = $user->response->user->id;
                     // The ID of the checkin this is a reply to
                     $comment_store['in_reply_to_post_id'] = $item->id;
                     // The number of replies this checkin has
                     $comment_store['reply_count_cache'] = $item->comments->count;
                     // These parameters cant be null but we don't need them so set them to any empty string
                     $comment_store['reply_count_cache'] = '';
                     $comment_store['favlike_count_cache'] = '';
                     $comment_store['retweet_count_cache'] = '';
                     $comment_store['author_follower_count'] = '';
                     self::fetchUser($comment_store['author_user_id'], 'comment');
                     // Now store the comment in the database
                     $post_dao->addPost($comment_store);
                     $comment = null;
                 }
             }
             // Store the details about this place in the place table if it doesn't already exist
             // See if this place is already in the database
             $place_test = $place_dao->getPlaceByID($item->venue->id);
             // If it isn't already in the database
             if ($place_test == null) {
                 // Insert it
                 $places['id'] = $item->venue->id;
                 $places['place_type'] = $item->venue->categories[0]->name;
                 $places['name'] = $item->venue->name;
                 $places['full_name'] = $item->venue->name;
                 $places['icon'] = $item->venue->categories[0]->icon->prefix . '64' . $item->venue->categories[0]->icon->suffix;
                 $places['lat_lng'] = 'POINT(' . $item->venue->location->lat . " " . $item->venue->location->lng . ')';
                 $places['map_image'] = $this->generateMap($item);
                 $place_dao->insertGenericPlace($places, 'foursquare');
             }
             // Blank out the details ready for the next checkin
             $post = null;
             $places = null;
         }
     } else {
         $this->logger->logInfo("No checkins found " . Utils::varDumpToString($checkins));
     }
 }
 public function testTrendMillionPlusGroupMemberships2()
 {
     $format = 'n/j';
     $date = date($format);
     $group_member_count = array('member_user_id' => '930061', 'network' => 'twitter', 'date' => '-1d', 'count' => 1272643);
     $builder1 = FixtureBuilder::build('group_member_count', $group_member_count);
     $group_member_count = array('member_user_id' => '930061', 'network' => 'twitter', 'date' => '-2d', 'count' => 1271684);
     $builder2 = FixtureBuilder::build('group_member_count', $group_member_count);
     $group_member_count = array('member_user_id' => '930061', 'network' => 'twitter', 'date' => '-3d', 'count' => 1271500);
     $builder3 = FixtureBuilder::build('group_member_count', $group_member_count);
     $group_member_count = array('member_user_id' => '930061', 'network' => 'twitter', 'date' => '-4d', 'count' => 1261500);
     $builder4 = FixtureBuilder::build('group_member_count', $group_member_count);
     $dao = new GroupMembershipCountMySQLDAO();
     $result = $dao->getHistory('930061', 'twitter', 'DAY', 4);
     $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, milestone, and vis_data');
     $this->debug(Utils::varDumpToString($result));
     //check milestone
     //latest group membership count is 1.7M, next milestone is 2M
     //with a 2786+/day trend, this should take 82 days
     //beyond our "don't feel bad about yourself" threshold of 10, so should be null
     $this->assertNull($result['milestone']);
 }
    public function testSuccessfulRegistration()
    {
        $config = Config::getInstance();
        $site_root_path = $config->getValue('site_root_path');
        // make sure registration is on...
        $bvalues = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_registration_open', 'option_value' => 'true');
        $bdata = FixtureBuilder::build('options', $bvalues);
        $_SERVER['HTTP_HOST'] = "mytestthinkup";
        $_POST['Submit'] = 'Register';
        $_POST['full_name'] = "Angelina Jolie";
        $_POST['email'] = '*****@*****.**';
        $_POST['user_code'] = '123456';
        $_POST['pass1'] = 'mypass';
        $_POST['pass2'] = 'mypass';
        $controller = new RegisterController(true);
        $results = $controller->go();
        $v_mgr = $controller->getViewManager();
        $this->assertEqual($v_mgr->getTemplateDataItem('controller_title'), 'Register');
        $this->debug($v_mgr->getTemplateDataItem('success_msg'));
        $this->debug($v_mgr->getTemplateDataItem('error_msg'));
        $this->debug(Utils::varDumpToString($v_mgr->getTemplateDataItem('error_msgs')));
        $this->assertEqual($v_mgr->getTemplateDataItem('success_msg'), 'Success! Check your email for an activation link.');
        $expected_reg_email_pattern = '/to: angie@example.com
subject: Activate Your ThinkUp Account
message: Click on the link below to activate your new ThinkUp account:

http:\\/\\/mytestthinkup' . str_replace('/', '\\/', $site_root_path) . 'session\\/activate.php\\?usr=angie%40example.com/';
        $actual_reg_email = Mailer::getLastMail();
        $this->debug($actual_reg_email);
        $this->assertPattern($expected_reg_email_pattern, $actual_reg_email);
    }
 /**
  * Add user auth link or process incoming auth requests.
  * @param array $options Plugin options array
  */
 protected function setUpGPlusInteractions(array $options)
 {
     //get options
     $client_id = $options['google_plus_client_id']->option_value;
     $client_secret = $options['google_plus_client_secret']->option_value;
     //prep redirect URI
     $config = Config::getInstance();
     $site_root_path = $config->getValue('site_root_path');
     $redirect_uri = urlencode(Utils::getApplicationURL() . 'account/?p=google%2B');
     //create OAuth link
     $oauth_link = "https://accounts.google.com/o/oauth2/auth?client_id=" . $client_id . "&redirect_uri=" . $redirect_uri . "&scope=https://www.googleapis.com/auth/plus.me&response_type=code&access_type=offline&approval_prompt=force";
     $this->addToView('oauth_link', $oauth_link);
     // Google provided a code to get an access token
     if (isset($_GET['code'])) {
         $code = $_GET['code'];
         $crawler_plugin_registrar = new GooglePlusCrawler(null, null);
         $tokens = $crawler_plugin_registrar->getOAuthTokens($client_id, $client_secret, $code, 'authorization_code', $redirect_uri);
         if (isset($tokens->error)) {
             $this->addErrorMessage("Oops! Something went wrong while obtaining OAuth tokens.<br>Google says \"" . $tokens->error . ".\" Please double-check your settings and try again.", 'authorization');
         } else {
             if (isset($tokens->access_token) && isset($tokens->access_token)) {
                 //Get user data
                 $gplus_api_accessor = new GooglePlusAPIAccessor();
                 $gplus_user = $gplus_api_accessor->apiRequest('people/me', $tokens->access_token, null);
                 if (isset($gplus_user->error)) {
                     if ($gplus_user->error->code == "403" && $gplus_user->error->message == 'Access Not Configured') {
                         $this->addErrorMessage("Oops! Looks like Google+ API access isn't turned on. " . "<a href=\"http://code.google.com/apis/console#access\">In the Google APIs console</a>, " . "in Services, flip the Google+ API Status switch to 'On' and try again.", 'authorization');
                     } else {
                         $this->addErrorMessage("Oops! Something went wrong querying the Google+ API.<br>" . "Google says \"" . $gplus_user->error->code . ": " . $gplus_user->error->message . ".\" Please double-check your settings and try again.", 'authorization');
                     }
                 } else {
                     if (isset($gplus_user->id) && isset($gplus_user->displayName)) {
                         $gplus_user_id = $gplus_user->id;
                         $gplus_username = $gplus_user->displayName;
                         //Process tokens
                         $this->saveAccessTokens($gplus_user_id, $gplus_username, $tokens->access_token, $tokens->refresh_token);
                     } else {
                         $this->addErrorMessage("Oops! Something went wrong querying the Google+ API.<br>" . "Google says \"" . Utils::varDumpToString($gplus_user) . ".\" Please double-check your settings and try again.", 'authorization');
                     }
                 }
             } else {
                 $this->addErrorMessage("Oops! Something went wrong while obtaining OAuth tokens.<br>Google says \"" . Utils::varDumpToString($tokens) . ".\" Please double-check your settings and try again.", 'authorization');
             }
         }
     }
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     $owner_instances = $instance_dao->getByOwnerAndNetwork($this->owner, 'google+');
     $this->addToView('owner_instances', $owner_instances);
 }
 public function testSingleLongLostContact()
 {
     // Get data ready that insight requires
     $builders = self::buildData($multiple = false);
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_user_id = 7612345;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $insight_plugin = new LongLostContactsInsight();
     $insight_plugin->generateInsight($instance, null, $last_week_of_posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('long_lost_contacts', 10, $today);
     $contacts = unserialize($result->related_data);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertPattern('/\\@twitteruser hasn\'t replied to /', $result->headline);
     $this->assertPattern('/Twitter Follower One /', $result->headline);
     $this->assertPattern('/in over a year/', $result->headline);
     $this->assertPattern('/avatar.jpg/', $result->header_image);
     $this->assertNoPattern('/people/', $result->headline);
     $this->assertIsA($contacts, "array");
     $this->assertIsA($contacts["people"][0], "User");
     $this->assertEqual(count($contacts["people"]), 1);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
Ejemplo n.º 11
0
 /**
  * Test getExchangesBetweenUsers
  */
 public function testGetExchangesBetweenUsers()
 {
     $dao = new PostMySQLDAO();
     $posts_replied_to = $dao->getExchangesBetweenUsers(18, 21, 'twitter');
     $this->assertEqual(sizeof($posts_replied_to), 2);
     $this->assertEqual($posts_replied_to[0]["questioner_username"], "shutterbug");
     $this->assertEqual($posts_replied_to[0]["question"], "This is image post 1");
     $this->assertEqual($posts_replied_to[0]["answerer_username"], "user2");
     $this->assertEqual($posts_replied_to[0]["answer"], "@shutterbug Nice shot!");
     $this->assertEqual($posts_replied_to[1]["questioner_username"], "user2");
     $this->assertEqual($posts_replied_to[1]["question"], "@shutterbug Nice shot!");
     $this->assertEqual($posts_replied_to[1]["answerer_username"], "shutterbug");
     $this->assertEqual($posts_replied_to[1]["answer"], "@user2 Thanks!");
     $this->debug(Utils::varDumpToString($posts_replied_to));
     $posts_replied_to = $dao->getExchangesBetweenUsers(13, 20, 'twitter');
     $this->assertEqual(sizeof($posts_replied_to), 1);
     $this->assertEqual($posts_replied_to[0]["question_post_id"], 139);
     $this->assertEqual($posts_replied_to[0]["questioner_username"], "user1");
     $this->assertEqual($posts_replied_to[0]["question"], "@ev When will Twitter have a business model?");
     $this->assertEqual($posts_replied_to[0]['answer_post_id'], 140);
     $this->assertEqual($posts_replied_to[0]["answerer_username"], "ev");
     $this->assertEqual($posts_replied_to[0]["answer"], "@user1 Soon...");
 }
Ejemplo n.º 12
0
 public function testCrawlCompletion()
 {
     $this->debug(__METHOD__);
     $builders = array();
     //Add instances
     $instance_builder_1 = FixtureBuilder::build('instances', array('id' => 1, 'network_username' => 'julie', 'network' => 'twitter', 'crawler_last_run' => '-5d', 'is_activated' => '1', 'is_public' => '1'));
     $instance_builder_2 = FixtureBuilder::build('instances', array('id' => 2, 'network_username' => 'john', 'network' => 'twitter', 'crawler_last_run' => '-5d', 'is_activated' => '1', 'is_public' => '1'));
     $builders[] = FixtureBuilder::build('instances_twitter', array('id' => 1));
     $builders[] = FixtureBuilder::build('instances_twitter', array('id' => 2));
     //Add owner
     $builders[] = FixtureBuilder::build('owners', array('id' => 1, 'full_name' => 'ThinkUp J. User', 'email' => '*****@*****.**', 'is_activated' => 1, 'is_admin' => 1));
     $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 1, 'instance_id' => 1, 'auth_error' => ''));
     $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 1, 'instance_id' => 2, 'auth_error' => ''));
     $this->simulateLogin('*****@*****.**', true, true);
     $test = new TwitterInstanceMySQLDAO();
     $twitter_plugin = new TwitterPlugin();
     $twitter_plugin->crawl();
     $instance_dao = new InstanceMySQLDAO();
     $updated_instance = $instance_dao->get(1);
     $this->debug(Utils::varDumpToString($updated_instance));
     // crawler_last_run should have been updated
     $this->assertNotEqual($instance_builder_1->columns['crawler_last_run'], $updated_instance->crawler_last_run);
 }
 public function testLinkUtilities()
 {
     $year = date('Y');
     $user_id = $this->instance->network_user_id;
     $counter = 12;
     $days = 0;
     // set up most links
     while ($counter != 0) {
         $post_key = $counter + 1760;
         $days++;
         $builders[] = FixtureBuilder::build('posts', array('id' => $post_key, 'post_id' => $post_key, 'network' => 'twitter', 'author_user_id' => $user_id, 'author_username' => 'user', 'in_reply_to_user_id' => NULL, 'in_retweet_of_post_id' => NULL, 'retweet_count_cache' => $days, 'reply_count_cache' => $days, 'favlike_count_cache' => $days, 'in_reply_to_post_id' => 0, 'is_protected' => 0, 'author_fullname' => 'User', 'post_text' => 'Link post http://lifehacker.com/' . $counter, 'pub_date' => '-1d'));
         $builders[] = FixtureBuilder::build('links', array('url' => 'http://lifehacker.com/' . $counter, 'title' => 'Link ' . $counter, 'post_key' => $post_key, 'expanded_url' => 'http://lifehacker.com/' . $counter, 'error' => '', 'image_src' => ''));
         $counter--;
     }
     // set up fewer links
     $counter = 10;
     $days = 0;
     while ($counter != 0) {
         $post_key = $counter + 1860;
         $days++;
         $builders[] = FixtureBuilder::build('posts', array('id' => $post_key, 'post_id' => $post_key, 'network' => 'twitter', 'author_user_id' => $user_id, 'author_username' => 'user', 'in_reply_to_user_id' => NULL, 'in_retweet_of_post_id' => NULL, 'in_reply_to_post_id' => 0, 'is_protected' => 0, 'author_fullname' => 'User', 'post_text' => 'Link post http://nytimes.com/' . $counter, 'pub_date' => '-1d'));
         $builders[] = FixtureBuilder::build('links', array('url' => 'http://nytimes.com/' . $counter, 'title' => 'Link ' . $counter, 'post_key' => $post_key, 'expanded_url' => 'http://nytimes.com/' . $counter, 'error' => '', 'image_src' => ''));
         $counter--;
     }
     $insight_plugin = new EOYMostLinksInsight();
     $post_dao = new PostMySQLDAO();
     $it_posts = $post_dao->getThisYearOfPostsWithLinksIterator($author_id = $this->instance->network_user_id, $network = $this->instance->network);
     $posts = array();
     foreach ($it_posts as $post) {
         $posts[] = $post;
     }
     $this->assertEqual(count($posts), 22);
     $domain_counts = $insight_plugin->getDomainCounts($posts);
     $this->debug(Utils::varDumpToString($domain_counts));
     $sorted_domains = array(0 => array('lifehacker.com' => 12), 1 => array('nytimes.com' => 10));
     $i = 0;
     foreach ($domain_counts as $domain => $count) {
         $this->assertEqual($sorted_domains[$i][$domain], $count);
         $i++;
     }
     $domain = $insight_plugin->getPopularDomain($domain_counts);
     $this->assertEqual('lifehacker.com', $domain);
     $posts = $insight_plugin->getMostPopularPostsLinkingTo($this->instance, $domain);
     $this->debug(Utils::varDumpToString($posts));
     $this->assertEqual(3, count($posts));
     $this->assertEqual($posts[0]->id, 1761);
     $this->assertEqual($posts[2]->id, 1763);
 }
 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);
 }
Ejemplo n.º 15
0
 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $since_date = date("Y-m-d");
     $filename = basename(__FILE__, ".php");
     $regenerate = false;
     switch ($instance->network) {
         case 'twitter':
             $day_of_month = 7;
             break;
         case 'facebook':
             $day_of_month = 14;
             break;
         case 'instagram':
             $day_of_month = 23;
             break;
         default:
             $day_of_month = 23;
     }
     $should_generate_insight = self::shouldGenerateMonthlyInsight($this->slug, $instance, $insight_date = $since_date, $regenerate_existing_insight = $regenerate, $day_of_month = $day_of_month, $count_related_posts = null, $excluded_networks = null, $enable_bonus_alternate_day = true);
     if ($should_generate_insight) {
         $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__);
         $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
         $owner_dao = DAOFactory::getDAO('OwnerDAO');
         $owner_instance = $owner_instance_dao->getByInstance($instance->id);
         $owner_id = $owner_instance[0]->owner_id;
         $owner = $owner_dao->getById($owner_instance[0]->owner_id);
         try {
             $owner_timezone = new DateTimeZone($owner->timezone);
         } catch (Exception $e) {
             // In the odd case the owner has no or a malformed timezone
             $cfg = Config::getInstance();
             $owner_timezone = new DateTimeZone($cfg->getValue('timezone'));
         }
         $now = new DateTime();
         $offset = timezone_offset_get($owner_timezone, $now);
         $post_dao = DAOFactory::getDAO('PostDAO');
         $last_months_posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $instance->network, $count = null, $order_by = "pub_date", $in_last_x_days = 30, $iterator = false, $is_public = false);
         $punchcard = array();
         $responses_chron = array();
         $response_avg_timediffs = array();
         for ($hotd = 0; $hotd < 24; $hotd++) {
             for ($dotm = 1; $dotm <= 30; $dotm++) {
                 $punchcard['posts'][$dotm][$hotd] = 0;
                 $punchcard['responses'][$dotm][$hotd] = 0;
             }
             $responses_chron[$hotd] = 0;
         }
         // $this->logger->logInfo("Last month's posts: ".Utils::varDumpToString($last_months_posts),
         //     __METHOD__.','.__LINE__);
         if ($instance->network !== 'instagram') {
             //count replies and retweets
             foreach ($last_months_posts as $post) {
                 $responses = array();
                 $responses = array_merge((array) $post_dao->getRepliesToPost($post->post_id, $post->network), (array) $post_dao->getRetweetsOfPost($post->post_id, $post->network));
                 foreach ($responses as $response) {
                     $response_pub_date = new DateTime($response->pub_date);
                     $response_dotm = date('j', date('U', strtotime($response->pub_date) + $offset));
                     // Day of month
                     $response_hotd = date('G', date('U', strtotime($response->pub_date) + $offset));
                     // Hour of day
                     $punchcard['responses'][$response_dotm][$response_hotd]++;
                     $responses_chron[$response_hotd]++;
                 }
                 $post_pub_date = new DateTime($post->pub_date);
                 $post_dotm = date('j', date('U', strtotime($post->pub_date) + $offset));
                 // Day of the month
                 $post_hotd = date('G', date('U', strtotime($post->pub_date) + $offset));
                 // Hour of the day
                 $punchcard['posts'][$post_dotm][$post_hotd]++;
             }
         } else {
             //count likes
             foreach ($last_months_posts as $post) {
                 $post_pub_date = new DateTime($post->pub_date);
                 $post_dotm = date('j', date('U', strtotime($post->pub_date) + $offset));
                 // Day of month
                 $post_hotd = date('G', date('U', strtotime($post->pub_date) + $offset));
                 // Hour of day
                 $punchcard['responses'][$post_dotm][$post_hotd]++;
                 //$this->logger->logInfo("HOTD: ".$post_hotd, __METHOD__.','.__LINE__);
                 $responses_chron[$post_hotd] += $post->favlike_count_cache;
                 $punchcard['posts'][$post_dotm][$post_hotd]++;
             }
         }
         arsort($responses_chron);
         $most_responses = each($responses_chron);
         $insight_text = '';
         if ($most_responses['value'] > 2) {
             $time1_low_hotd = $most_responses['key'];
             $time1_high_hotd = $time1_low_hotd + 1;
             $time1_low = ($time1_low_hotd % 12 ? $time1_low_hotd % 12 : 12) . (floor($time1_low_hotd / 12) == 1 ? 'pm' : 'am');
             $time1_high = ($time1_high_hotd % 12 ? $time1_high_hotd % 12 : 12) . (floor($time1_high_hotd / 12) == 1 ? 'pm' : 'am');
             $plural = $most_responses['value'] == 1 ? InsightTerms::SINGULAR : InsightTerms::PLURAL;
             if ($instance->network == 'instagram') {
                 $insight_text = "In the past month, what " . $this->username . " posted " . "between <strong>" . $time1_low . " and " . $time1_high . "</strong> on Instagram got the most love - " . $most_responses['value'] . " " . $this->terms->getNoun('like', $plural) . " in all.";
             } else {
                 $insight_text = "In the past month, " . $this->username . "'s " . $this->terms->getNoun('post', InsightTerms::PLURAL) . " got the biggest response between <strong>" . $time1_low . " and " . $time1_high . "</strong> - " . $most_responses['value'] . " " . $this->terms->getNoun('reply', $plural) . " in all.";
             }
             // $this->logger->logInfo("Responses chron: ".Utils::varDumpToString($responses_chron),
             //     __METHOD__.','.__LINE__);
             foreach ($responses_chron as $key => $value) {
                 if ($value > 0 && $value < $most_responses['value']) {
                     $time2_low_hotd = $key;
                     $time2_high_hotd = $time2_low_hotd + 1;
                     $time2_low = ($time2_low_hotd % 12 ? $time2_low_hotd % 12 : 12) . (floor($time2_low_hotd / 12) == 1 ? 'pm' : 'am');
                     $time2_high = ($time2_high_hotd % 12 ? $time2_high_hotd % 12 : 12) . (floor($time2_high_hotd / 12) == 1 ? 'pm' : 'am');
                     if ($instance->network == 'instagram') {
                         $response_text = $value > 1 ? 'hearts' : 'heart';
                     } else {
                         $response_text = $value > 1 ? 'responses' : 'response';
                     }
                     $comparison_text = " That's compared to " . $value . " " . $response_text . " between " . $time2_low . " and " . $time2_high . ". ";
                 }
             }
             $insight_text .= $comparison_text;
             $headline = $this->username . "'s best time is around " . $time1_low;
             $optimal_hour = substr($time1_low, 0, -2);
             //Instantiate the Insight object
             $my_insight = new Insight();
             //REQUIRED: Set the insight's required attributes
             $my_insight->instance_id = $instance->id;
             $my_insight->slug = $this->slug;
             //slug to label this insight's content
             $my_insight->date = $this->insight_date;
             //date of the data this insight applies to
             $my_insight->headline = $headline;
             $my_insight->text = $insight_text;
             $my_insight->header_image = '';
             $my_insight->emphasis = Insight::EMPHASIS_HIGH;
             $my_insight->filename = basename(__FILE__, ".php");
             // $my_insight->related_data = $punchcard;
             $my_insight->related_data = $optimal_hour;
             $this->insight_dao->insertInsight($my_insight);
         } else {
             $this->logger->logInfo("No insight: Most responses is " . Utils::varDumpToString($most_responses), __METHOD__ . ',' . __LINE__);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
Ejemplo n.º 16
0
 public function testDailySendSetting()
 {
     unlink(FileDataManager::getDataPath(Mailer::EMAIL));
     $builders = array();
     $builders[] = FixtureBuilder::build('owners', array('id' => 1, 'full_name' => 'ThinkUp J. User', 'is_admin' => 1, 'email' => '*****@*****.**', 'is_activated' => 1, 'email_notification_frequency' => 'daily', 'timezone' => 'America/New_York'));
     $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 1, 'instance_id' => 5, 'auth_error' => ''));
     $builders[] = FixtureBuilder::build('instances', array('network_username' => 'cdmoyer', 'id' => 5, 'network' => 'twitter', 'is_activated' => 1, 'is_public' => 1));
     $builders[] = FixtureBuilder::build('insights', array('id' => 1, 'instance_id' => 5, 'slug' => 'new_group_memberships', 'prefix' => 'Made the List:', 'text' => 'CDMoyer is on 29 new lists', 'time_generated' => date('Y-m-d 03:00:00')));
     $builders[] = FixtureBuilder::build('insights', array('id' => 2, 'instance_id' => 5, 'slug' => 'new_group_memberships', 'prefix' => 'Made the List:', 'text' => 'CDMoyer is on 99 new lists', 'time_generated' => date('Y-m-d 01:00:00')));
     $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
     $options = $plugin_option_dao->getOptionsHash($plugin->folder_name, true);
     $this->assertEqual(count($options), 0);
     $this->simulateLogin('*****@*****.**');
     $plugin = new InsightsGeneratorPlugin();
     $plugin->current_timestamp = strtotime('5pm');
     $plugin->crawl();
     $options = $plugin_option_dao->getOptionsHash($plugin->folder_name, true);
     $this->debug(Utils::varDumpToString($options));
     $this->assertNotNull($options['last_daily_email'], 'last_daily_email set');
     $sent = Mailer::getLastMail();
     $this->assertNotEqual($sent, '');
     $this->assertPattern('/to.*daily@example.com/', $sent);
     $this->assertPattern('/29 new lists/', $sent);
     $this->assertPattern('/99 new lists/', $sent);
     unlink(FileDataManager::getDataPath(Mailer::EMAIL));
     $plugin->crawl();
     $sent = Mailer::getLastMail();
     $this->assertEqual('', $sent, 'Should not send again same day');
 }
Ejemplo n.º 17
0
 public function testInstallerIsThinkUpInstalled()
 {
     $this->debug("Running testInstallerIsThinkUpInstalled");
     $config = Config::getInstance();
     $config_array = $config->getValuesArray();
     $installer = Installer::getInstance();
     //drop some tables so is_installed will be false
     $this->DAO = new InstallerMySQLDAO($config_array);
     $q = "DROP TABLE " . $config->getValue('table_prefix') . "encoded_locations, " . $config->getValue('table_prefix') . "favorites, " . $config->getValue('table_prefix') . "follower_count, " . $config->getValue('table_prefix') . "groups, " . $config->getValue('table_prefix') . "group_members, " . $config->getValue('table_prefix') . "group_member_count, " . $config->getValue('table_prefix') . "hashtags," . $config->getValue('table_prefix') . "hashtags_posts, " . $config->getValue('table_prefix') . "instances, " . $config->getValue('table_prefix') . "instances_twitter, " . $config->getValue('table_prefix') . "invites," . $config->getValue('table_prefix') . "mentions," . $config->getValue('table_prefix') . "mentions_posts, " . $config->getValue('table_prefix') . "owner_instances, " . $config->getValue('table_prefix') . "owners, " . $config->getValue('table_prefix') . "options, " . $config->getValue('table_prefix') . "places," . $config->getValue('table_prefix') . "places_posts, " . $config->getValue('table_prefix') . "plugins, " . $config->getValue('table_prefix') . "post_errors, " . $config->getValue('table_prefix') . "posts, " . $config->getValue('table_prefix') . "stream_data, " . $config->getValue('table_prefix') . "stream_procs, " . $config->getValue('table_prefix') . "user_errors, " . $config->getValue('table_prefix') . "users;";
     PDODAO::$PDO->exec($q);
     if (file_exists(THINKUP_WEBAPP_PATH . 'config.inc.php')) {
         // test when config file exists
         $this->debug("config file exists");
         $version_met = $installer->checkStep1();
         $this->debug("version met " . Utils::varDumpToString($version_met));
         $db_check = $installer->checkDb($config_array);
         $this->debug("db check " . Utils::varDumpToString($db_check));
         $table_present = $installer->doThinkUpTablesExist($config_array);
         $this->debug("table present " . Utils::varDumpToString($table_present));
         $is_installed = $installer->isThinkUpInstalled($config_array);
         $this->debug("is installed " . Utils::varDumpToString($is_installed));
         $expected = $version_met && $db_check && $table_present;
         $this->assertEqual($is_installed, $expected);
         $this->assertFalse($is_installed);
     } else {
         // test when config doesn't exist
         $this->debug("config file does not exist");
         $this->assertFalse($installer->isThinkUpInstalled($this->config));
         $expected = $installer->getErrorMessages();
         $this->assertEqual($expected['config_file'], "Config file doesn't exist.");
     }
 }
Ejemplo n.º 18
0
 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     if ($instance->network == 'facebook') {
         parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
         $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
         $should_generate_insight = self::shouldGenerateWeeklyInsight('gender_analysis', $instance, null, false, $day_of_week = 5, null, $excluded_networks = array('twitter', 'instagram', 'foursquare', 'google+'));
         if ($should_generate_insight) {
             $fav_post_dao = DAOFactory::getDAO('FavoritePostDAO');
             $female_likes_total = 0;
             $male_likes_total = 0;
             $female_comments_total = 0;
             $male_comments_total = 0;
             foreach ($last_week_of_posts as $post) {
                 $gender_fav = $fav_post_dao->getGenderOfFavoriters($post->post_id, $post->network);
                 $this->logger->logInfo("Likes by gender for {$post->post_id} are " . Utils::varDumpToString($gender_fav), __METHOD__ . ',' . __LINE__);
                 if (isset($gender_fav['female_likes_count'])) {
                     $female_likes_total = $female_likes_total + intval($gender_fav['female_likes_count']);
                 }
                 if (isset($gender_fav['male_likes_count'])) {
                     $male_likes_total = $male_likes_total + intval($gender_fav['male_likes_count']);
                 }
                 $gender_comm = $fav_post_dao->getGenderOfCommenters($post->post_id, $post->network);
                 $this->logger->logInfo("Comments by gender for {$post->post_id} are " . Utils::varDumpToString($gender_comm), __METHOD__ . ',' . __LINE__);
                 if (isset($gender_comm['female_comment_count'])) {
                     $female_comments_total = $female_comments_total + intval($gender_comm['female_comment_count']);
                 }
                 if (isset($gender_comm['male_comment_count'])) {
                     $male_comments_total = $male_comments_total + intval($gender_comm['male_comment_count']);
                 }
                 $this->logger->logInfo("Male likes total is now {$male_likes_total}", __METHOD__ . ',' . __LINE__);
                 $this->logger->logInfo("Female likes total is now {$female_likes_total}", __METHOD__ . ',' . __LINE__);
                 $this->logger->logInfo("Male comments total is now {$male_comments_total}", __METHOD__ . ',' . __LINE__);
                 $this->logger->logInfo("Female comments total is now {$female_comments_total}", __METHOD__ . ',' . __LINE__);
             }
             $female_total = $female_likes_total + $female_comments_total;
             $male_total = $male_likes_total + $male_comments_total;
             $total_gender_data = $female_total + $male_total;
             $this->logger->logInfo("Of {$total_gender_data} bits of gender data the last week of posts, " . "{$female_total} were female and {$male_total} were male", __METHOD__ . ',' . __LINE__);
             // Only generate this insight if there is gender data for at least 3 comments and/or likes
             if ($total_gender_data >= 3) {
                 $gender_data = array('gender' => 'value', 'female' => $female_total, 'male' => $male_total);
                 $headlines = array("%genderucase reacted to %username's %posts the most", "%genderucase responded to %username's %posts the most", "%username's %posts resonated with %genderlcase");
                 $headlines_100percent = array("Only %genderlcase reacted to %username's %posts", "Only %genderlcase responded to %username's %posts", "%username's %posts resonated with %genderlcase");
                 if ($female_total > $male_total) {
                     if ($male_total == 0) {
                         $headline = $this->getVariableCopy($headlines_100percent, array('genderlcase' => 'women'));
                     } else {
                         $headline = $this->getVariableCopy($headlines, array('genderucase' => 'Women', 'genderlcase' => 'women'));
                     }
                     $text = "This past week, <strong>" . number_format($female_total) . " likes and comments</strong> on " . $instance->network_username . "'s status updates were by people who identify as female, compared to " . number_format($male_total) . " by people who identify as male.";
                 } elseif ($male_total > $female_total) {
                     if ($female_total == 0) {
                         $headline = $this->getVariableCopy($headlines_100percent, array('genderlcase' => 'men'));
                     } else {
                         $headline = $this->getVariableCopy($headlines, array('genderucase' => 'Men', 'genderlcase' => 'men'));
                     }
                     $text = "This past week, <strong>" . number_format($male_total) . " likes and comments</strong> on " . $instance->network_username . "'s status updates were by people who identify as male, compared to " . number_format($female_total) . " by people who identify as female.";
                 } else {
                     $headlines = array("Both genders reacted to %username's %posts equally", "Both genders responded to %username's %posts equally", "%username's %posts resonated with both genders");
                     $headline = $this->getVariableCopy($headlines);
                     $text = "This past week, people who identify as male and female liked and commented on " . "{$this->username}'s status updates at the same rate.";
                 }
                 $my_insight = new Insight();
                 $my_insight->slug = 'gender_analysis';
                 //slug to label this insight's content
                 $my_insight->instance_id = $instance->id;
                 $my_insight->headline = $headline;
                 $my_insight->text = $text;
                 $my_insight->date = $this->insight_date;
                 $my_insight->filename = basename(__FILE__, ".php");
                 $my_insight->emphasis = Insight::EMPHASIS_MED;
                 $my_insight->setPieChart($gender_data);
                 $this->insight_dao->insertInsight($my_insight);
             } else {
                 $this->logger->logInfo("Not enough gender data to generate insight", __METHOD__ . ',' . __LINE__);
             }
             $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
         } else {
             $this->logger->logInfo("Not generating insight for non-Facebook network", __METHOD__ . ',' . __LINE__);
         }
     }
 }
 public function test2LocalFollowersInsightWith1Verified()
 {
     // Get data ready that insight requires
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_user_id = 9654000768;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $builders = array();
     // User
     $builders[] = FixtureBuilder::build('users', array('user_id' => '9654000768', 'user_name' => 'testuser', 'full_name' => 'Twitter User', 'avatar' => 'avatar.jpg', 'follower_count' => 360, 'is_protected' => 1, 'network' => 'twitter', 'description' => 'A test Twitter User', 'location' => 'San Francisco, CA', 'friend_count' => 360, 'is_verified' => 0));
     // Followers
     $builders[] = FixtureBuilder::build('users', array('user_id' => '9654000769', 'user_name' => 'testfollower1', 'full_name' => 'Twitter Follower One', 'avatar' => 'avatar.jpg', 'follower_count' => 3600000, 'is_protected' => 0, 'network' => 'twitter', 'description' => 'A test Twitter Folower', 'location' => 'San Francisco, CA', 'friend_count' => 360, 'is_verified' => 0));
     $builders[] = FixtureBuilder::build('users', array('user_id' => '9654000770', 'user_name' => 'testfollower2', 'full_name' => 'Twitter Follower Two', 'avatar' => 'avatar.jpg', 'follower_count' => 360, 'is_protected' => 0, 'network' => 'twitter', 'description' => 'A test Twitter Folower', 'location' => 'San Francisco, CA', 'friend_count' => 360, 'is_verified' => 1));
     $builders[] = FixtureBuilder::build('users', array('user_id' => '9654000771', 'user_name' => 'testfollower3', 'full_name' => 'Twitter Follower Three', 'avatar' => 'avatar.jpg', 'follower_count' => 360, 'is_protected' => 0, 'network' => 'twitter', 'description' => 'A test Twitter Folower', 'location' => 'San Diego, CA', 'friend_count' => 360, 'is_verified' => 0));
     // Follows
     $builders[] = FixtureBuilder::build('follows', array('user_id' => '9654000768', 'follower_id' => '9654000769', 'last_seen' => '-0d', 'first_seen' => '-0d', 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => '9654000768', 'follower_id' => '9654000770', 'last_seen' => '-0d', 'first_seen' => '-0d', 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => '9654000768', 'follower_id' => '9654000771', 'last_seen' => '-0d', 'first_seen' => '-0d', 'network' => 'twitter'));
     // Initialize and run the insight
     $insight_plugin = new InterestingFollowersInsight();
     $insight_plugin->generateInsight($instance, $this->getUser(), $posts = array(), 3);
     //sleep(1000);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('local_followers', 10, $today);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertPattern('/@testuser got a new follower in San Francisco, CA/', $result->headline);
     $this->assertPattern('/avatar.jpg/', $result->header_image);
 }
Ejemplo n.º 20
0
 /**
  * If user doesn't exist in the datastore, fetch details from Facebook API and insert into the datastore.
  * If $reload_from_facebook is true, update existing user details in store with data from Facebook API.
  * @param int $user_id Facebook user ID
  * @param str $found_in Where the user was found
  * @param bool $reload_from_facebook Defaults to false; if true will query Facebook API and update existing user
  * @return User
  */
 public function fetchUser($user_id, $found_in, $force_reload_from_facebook = false)
 {
     //assume all users except the instance user is a facebook profile, not a page
     //@TODO: Start supporting users of type 'facebook page'
     $network = $user_id == $this->instance->network_user_id ? $this->instance->network : 'facebook';
     $user_dao = DAOFactory::getDAO('UserDAO');
     $user_object = null;
     if ($force_reload_from_facebook || !$user_dao->isUserInDB($user_id, $network)) {
         // Get owner user details and save them to DB
         $fields = $network != 'facebook page' ? 'id,name,is_verified,updated_time' : null;
         $user_details = FacebookGraphAPIAccessor::apiRequest($user_id, $this->access_token, null, $fields);
         if (isset($user_details)) {
             $user_details->network = $network;
         }
         $user = $this->parseUserDetails($user_details);
         if (isset($user)) {
             $user_object = new User($user, $found_in);
             $user_dao->updateUser($user_object);
         }
         if ($this->instance->network_user_id == $user_id && $user['updated_time']) {
             $this->instance->profile_updated = $user['updated_time'];
         }
         // Record the current number of page likes in follower count table
         if ($network == 'facebook page' && isset($user_details->likes) && !$this->page_like_count_set) {
             $count_dao = DAOFactory::getDAO('CountHistoryDAO');
             $count_dao->insert($this->instance->network_user_id, 'facebook page', $user_details->likes, null, 'followers');
             $this->page_like_count_set = true;
         }
         if (isset($user_object)) {
             $this->logger->logSuccess("Successfully fetched " . $user_id . " " . $network . "'s details from Facebook", __METHOD__ . ',' . __LINE__);
         } else {
             //@TODO: Most of these errors occur because TU doesn't yet support users of type 'facebook page'
             //We just assume every user is a vanilla FB user. However, we can't retrieve page details using
             //a vanilla user call here
             $this->logger->logInfo("Error fetching " . $user_id . " " . $network . "'s details from Facebook API, " . "response was " . Utils::varDumpToString($user_details), __METHOD__ . ',' . __LINE__);
         }
     }
     return $user_object;
 }
Ejemplo n.º 21
0
 public function testGetLinksForPost()
 {
     $result = $this->DAO->getLinksForPost(80, 'twitter');
     $this->debug(Utils::varDumpToString($result));
     $this->assertEqual(4, sizeof($result));
     //should be 4 links for this post
     $this->assertEqual($result[0]->url, "http://example.com/0");
     $this->assertEqual($result[1]->url, "http://flic.kr/p/0");
     $this->assertEqual($result[2]->url, "http://flic.kr/p/0e");
     $this->assertEqual($result[3]->url, "http://bit.ly/beEEfs");
     $result = $this->DAO->getLinksForPost(800, 'twitter');
     $this->assertEqual(0, sizeof($result));
     //should be no links for this post
 }
 public function testGetUserProfileWith403Error()
 {
     $builders = $this->buildPluginOptions();
     $config = Config::getInstance();
     $config->setValue('site_root_path', '/');
     $plugin_options_dao = DAOFactory::getDAO("PluginOptionDAO");
     PluginOptionMySQLDAO::$cached_options = array();
     $builders[] = FixtureBuilder::build('owners', array('email' => '*****@*****.**', 'user_activated' => 1));
     $this->simulateLogin('*****@*****.**');
     $owner_dao = DAOFactory::getDAO('OwnerDAO');
     $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
     $controller = new GooglePlusPluginConfigurationController($owner);
     $_GET['code'] = 'test-google-provided-code-user-profile-403-error';
     $results = $controller->go();
     $v_mgr = $controller->getViewManager();
     $this->assertEqual($v_mgr->getTemplateDataItem('success_msg'), '');
     $msgs = $v_mgr->getTemplateDataItem('error_msgs');
     $this->assertEqual($msgs['authorization'], 'Oops! Looks like Google+ API access isn\'t turned on. ' . '<a href="http://code.google.com/apis/console#access">In the Google APIs console</a>, in Services, flip the ' . 'Google+ API Status switch to \'On\' and try again.');
     $this->debug(Utils::varDumpToString($msgs));
 }
 public function testGroupMembershipGetDayHistoryWithGaps()
 {
     // Filling gaps was only required by the old visualization library
     $format = 'n/j';
     $date = date($format);
     $count_history = array('network_user_id' => '930061', 'network' => 'twitter', 'date' => '-1d', 'type' => 'group_memberships', 'count' => 140);
     $builder1 = FixtureBuilder::build('count_history', $count_history);
     $count_history = array('network_user_id' => '930061', 'network' => 'twitter', 'date' => '-2d', 'type' => 'group_memberships', 'count' => 100);
     $builder2 = FixtureBuilder::build('count_history', $count_history);
     $count_history = array('network_user_id' => '930061', 'network' => 'twitter', 'date' => '-5d', 'type' => 'group_memberships', 'count' => 120);
     $builder3 = FixtureBuilder::build('count_history', $count_history);
     $dao = new CountHistoryMySQLDAO();
     $result = $dao->getHistory('930061', 'twitter', 'DAY', 5, null, 'group_memberships');
     $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, milestone, and vis_data');
     //check history
     $this->assertEqual(sizeof($result['history']), 3);
     $format = 'm/d/Y';
     $this->debug(Utils::varDumpToString($result));
     $date_ago = date($format, strtotime('-5 day' . $date));
     $this->assertEqual($result['history'][$date_ago], 120);
     $date_ago = date($format, strtotime('-4 day' . $date));
     $this->assertTrue(!isset($result['history'][$date_ago]), 'gap filled');
     $date_ago = date($format, strtotime('-3 day' . $date));
     $this->assertTrue(!isset($result['history'][$date_ago]), 'gap filled');
     $date_ago = date($format, strtotime('-2 day' . $date));
     $this->assertEqual($result['history'][$date_ago], 100);
     $date_ago = date($format, strtotime('-1 day' . $date));
     $this->assertEqual($result['history'][$date_ago], 140);
     //check trend
     $this->assertFalse($result['trend']);
     //check milestone
     $this->assertFalse($result['milestone']);
 }
 public function testConnectAccountThatAlreadyExists()
 {
     self::buildInstanceData();
     $owner_instance_dao = new OwnerInstanceMySQLDAO();
     $instance_dao = new InstanceMySQLDAO();
     $owner_dao = new OwnerMySQLDAO();
     $config = Config::getInstance();
     $config->setValue('site_root_path', '/');
     $_SERVER['SERVER_NAME'] = "srvr";
     SessionCache::put('facebook_auth_csrf', '123');
     $_GET['p'] = 'facebook';
     $_GET['code'] = '456';
     $_GET['state'] = '123';
     $options_arry = $this->buildPluginOptions();
     $this->simulateLogin('*****@*****.**', true);
     $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
     $controller = new FacebookPluginConfigurationController($owner, 'facebook');
     $output = $controller->go();
     $v_mgr = $controller->getViewManager();
     $msgs = $v_mgr->getTemplateDataItem('success_msgs');
     $this->assertEqual($msgs['user_add'], "Success! You've reconnected your Facebook account. To connect " . "a different account, log  out of Facebook in a different browser tab and try again.");
     $this->debug(Utils::varDumpToString($msgs));
     $instance = $instance_dao->getByUserIdOnNetwork('606837591', 'facebook');
     $this->assertNotNull($instance);
     $owner_instance = $owner_instance_dao->get($owner->id, $instance->id);
     $this->assertNotNull($owner_instance);
     $this->assertEqual($owner_instance->oauth_access_token, 'newfauxaccesstoken11234567890');
 }
Ejemplo n.º 25
0
 public function testOscars2015OnlyALoserReference()
 {
     // Get data ready that insight requires
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_username = '******';
     $instance->network = 'facebook';
     $builders = self::setUpPublicInsight($instance);
     $builders[] = FixtureBuilder::build('posts', array('post_text' => 'That Jonah Hill sucks.', 'pub_date' => '2015-02-19', 'author_username' => $instance->network_username, 'network' => $instance->network));
     $posts = array();
     $insight_plugin = new Oscars2015Insight();
     $insight_plugin->generateInsight($instance, null, $posts, 3);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('oscars_2015', 1, $today);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNull($result);
 }
Ejemplo n.º 26
0
 public function testAllAboutYouInsightPriorEqualBaseline()
 {
     // Get data ready that insight requires
     $posts = self::getTestPostObjects();
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_username = '******';
     $instance->network = 'twitter';
     $insight_plugin = new AllAboutYouInsight();
     // Add a baseline from prior week
     $last_week = date('Y-m-d', strtotime('-7 day'));
     $builder = FixtureBuilder::build('insight_baselines', array('date' => $last_week, 'slug' => 'all_about_you', 'instance_id' => 10, 'value' => 9));
     $insight_plugin->generateInsight($instance, $posts, 3);
     // Assert that week-over-week comparison is correct
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('all_about_you', 10, $today);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertPattern('/\\@testeriffic\'s posts contained the words/', $result->text);
     $this->assertPattern('/9 times/', $result->text);
     //assert no comparison to prior week
     $this->assertNoPattern('/prior week/', $result->text);
     $this->assertNoPattern('/prior week/', $result->text);
 }
Ejemplo n.º 27
0
 public function testBarelySlower()
 {
     // 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' => 0, 'retweet_count_cache' => 0, 'favlike_count_cache' => 6));
     // 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' => 'response_count_like', 'instance_id' => 10, 'value' => 7));
     $insight_plugin = new ResponseTimeInsight();
     $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('response_time', 10, $today);
     $this->debug(Utils::varDumpToString($result));
     $this->assertNotNull($result);
     $this->assertNoPattern('/slower/', $result->text);
     $this->assertNoPattern('/every day/', $result->text);
     $this->assertPattern('/<strong>day<\\/strong>/', $result->headline);
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 public function testParseError()
 {
     $to = new TwitterOAuth('', '', '', '');
     //Public statuses
     $twitter_data = $to->http('https://twitter.com/statuses/user_timeline/ginatrasdfasdfasdapani.xml?count=100');
     $api = new CrawlerTwitterAPIAccessorOAuth('111', '222', 1234, 1234, 5, 3200, 5, 350);
     $results = $api->parseError($twitter_data);
     $this->debug(Utils::varDumpToString($results));
     $this->assertEqual($results['error'], 'Not found');
     $this->assertEqual($results['request'], '/statuses/user_timeline/ginatrasdfasdfasdapani.xml?count=100');
 }
Ejemplo n.º 29
0
 public function testFetchPrivateInstanceUserTweets()
 {
     self::setUpInstanceUserPrivateMcPrivate();
     $twitter_crawler = new TwitterCrawler($this->instance, $this->api);
     $twitter_crawler->fetchInstanceUserTweets();
     //Test post is set as protected
     $post_dao = DAOFactory::getDAO('PostDAO');
     $this->assertTrue($post_dao->isPostInDB('14846078418', 'twitter'));
     $post = $post_dao->getPost('14846078418', 'twitter');
     $this->debug(Utils::varDumpToString($post));
     $this->assertTrue($post->is_protected);
 }
Ejemplo n.º 30
0
 public function testExpandInstagramImageURLs()
 {
     $builders = $this->buildInstagramData();
     $crawler = Crawler::getInstance();
     $config = Config::getInstance();
     $option_builder = FixtureBuilder::build('options', array('namespace' => OptionDAO::PLUGIN_OPTIONS . '-4', 'option_name' => 'flickr_api_key', 'option_value' => 'dummykey'));
     $this->simulateLogin('*****@*****.**', true);
     $crawler->crawl();
     $link_dao = DAOFactory::getDAO('LinkDAO');
     $link = $link_dao->getLinkById(43);
     $this->debug(Utils::varDumpToString($link));
     //Instagr.am constantly changes the location of their images so it's an unpredictable assertion
     //        $this->assertEqual($link->expanded_url,
     //        'http://images.instagram.com/media/2010/12/20/f0f411210cc54353be07cf74ceb79f3b_7.jpg');
     $this->assertEqual($link->error, '');
     $link = $link_dao->getLinkById(42);
     $this->assertEqual($link->expanded_url, 'http://instagr.am/41');
     $this->assertEqual($link->image_src, 'http://instagr.am/41/media/');
     $this->assertEqual($link->error, '');
     $link = $link_dao->getLinkById(41);
     $this->assertEqual($link->expanded_url, 'http://instagr.am/40');
     $this->assertEqual($link->image_src, 'http://instagr.am/40/media/');
     $this->assertEqual($link->error, '');
 }