public function testStyleStats()
 {
     // Assert that insight doesn't exist
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('style_stats', 1, date('Y-m-d'));
     $this->assertNull($result);
     $builders = self::buildData();
     // Add post that's not a photo, link, quotation, or question
     $post1_builder = FixtureBuilder::build('posts', array('id' => 28, 'post_id' => '28', 'author_user_id' => '13', 'author_username' => 'ev', 'author_fullname' => 'Ev Williams', 'author_avatar' => 'avatar.jpg', 'post_text' => 'This is post 28', 'source' => 'web', 'pub_date' => '-1d', 'reply_count_cache' => 0, 'is_protected' => 0, 'retweet_count_cache' => 0, 'network' => 'twitter', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'is_geo_encoded' => 0));
     $link1_builder = FixtureBuilder::build('links', array('id' => 28, 'post_key' => '28', 'short_url' => 'http://bit.ly/blah', 'expanded_url' => 'http://expandedurl.com/asfasdfadsf/adsfa'));
     $builders[] = FixtureBuilder::build('links_short', array('id' => 28, 'link_id' => '28', 'short_url' => 'http://bit.ly/blah' . $counter, 'click_count' => 7609));
     $builders[] = FixtureBuilder::build('insights', array('slug' => 'PostMySQLDAO::getHotPosts', 'date' => date('Y-m-d'), 'instance_id' => 1));
     // Add a question
     $post2_builder = FixtureBuilder::build('posts', array('id' => 29, 'post_id' => '29', 'author_user_id' => '13', 'author_username' => 'ev', 'author_fullname' => 'Ev Williams', 'author_avatar' => 'avatar.jpg', 'post_text' => 'Is this post 29?', 'source' => 'web', 'pub_date' => '-1d', 'reply_count_cache' => 0, 'is_protected' => 0, 'retweet_count_cache' => 0, 'network' => 'twitter', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'is_geo_encoded' => 0));
     $post_dao = new PostMySQLDAO();
     $last_week_of_posts = $post_dao->getAllPostsByUsernameOrderedBy('ev', 'twitter', $count = 0, $order_by = "pub_date", $in_last_x_days = 7, $iterator = false, $is_public = false);
     $instance = new Instance();
     $instance->id = 1;
     $instance->network_user_id = '13';
     $instance->network = 'twitter';
     $instance->network_username = '******';
     $stylestats_insight_plugin = new StyleStatsInsight();
     $stylestats_insight_plugin->generateInsight($instance, null, $last_week_of_posts, 3);
     // Assert that insight got generated
     $insight_dao = new InsightMySQLDAO();
     $result = $insight_dao->getInsight('style_stats', 1, date('Y-m-d'));
     $this->assertNotNull($result);
     $this->assertEqual($result->slug, 'style_stats');
     $this->assertEqual($result->filename, 'stylestats');
     $this->assertEqual("7 of @ev's posts this week were photos and 1 was a question", $result->headline);
     //sleep(1000);
 }
Example #2
0
 public function addVideo($vals)
 {
     $res = null;
     // Check all the fields we need are set
     if (self::hasAllRequiredFields($vals)) {
         // Insert the values which go into the post table
         $row_id = parent::addPost($vals);
         // If the post insertion went fine insert the values that go into the videos table
         if ($row_id != null) {
             //SQL variables to bind
             $vars = array();
             //SQL query
             $q = "INSERT IGNORE INTO #prefix#videos SET ";
             //Set up required fields
             foreach ($this->REQUIRED_VIDEO_FIELDS as $field) {
                 $q .= $field . "=:" . $field . ", ";
                 $vars[':' . $field] = $vals[$field];
             }
             // Append the internal post ID
             $q .= 'post_key=:post_key';
             $vars[':post_key'] = $row_id;
             // Try to insert the video
             if ($this->profiler_enabled) {
                 Profiler::setDAOMethod(__METHOD__);
             }
             $ps = $this->execute($q, $vars);
             $res = $this->getInsertId($ps);
         } else {
             // If the video was already in the database, update the counts
             $res = self::updateVideoCounts($vals);
         }
     }
     return $res;
 }
 public function adminControl()
 {
     $post_dao = new PostMySQLDAO();
     if (!isset($_POST['upgrade'])) {
         if ($post_dao->needsSnowflakeUpgrade()) {
             $this->addInfoMessage('In order to work correctly, your ThinkUp database needs an upgrade to suppport ' . '<a href="http://engineering.twitter.com/2010/06/announcing-snowflake.html">Twitter\'s new 64-bit ' . 'post IDs</a>.  On large ThinkUp databases, this update can take a very long time.');
             $this->addToView('needs_upgrade', true);
         } else {
             $this->addSuccessMessage('Your database is up to date.');
         }
     } else {
         if ($post_dao->needsSnowflakeUpgrade()) {
             $changed = $post_dao->performSnowflakeUpgrade();
             $this->addSuccessMessage('Database updated! ' . $changed . ' rows affected. You may continue using ' . 'ThinkUp as usual.');
         } else {
             $this->addSuccessMessage('Your database is up to date.');
         }
     }
     return $this->generateView();
 }
 public function testGetPostCountForYear()
 {
     $year = date('Y');
     $user = "******";
     $network = "twitter";
     // Five posts from current year
     for ($i = 1; $i < 6; $i++) {
         $builders[] = FixtureBuilder::build('posts', array('post_text' => 'This is a post', 'pub_date' => "{$year}-0{$i}-07 {$i0}:{$i0}:00", 'author_username' => $user, 'network' => $network, 'post_id' => 2356 + $i));
     }
     // a post from last year
     $builders[] = FixtureBuilder::build('posts', array('post_text' => 'This is an old post', 'pub_date' => "2013-01-07 10:10:00", 'author_username' => $user, 'network' => $network, 'post_id' => 3356 + $i));
     // 2 posts from next year
     for ($i = 1; $i < 3; $i++) {
         $next_year = $year + 1;
         $builders[] = FixtureBuilder::build('posts', array('post_text' => 'This is an old post', 'pub_date' => "{$next_year}-01-07 10:10:00", 'author_username' => $user, 'network' => $network, 'post_id' => 4356 + $i));
     }
     $post_dao = new PostMySQLDAO();
     // test that query returns a post_count of 5
     $total_post_count = $post_dao->getPostCountForYear($author_username = $user, $network = $network, $year = $year);
     $this->assertEqual(5, $total_post_count['post_count']);
     // test that query returns a post_count of 1 for 2013
     $total_post_count = $post_dao->getPostCountForYear($author_username = $user, $network = $network, $year = 2013);
     $this->assertEqual(1, $total_post_count['post_count']);
     // test that query returns a post_count of 1 for $next_year
     $total_post_count = $post_dao->getPostCountForYear($author_username = $user, $network = $network, $year = $next_year);
     $this->assertEqual(2, $total_post_count['post_count']);
 }
Example #5
0
 public function testUpdatePostText()
 {
     $dao = new PostMySQLDAO();
     $post = $dao->getPost(10, 'twitter');
     $this->assertEqual($post->post_text, "This is post 10");
     // bad id
     $update_cnt = $dao->updatePostText(-99, 'twitter', 'updated post text');
     $this->assertEqual($update_cnt, 0);
     // bad network
     $update_cnt = $dao->updatePostText(10, 'no-net', 'updated post text');
     $this->assertEqual($update_cnt, 0);
     // good id
     $update_cnt = $dao->updatePostText(10, 'twitter', 'This is updated post 10');
     $this->assertEqual($update_cnt, 1);
     $post = $dao->getPost(10, 'twitter');
     $this->assertEqual($post->post_text, 'This is updated post 10');
 }
 public function testGetMostPopularPostsOfTheYear()
 {
     $post_dao = new PostMySQLDAO();
     $posts = $post_dao->getMostPopularPostsOfTheYear('13', 'twitter', '2006');
     $this->assertEqual(sizeof($posts), 25);
     foreach ($posts as $post) {
         $this->assertIsA($post, 'Post');
         $this->assertNotNull($post->id);
         $this->assertEqual($post->author_user_id, '13');
         $this->assertEqual($post->author_username, 'ev');
         $this->assertNull($post->in_reply_to_user_id);
         $this->assertNull($post->in_retweet_of_post_id);
         $this->assertNull($post->in_rt_of_user_id);
         $this->assertEqual(date('Y', strtotime($post->pub_date)), '2006');
     }
 }
Example #7
0
 public function getPhoto($post_id, $network, $is_public = false)
 {
     $associated_post = parent::getPost($post_id, $network, $is_public);
     $photo = self::getPhotoObjectFromAssociatedPostObject($associated_post);
     return $photo;
 }
 public function testSearchPostsByHashtag()
 {
     $dao = new PostMySQLDAO();
     $hashtag = new Hashtag();
     $hashtag->id = 1;
     //First search hashtag that exists
     $output = $dao->searchPostsByHashtag(array(), $hashtag, 'twitter');
     $this->assertEqual(sizeof($output), 20);
     $this->assertTrue(is_array($output));
     $counter = 359;
     foreach ($output as $post) {
         $this->assertTrue($post instanceof Post);
         $this->assertEqual($post->post_id, $counter);
         $counter = $counter - 2;
     }
     //Test page_count
     for ($i = 30; $i > 1; $i--) {
         $output = $dao->searchPostsByHashtag(array(), $hashtag, 'twitter', 1, $i);
         $this->assertEqual(sizeof($output), $i);
         $counter = 359;
         foreach ($output as $post) {
             $this->assertEqual($post->post_id, $counter);
             $counter = $counter - 2;
         }
     }
     //Test page
     for ($i = 1; $i < 4; $i++) {
         $output = $dao->searchPostsByHashtag(array(), $hashtag, 'twitter', $i);
         switch ($i) {
             case 1:
                 $this->assertEqual(sizeof($output), 20);
                 break;
             case 2:
                 $this->assertEqual(sizeof($output), 10);
                 break;
             case 3:
                 $this->assertEqual(sizeof($output), 0);
                 break;
         }
     }
     //test second hashtag search that exists
     $hashtag = new Hashtag();
     $hashtag->id = 2;
     $output = $dao->searchPostsByHashtag(array(), $hashtag, 'twitter', 1, 60);
     $this->assertEqual(sizeof($output), 30);
     $this->assertTrue(is_array($output));
     $counter = 358;
     foreach ($output as $post) {
         $this->assertEqual($post->post_id, $counter);
         $counter = $counter - 2;
     }
 }
 /**
  * Test getClientsUsedByUserOnNetwork
  */
 public function testGetClientsUsedByUserOnNetwork()
 {
     $dao = new PostMySQLDAO();
     list($all_time_clients_usage, $latest_clients_usage) = $dao->getClientsUsedByUserOnNetwork(13, 'twitter');
     $this->assertIsA($all_time_clients_usage, 'array');
     $this->assertEqual(sizeof($all_time_clients_usage), 3);
     $this->assertEqual($all_time_clients_usage['Tweetie for Mac'], 14);
     $this->assertEqual($all_time_clients_usage['web'], 14);
     $this->assertEqual($all_time_clients_usage['Tweet Button'], 13);
     $keys = array_keys($all_time_clients_usage);
     $this->assertEqual($keys[0], 'Tweetie for Mac');
     $this->assertEqual($keys[1], 'web');
     $this->assertEqual($keys[2], 'Tweet Button');
     $this->assertIsA($latest_clients_usage, 'array');
     $this->assertEqual(sizeof($latest_clients_usage), 3);
     $this->assertEqual($latest_clients_usage['Tweetie for Mac'], 8);
     $this->assertEqual($latest_clients_usage['web'], 9);
     $this->assertEqual($latest_clients_usage['Tweet Button'], 8);
     $keys = array_keys($latest_clients_usage);
     $this->assertEqual($keys[0], 'web');
     $this->assertEqual($keys[1], 'Tweet Button');
     $this->assertEqual($keys[2], 'Tweetie for Mac');
 }
 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 testGetUserPostsInRange()
 {
     $dao = new PostMySQLDAO();
     $posts = $dao->getPostsByUserInRange(18, 'twitter', $from = '2006-01-02 00:00:00', $until = '2006-01-02 00:30:59', $order_by = "pub_date", $direction = "DESC", $iterator = false, $is_public = false);
     // test date ordering and time range check
     $date = strtotime($posts[0]->pub_date);
     foreach ($posts as $post) {
         $this->assertEqual($post->author_user_id, 18);
         $this->assertTrue(strtotime($post->pub_date) >= strtotime('2006-01-02 00:00:00'));
         $this->assertTrue(strtotime($post->pub_date) < strtotime('2006-01-02 00:30:59'));
         $this->assertTrue(strtotime($post->pub_date) <= $date);
         $date = strtotime($post->pub_date);
     }
     // test ascending order
     $posts = $dao->getPostsByUserInRange(18, 'twitter', $from = '2006-01-02 00:00:00', $until = '2006-01-02 00:30:59', $order_by = "pub_date", $direction = "ASC", $iterator = false, $is_public = false);
     $date = strtotime($posts[0]->pub_date);
     foreach ($posts as $post) {
         $this->assertTrue(strtotime($post->pub_date) >= $date);
         $date = strtotime($post->pub_date);
     }
     // test filter protected posts
     $posts = $dao->getPostsByUserInRange(18, 'twitter', $from = '2006-01-02 00:00:00', $until = '2006-01-02 00:59:59', $order_by = "pub_date", $direction = "DESC", $iterator = false, $is_public = true);
     foreach ($posts as $post) {
         $this->assertEqual($post->is_protected, false);
     }
     // test range with no posts
     $posts = $dao->getPostsByUserInRange(18, 'twitter', $from = '1970-01-02 00:00:00', $until = '1971-01-02 00:59:59', $order_by = "pub_date", $direction = "DESC", $iterator = false, $is_public = true);
     $this->assertEqual(sizeof($posts), 0);
     // test from greater than until
     $posts = $dao->getPostsByUserInRange(18, 'twitter', $from = '2008-01-02 00:00:00', $until = '2006-01-02 00:59:59', $order_by = "pub_date", $direction = "DESC", $iterator = false, $is_public = true);
     $this->assertEqual(sizeof($posts), 0);
 }
Example #12
0
 public function testCountCheckinsToPlaceTypesLastWeek()
 {
     $dao = new PostMySQLDAO();
     // Add place information for checkins
     $place = array();
     $place['place_id'] = '12345a';
     $place['place_type'] = "Park";
     $place['name'] = "A Park";
     $place['full_name'] = "The Greatest Park";
     $place['country_code'] = "UK";
     $place['country'] = "United Kingdom";
     $place['icon'] = "http://www.iconlocation.com";
     $place['network'] = "foursquare";
     $place['longlat'] = "GeometryFromText( 'Point(51.514 -0.1167)' )";
     $place['bounding_box'] = "PolygonFromText( 'Polygon(-0.213503 51.512805,-0.105303 51.512805," . "-0.105303 51.572068,-0.213503 51.572068, -0.213503 51.512805)')";
     $place['map_image'] = "http://www.mapimage.com";
     $this->builders[] = FixtureBuilder::build('places', $place);
     $place = array();
     $place['place_id'] = '12345b';
     $place['place_type'] = "Museum";
     $place['name'] = "A Park";
     $place['full_name'] = "The Greatest Park";
     $place['country_code'] = "UK";
     $place['country'] = "United Kingdom";
     $place['icon'] = "http://www.iconlocation.com";
     $place['network'] = "foursquare";
     $place['longlat'] = "GeometryFromText( 'Point(51.514 -0.1167)' )";
     $place['bounding_box'] = "PolygonFromText( 'Polygon(-0.213503 51.512805,-0.105303 51.512805," . "-0.105303 51.572068,-0.213503 51.572068, -0.213503 51.512805)')";
     $place['map_image'] = "http://www.mapimage.com";
     $this->builders[] = FixtureBuilder::build('places', $place);
     $place = array();
     $place['place_id'] = '12345c';
     $place['place_type'] = "Museum";
     $place['name'] = "A Park";
     $place['full_name'] = "The Greatest Park";
     $place['country_code'] = "UK";
     $place['country'] = "United Kingdom";
     $place['icon'] = "http://www.iconlocation.com";
     $place['network'] = "foursquare";
     $place['longlat'] = "GeometryFromText( 'Point(51.514 -0.1167)' )";
     $place['bounding_box'] = "PolygonFromText( 'Polygon(-0.213503 51.512805,-0.105303 51.512805," . "-0.105303 51.572068,-0.213503 51.572068, -0.213503 51.512805)')";
     $place['map_image'] = "http://www.mapimage.com";
     $this->builders[] = FixtureBuilder::build('places', $place);
     // ensure this is not this week
     $this->builders[] = FixtureBuilder::build('posts', array('post_id' => '249', 'author_user_id' => '20', 'author_username' => 'user1', 'author_fullname' => 'User 1', 'network' => 'foursquare', 'post_text' => 'I just checked in', 'source' => '', 'pub_date' => '2011-12-1 09:50:00', 'location' => 'England', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place' => 'The Park', 'place_id' => '12345a', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'foursquare', 'in_reply_to_user_id' => '23', 'in_reply_to_post_id' => null, 'geo' => '52.477192843264,-1.484333726346'));
     $res = $dao->countCheckinsToPlaceTypesLastWeek(20, 'foursquare');
     // We now have posts, but they are way in the past.  Nothing this week
     $this->assertEqual($res, '');
     // now we add some this week.
     $this->builders[] = FixtureBuilder::build('posts', array('post_id' => '250', 'author_user_id' => '20', 'author_username' => 'user1', 'author_fullname' => 'User 1', 'network' => 'foursquare', 'post_text' => 'I just checked in', 'source' => '', 'pub_date' => date('Y-m-d') . ' 09:50:00', 'location' => 'England', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place' => 'The Park', 'place_id' => '12345a', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'foursquare', 'in_reply_to_user_id' => '23', 'in_reply_to_post_id' => null, 'geo' => '52.477192843264,-1.484333726346'));
     $this->builders[] = FixtureBuilder::build('posts', array('post_id' => '251', 'author_user_id' => '20', 'author_username' => 'user1', 'author_fullname' => 'User 1', 'network' => 'foursquare', 'post_text' => 'I just checked in', 'source' => '', 'pub_date' => date('Y-m-d') . ' 09:50:00', 'location' => 'England', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place' => 'The Park', 'place_id' => '12345c', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'foursquare', 'in_reply_to_user_id' => '23', 'in_reply_to_post_id' => null, 'geo' => '52.477192843264,-1.484333726346'));
     $this->builders[] = FixtureBuilder::build('posts', array('post_id' => '253', 'author_user_id' => '20', 'author_username' => 'user1', 'author_fullname' => 'User 1', 'network' => 'foursquare', 'post_text' => 'I just checked in', 'source' => '', 'pub_date' => date('Y-m-d') . ' 09:51:00', 'location' => 'England', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place' => 'The Park', 'place_id' => '12345b', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'foursquare', 'in_reply_to_user_id' => '23', 'in_reply_to_post_id' => null, 'geo' => '52.477192843264,-1.484333726346'));
     // Now we have actual checkins this week.
     // 2 Museums, 1 Park
     // And we can verify the formatting for the charts.
     $res = $dao->countCheckinsToPlaceTypesLastWeek(20, 'foursquare');
     $this->assertNotEqual($res, '');
     $res = json_decode($res);
     $this->assertEqual($res->rows[0]->c[0]->v, 'Museum');
     $this->assertEqual($res->rows[0]->c[0]->f, 'Museum');
     $this->assertEqual($res->rows[0]->c[1]->v, 2);
     $this->assertEqual($res->rows[1]->c[0]->v, 'Park');
     $this->assertEqual($res->rows[1]->c[0]->f, 'Park');
     $this->assertEqual($res->rows[1]->c[1]->v, 1);
     $this->assertEqual($res->cols[0]->type, 'string');
     $this->assertEqual($res->cols[0]->label, 'Place Type');
     $this->assertEqual($res->cols[1]->type, 'number');
     $this->assertEqual($res->cols[1]->label, 'Number of Checkins to this place type');
 }
Example #13
0
 public function testPerformSnowflakeUpgrade()
 {
     $dao = new PostMySQLDAO();
     $this->assertFalse($dao->needsSnowflakeUpgrade());
     $changed = $dao->performSnowflakeUpgrade();
     $this->assertEqual($changed, 0);
     $this->db->exec('ALTER TABLE tu_posts CHANGE post_id post_id bigint(11) NOT NULL;');
     $this->db->exec('ALTER TABLE tu_instances CHANGE last_post_id last_status_id bigint(11) NOT NULL;');
     $this->assertTrue($dao->needsSnowflakeUpgrade());
     $changed = $dao->performSnowflakeUpgrade();
     $this->assertEqual($changed, 149);
     //144 posts + 5 instances
     $this->db->exec('ALTER TABLE tu_posts CHANGE post_id post_id bigint(11) NOT NULL;');
     $this->db->exec('ALTER TABLE tu_links CHANGE post_id post_id bigint(11) NOT NULL;');
     $this->db->exec('ALTER TABLE tu_instances CHANGE last_post_id last_status_id bigint(11) NOT NULL;');
     $this->assertTrue($dao->needsSnowflakeUpgrade());
     $changed = $dao->performSnowflakeUpgrade();
     $this->assertEqual($changed, 230);
     //225 posts + 5 instances
 }
 public function testFetchPostsAndRepliesForPage()
 {
     $fbc = new FacebookCrawler($this->page1_instance, 'abc', 10);
     $fbc->fetchPostsAndReplies();
     $post_dao = new PostMySQLDAO();
     $post = $post_dao->getPost('10152714332426356', 'facebook page');
     $this->assertEqual($post->post_text, 'Looks like a very serene place to work:');
     $this->assertFalse($post->is_protected);
     $this->assertEqual($post->reply_count_cache, 4);
     //test link with image
     $this->assertEqual(sizeof($post->links), 1);
     $this->assertEqual($post->links[0]->url, 'http://lifehac.kr/Jg0mR3E');
     $this->assertEqual($post->links[0]->expanded_url, '');
     $this->assertEqual($post->links[0]->image_src, 'https://fbexternal-a.akamaihd.net/safe_image.php?d=AQDJyDKV3JDoU0-y&w=130&h=130&url=http%3A%2F%2' . 'Fi.kinja-img.com%2Fgawker-media%2Fimage%2Fupload%2Fs--G2ekOhHZ--%2Fgobnypf78nigkkl7cwpl.png&cfs=1');
     $this->assertEqual($post->links[0]->description, 'Today’s featured workspace looks immaculate, with its pristine white walls, simple white desk, and ' . 'wood accents. Those skylights help too.');
     //assert user network is set to Facebook, not Facebook Page
     $ud = new UserMySQLDAO();
     $user = $ud->getUserByName('Gregory Robert Dumas', 'facebook');
     $this->assertEqual($user->full_name, 'Gregory Robert Dumas');
     $this->assertEqual($user->network, 'facebook');
     $this->assertTrue($user->is_protected);
     $user = $ud->getUserByName('Matthew Fleisher', 'facebook page');
     $this->assertEqual($user, null);
     $fav_dao = new FavoritePostMySQLDAO();
     $favs = $fav_dao->getUsersWhoFavedPost('10152714332426356', 'facebook page');
     $this->assertEqual($favs[0]['user_name'], 'Peter-Sarah Crofton');
     $this->assertEqual($favs[0]['user_id'], '25913266');
     // Test Facebook paging by confirming post on second "page" was captured
     $post = $post_dao->getPost('10152712264921356', 'facebook page');
     $this->assertNotNull($post);
     $this->assertEqual($post->author_user_id, '7568536355');
 }
Example #15
0
 public function testSearchPostsByUsername()
 {
     $post_dao = new PostMySQLDAO();
     //should be first page of 20
     $results = $post_dao->searchPostsByUser(array('post'), 'twitter', 'ev');
     $this->assertEqual(sizeof($results), 20);
     //page 2
     $results = $post_dao->searchPostsByUser(array('post'), 'twitter', 'ev', 2);
     $this->assertEqual(sizeof($results), 19);
     //empty page 3
     $results = $post_dao->searchPostsByUser(array('post'), 'twitter', 'ev', 3);
     $this->assertEqual(sizeof($results), 0);
     //test and
     $results = $post_dao->searchPostsByUser(array('post', 'asdf'), 'twitter', 'ev');
     $this->assertEqual(sizeof($results), 0);
     $results = $post_dao->searchPostsByUser('keyword', 'twitter', 'ev');
     $this->assertEqual(sizeof($results), 0);
 }
 public function testGenderAnalysisForFacebookLessThanThreeGenderDataBits()
 {
     // Get data ready that insight requires
     $builders = array();
     // Build users
     $builders[] = FixtureBuilder::build('users', array('user_id' => '9654321', 'user_name' => 'Gloria Steinem', 'full_name' => 'Gloria Steinem', 'gender' => 'female', 'avatar' => 'avatar.jpg', 'is_protected' => 0, 'network' => $network));
     $builders[] = FixtureBuilder::build('users', array('user_id' => '9654320', 'user_name' => 'Abraham Lincoln', 'full_name' => 'Abraham Lincoln', 'gender' => 'male', 'avatar' => 'avatar.jpg', 'is_protected' => 0, 'network' => $network));
     // Posts
     $builders[] = FixtureBuilder::build('posts', array('id' => 333, 'post_id' => 333, 'author_user_id' => '9654321', 'author_username' => 'Gloria Steinem', 'author_fullname' => 'Gloria Steinem', 'author_avatar' => 'avatar.jpg', 'network' => $network, 'post_text' => 'This is a simple post.', 'pub_date' => '-1d', 'reply_count_cache' => 3, 'is_protected' => 0, 'favlike_count_cache' => 2));
     $builders[] = FixtureBuilder::build('posts', array('id' => 334, 'post_id' => 334, 'author_user_id' => '9654321', 'author_username' => 'Gloria Steinem', 'author_fullname' => 'Gloria Steinem', 'author_avatar' => 'avatar.jpg', 'network' => $network, 'post_text' => 'This is a simple comment.', 'pub_date' => '-2h', 'reply_count_cache' => 0, 'is_protected' => 0, 'favlike_count_cache' => 0, 'in_reply_to_post_id' => 333));
     $instance = new Instance();
     $instance->id = 100;
     $instance->network_user_id = '8654321';
     $instance->network_username = '******';
     $instance->network = 'facebook';
     $post_dao = new PostMySQLDAO();
     $last_week_of_posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $network = $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = $number_days, $iterator = false, $is_public = false);
     $insight_plugin = new GenderAnalysisInsight();
     $insight_plugin->generateInsight($instance, null, $last_week_of_posts, 1);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('gender_analysis', 100, $today);
     $this->assertNull($result);
 }
Example #17
0
 public function testFetchInstanceUserVideos()
 {
     $builders = self::buildData();
     $ytc = new YouTubeCrawler($this->instance, 'at', 20);
     $ytc->fetchInstanceUserVideos();
     $video_dao = new VideoMySQLDAO();
     $post_dao = new PostMySQLDAO();
     $count_history_dao = new CountHistoryMySQLDAO();
     // Check the first video got added
     $video_one = $video_dao->getVideoByID('H', 'youtube');
     $this->assertEqual($video_one->post_text, 'My Slideshow');
     $this->assertEqual($video_one->description, 'I created this video with the YouTube Slideshow Creator (http://www.youtube.com/upload)');
     $this->assertEqual($video_one->likes, 1);
     $this->assertEqual($video_one->dislikes, 0);
     $this->assertEqual($video_one->views, 6);
     $this->assertEqual($video_one->post_id, 'H');
     $this->assertEqual($video_one->is_protected, 0);
     $this->assertEqual($video_one->favorites_added, 0);
     $this->assertEqual($video_one->favorites_removed, 0);
     $this->assertEqual($video_one->shares, 0);
     $this->assertEqual($video_one->subscribers_gained, 0);
     $this->assertEqual($video_one->subscribers_lost, 0);
     $this->assertEqual($video_one->minutes_watched, 4);
     $this->assertEqual($video_one->average_view_duration, 52);
     $this->assertEqual($video_one->average_view_percentage, 24.8284);
     $this->assertEqual($video_one->author_user_id, '113612142759476883204');
     $this->assertEqual($video_one->author_username, 'Gina Trapani');
     $this->assertEqual($video_one->author_fullname, 'Gina Trapani');
     $this->assertEqual($video_one->author_avatar, 'http://www.myavatar.com');
     $this->assertEqual($video_one->source, '');
     $this->assertEqual($video_one->network, 'youtube');
     // Check the all time counts were added correctly
     $favs_added_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'favorites_added_all_time');
     $favs_removed_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'favorites_removed_all_time');
     $shares_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'shares_all_time');
     $subs_gained_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'subscribers_gained_all_time');
     $subs_lost_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'subscribers_lost_all_time');
     $mins_watched_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'minutes_watched_all_time');
     $avg_view_percent_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'average_view_percentage_all_time');
     $avg_view_dur_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'average_view_duration_all_time');
     $views_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'views_all_time');
     $likes_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'likes_all_time');
     $dislikes_all_time = $count_history_dao->getLatestCountByPostIDAndType('H', 'dislikes_all_time');
     $this->assertEqual($favs_added_all_time['count'], 0);
     $this->assertEqual($favs_removed_all_time['count'], 0);
     $this->assertEqual($shares_all_time['count'], 0);
     $this->assertEqual($subs_gained_all_time['count'], 0);
     $this->assertEqual($subs_lost_all_time['count'], 0);
     $this->assertEqual($mins_watched_all_time['count'], 4);
     $this->assertEqual($avg_view_percent_all_time['count'], 25);
     $this->assertEqual($avg_view_dur_all_time['count'], 52);
     $this->assertEqual($views_all_time['count'], 6);
     $this->assertEqual($likes_all_time['count'], 1);
     $this->assertEqual($dislikes_all_time['count'], 0);
     // Check the replies to it got added
     // Basic 1st reply
     $reply_one = $post_dao->getPost('jm_SGXNfF6AmF20tsHqF_2h_S_fV_0l2DU3AfqjbsNc', 'youtube');
     $this->assertEqual($reply_one->post_id, 'jm_SGXNfF6AmF20tsHqF_2h_S_fV_0l2DU3AfqjbsNc');
     $this->assertEqual($reply_one->post_text, 'Test comment');
     $this->assertEqual($reply_one->author_username, 'Aaron Kalair');
     $this->assertEqual($reply_one->author_fullname, 'Aaron Kalair');
     $this->assertEqual($reply_one->author_avatar, 'https://lh5.googleusercontent.com/-Z2vFxu2wO6E/AAAAAAAAAAI/AAAAAAAAANQ/Pp0EB7dNKLY/photo.jpg?sz=50');
     $this->assertEqual($reply_one->author_user_id, '115383827382290096528');
     $this->assertEqual($reply_one->pub_date, '2013-06-05 08:13:43');
     $this->assertEqual($reply_one->source, '');
     $this->assertEqual($reply_one->is_protected, 0);
     $this->assertEqual($reply_one->network, 'youtube');
     $this->assertEqual($reply_one->in_reply_to_user_id, '113612142759476883204');
     $this->assertEqual($reply_one->in_reply_to_post_id, 'H');
     // Check we can itterate over replies in a single page
     $reply_two = $post_dao->getPost('gm_SGXNffMJT58F20tsHqF_2h_S_fV_0l2DU3AfqjbsNc', 'youtube');
     $this->assertEqual($reply_two->post_id, 'gm_SGXNffMJT58F20tsHqF_2h_S_fV_0l2DU3AfqjbsNc');
     $this->assertEqual($reply_two->post_text, 'yet another comment');
     $this->assertEqual($reply_two->author_username, 'Aaron Kalair');
     $this->assertEqual($reply_two->author_fullname, 'Aaron Kalair');
     $this->assertEqual($reply_two->author_avatar, 'https://lh5.googleusercontent.com/-Z2vFxu2wO6E/AAAAAAAAAAI/AAAAAAAAANQ/Pp0EB7dNKLY/photo.jpg?sz=50');
     $this->assertEqual($reply_two->author_user_id, '115383827382290096528');
     $this->assertEqual($reply_two->pub_date, '2013-06-15 07:45:11');
     $this->assertEqual($reply_two->source, '');
     $this->assertEqual($reply_two->is_protected, 0);
     $this->assertEqual($reply_two->network, 'youtube');
     $this->assertEqual($reply_two->in_reply_to_user_id, '113612142759476883204');
     $this->assertEqual($reply_two->in_reply_to_post_id, 'H');
     // Check we can get a reply from another page
     $reply_three = $post_dao->getPost('hg_HF75HJSNY38JH_ht5_fh', 'youtube');
     $this->assertEqual($reply_three->post_id, 'hg_HF75HJSNY38JH_ht5_fh');
     $this->assertEqual($reply_three->post_text, 'A comment on the second page');
     $this->assertEqual($reply_three->author_username, 'Aaron Kalair');
     $this->assertEqual($reply_three->author_fullname, 'Aaron Kalair');
     $this->assertEqual($reply_three->author_avatar, 'https://lh5.googleusercontent.com/-Z2vFxu2wO6E/AAAAAAAAAAI/AAAAAAAAANQ/Pp0EB7dNKLY/photo.jpg?sz=50');
     $this->assertEqual($reply_three->author_user_id, '115383827382290096528');
     $this->assertEqual($reply_three->pub_date, '2013-06-10 18:14:33');
     $this->assertEqual($reply_three->source, '');
     $this->assertEqual($reply_three->is_protected, 0);
     $this->assertEqual($reply_three->network, 'youtube');
     $this->assertEqual($reply_three->in_reply_to_user_id, '113612142759476883204');
     $this->assertEqual($reply_three->in_reply_to_post_id, 'H');
     // Check we can itterate over videos on the same page of replies
     $video_two = $video_dao->getVideoByID('a', 'youtube');
     $this->assertEqual($video_two->post_text, 'Same Page Video');
     $this->assertEqual($video_two->description, 'This video is on the same page');
     $this->assertEqual($video_two->likes, 10);
     $this->assertEqual($video_two->dislikes, 110);
     $this->assertEqual($video_two->views, 50);
     $this->assertEqual($video_two->post_id, 'a');
     $this->assertEqual($video_two->is_protected, 0);
     $this->assertEqual($video_two->favorites_added, 5);
     $this->assertEqual($video_two->favorites_removed, 1);
     $this->assertEqual($video_two->shares, 0);
     $this->assertEqual($video_two->subscribers_gained, 0);
     $this->assertEqual($video_two->subscribers_lost, 0);
     $this->assertEqual($video_two->minutes_watched, 1);
     $this->assertEqual($video_two->average_view_duration, 2);
     $this->assertEqual($video_two->average_view_percentage, 24.8284);
     $this->assertEqual($video_two->author_user_id, '113612142759476883204');
     $this->assertEqual($video_two->author_username, 'Gina Trapani');
     $this->assertEqual($video_two->author_fullname, 'Gina Trapani');
     $this->assertEqual($video_two->author_avatar, 'http://www.myavatar.com');
     $this->assertEqual($video_two->source, '');
     $this->assertEqual($video_two->network, 'youtube');
     // Check the per day counts got added correctly
     $favs_added = $count_history_dao->getLatestCountByPostIDAndType('a', 'favorites_added');
     $favs_removed = $count_history_dao->getLatestCountByPostIDAndType('a', 'favorites_removed');
     $shares = $count_history_dao->getLatestCountByPostIDAndType('a', 'shares');
     $subs_gained = $count_history_dao->getLatestCountByPostIDAndType('a', 'subscribers_gained');
     $subs_lost = $count_history_dao->getLatestCountByPostIDAndType('a', 'subscribers_lost');
     $mins_watched = $count_history_dao->getLatestCountByPostIDAndType('a', 'minutes_watched');
     $avg_view_percent = $count_history_dao->getLatestCountByPostIDAndType('a', 'average_view_percentage');
     $avg_view_dur = $count_history_dao->getLatestCountByPostIDAndType('a', 'average_view_duration');
     $views = $count_history_dao->getLatestCountByPostIDAndType('a', 'views');
     $likes = $count_history_dao->getLatestCountByPostIDAndType('a', 'likes');
     $dislikes = $count_history_dao->getLatestCountByPostIDAndType('a', 'dislikes');
     $this->assertEqual($favs_added['count'], 4);
     $this->assertEqual($favs_removed['count'], 2);
     $this->assertEqual($shares['count'], 3);
     $this->assertEqual($subs_gained['count'], 10);
     $this->assertEqual($subs_lost['count'], 11);
     $this->assertEqual($mins_watched['count'], 11);
     $this->assertEqual($avg_view_percent['count'], 14);
     $this->assertEqual($avg_view_dur['count'], 15);
     $this->assertEqual($views['count'], 100);
     $this->assertEqual($likes['count'], 0);
     $this->assertEqual($dislikes['count'], 0);
     // Check the all time counts were added correctly
     $favs_added_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'favorites_added_all_time');
     $favs_removed_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'favorites_removed_all_time');
     $shares_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'shares_all_time');
     $subs_gained_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'subscribers_gained_all_time');
     $subs_lost_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'subscribers_lost_all_time');
     $mins_watched_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'minutes_watched_all_time');
     $avg_view_percent_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'average_view_percentage_all_time');
     $avg_view_dur_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'average_view_duration_all_time');
     $views_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'views_all_time');
     $likes_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'likes_all_time');
     $dislikes_all_time = $count_history_dao->getLatestCountByPostIDAndType('a', 'dislikes_all_time');
     $this->assertEqual($favs_added_all_time['count'], 5);
     $this->assertEqual($favs_removed_all_time['count'], 1);
     $this->assertEqual($shares_all_time['count'], 0);
     $this->assertEqual($subs_gained_all_time['count'], 0);
     $this->assertEqual($subs_lost_all_time['count'], 0);
     $this->assertEqual($mins_watched_all_time['count'], 1);
     $this->assertEqual($avg_view_percent_all_time['count'], 25);
     $this->assertEqual($avg_view_dur_all_time['count'], 2);
     $this->assertEqual($views_all_time['count'], 50);
     $this->assertEqual($likes_all_time['count'], 10);
     $this->assertEqual($dislikes_all_time['count'], 110);
     // Check we can get a video from the next page of videos
     $video_three = $video_dao->getVideoByID('g', 'youtube');
     $this->assertEqual($video_three->post_text, 'My Slideshow');
     $this->assertEqual($video_three->description, 'I created this video with the YouTube Slideshow Creator (http://www.youtube.com/upload)');
     $this->assertEqual($video_three->likes, 0);
     $this->assertEqual($video_three->dislikes, 0);
     $this->assertEqual($video_three->views, 5);
     $this->assertEqual($video_three->post_id, 'g');
     $this->assertEqual($video_three->is_protected, 0);
     $this->assertEqual($video_three->favorites_added, 0);
     $this->assertEqual($video_three->favorites_removed, 0);
     $this->assertEqual($video_three->shares, 0);
     $this->assertEqual($video_three->subscribers_gained, 0);
     $this->assertEqual($video_three->subscribers_lost, 0);
     $this->assertEqual($video_three->minutes_watched, 0);
     $this->assertEqual($video_three->average_view_duration, 15);
     $this->assertEqual($video_three->average_view_percentage, 42.7689);
     $this->assertEqual($video_three->author_user_id, '113612142759476883204');
     $this->assertEqual($video_three->author_username, 'Gina Trapani');
     $this->assertEqual($video_three->author_fullname, 'Gina Trapani');
     $this->assertEqual($video_three->author_avatar, 'http://www.myavatar.com');
     $this->assertEqual($video_three->source, '');
     $this->assertEqual($video_three->network, 'youtube');
     // Check the all time counts were added correctly
     $favs_added_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'favorites_added_all_time');
     $favs_removed_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'favorites_removed_all_time');
     $shares_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'shares_all_time');
     $subs_gained_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'subscribers_gained_all_time');
     $subs_lost_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'subscribers_lost_all_time');
     $mins_watched_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'minutes_watched_all_time');
     $avg_view_percent_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'average_view_percentage_all_time');
     $avg_view_dur_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'average_view_duration_all_time');
     $views_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'views_all_time');
     $likes_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'likes_all_time');
     $dislikes_all_time = $count_history_dao->getLatestCountByPostIDAndType('g', 'dislikes_all_time');
     $this->assertEqual($favs_added_all_time['count'], 0);
     $this->assertEqual($favs_removed_all_time['count'], 0);
     $this->assertEqual($shares_all_time['count'], 0);
     $this->assertEqual($subs_gained_all_time['count'], 0);
     $this->assertEqual($subs_lost_all_time['count'], 0);
     $this->assertEqual($mins_watched_all_time['count'], 0);
     $this->assertEqual($avg_view_percent_all_time['count'], 43);
     $this->assertEqual($avg_view_dur_all_time['count'], 15);
     $this->assertEqual($views_all_time['count'], 5);
     $this->assertEqual($likes_all_time['count'], 0);
     $this->assertEqual($dislikes_all_time['count'], 0);
 }
Example #18
0
 public function testFetchInstanceUserPosts()
 {
     $builders = self::buildData();
     $gpc = new GooglePlusCrawler($this->profile1_instance, 'fauxaccesstoken', 10);
     $gpc->fetchInstanceUserPosts();
     $post_dao = new PostMySQLDAO();
     $post = $post_dao->getPost('z12is5v4snurihgdl22iiz3pjrnws3lle', 'google+', true);
     $this->assertIsA($post, 'Post');
     $this->assertEqual($post->post_text, 'I&#39;ve got a date with the G+ API this weekend to make a ThinkUp plugin!');
     $this->assertEqual($post->reply_count_cache, 24);
     $this->assertEqual($post->favlike_count_cache, 159);
     $this->assertEqual($post->retweet_count_cache, 29);
     $this->assertIsA($post->links[0], 'Link');
     $this->assertEqual($post->links[0]->url, 'http://googleplusplatform.blogspot.com/2011/09/getting-started-on-google-api.html');
     $this->assertEqual($post->links[0]->title, 'Getting Started on the Google+ API - Google+ Platform Blog');
     $this->assertEqual($post->links[0]->description, 'Official source of information about the Google+ platform');
     $this->assertEqual($post->links[0]->image_src, '');
     //test reshare with annotation
     $post = $post_dao->getPost('z12pcfdr2wvyzjfff22iiz3pjrnws3lle', 'google+', true);
     $this->assertIsA($post, 'Post');
     $this->assertEqual($post->post_text, 'Really fun episode this week.');
     //test reshare without annotation
     $post = $post_dao->getPost('z12pxlfjxpujivy3e230t3aqawfoz1qf1', 'google+', true);
     $this->assertIsA($post, 'Post');
     $this->assertEqual($post->post_text, '');
     //now crawl on updated data and assert counts and post text get updated in database
     $gpc->api_accessor->setDataLocation('new_counts/');
     $gpc->fetchInstanceUserPosts();
     $post = $post_dao->getPost('z12is5v4snurihgdl22iiz3pjrnws3lle', 'google+', true);
     $this->assertEqual($post->reply_count_cache, 64);
     $this->assertEqual($post->favlike_count_cache, 199);
     $this->assertEqual($post->retweet_count_cache, 69);
     $this->assertEqual($post->post_text, "I&#39;ve got a date with the G+ API this weekend to make a ThinkUp plugin! Updated: New text here!");
 }
Example #19
0
 public function testGetOnThisDayFlashbackPosts()
 {
     // Generate the date string for 1 year ago today
     $year_ago_date = date(date('Y-m-d H:i:s', strtotime("today -1 year")));
     // Add a post from a year ago that's not a reply or retweet
     $post_builder = FixtureBuilder::build('posts', array('post_id' => '148', 'author_user_id' => '20', 'author_username' => 'user1', 'author_fullname' => 'User 1', 'network' => 'foursquare', 'post_text' => 'I just checked in', 'source' => '', 'pub_date' => $year_ago_date, 'location' => 'England', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place' => 'The Park', 'place_id' => '12345a', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'foursquare', 'in_reply_to_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'geo' => '52.477192843264,-1.484333726346'));
     $post_key = $post_builder->columns['last_insert_id'];
     // Add a link for this post
     $link_builder = FixtureBuilder::build('links', array('post_key' => $post_key, 'url' => 'http://bit.ly/blah'));
     // Add a post from 2 years ago that's not a reply or retweet
     $two_years_ago_date = date(date('Y-m-d H:i:s', strtotime("today -2 year")));
     $post_builder2 = FixtureBuilder::build('posts', array('post_id' => '149', 'author_user_id' => '20', 'author_username' => 'user1', 'author_fullname' => 'User 1', 'network' => 'foursquare', 'post_text' => 'I just checked in', 'source' => '', 'pub_date' => $two_years_ago_date, 'location' => 'England', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place' => 'The Park', 'place_id' => '12345a', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'foursquare', 'in_reply_to_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'geo' => '52.477192843264,-1.484333726346'));
     $post_key = $post_builder2->columns['last_insert_id'];
     // Add a link for this post
     $link_builder2 = FixtureBuilder::build('links', array('post_key' => $post_key, 'url' => 'http://bit.ly/blahb'));
     // Add a post from today that's not a reply or retweet
     $today_date = date(date('Y-m-d H:i:s', strtotime("today")));
     $post_builder3 = FixtureBuilder::build('posts', array('post_id' => '150', 'author_user_id' => '20', 'author_username' => 'user1', 'author_fullname' => 'User 1', 'network' => 'foursquare', 'post_text' => 'I just checked in', 'source' => '', 'pub_date' => $today_date, 'location' => 'England', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'place' => 'The Park', 'place_id' => '12345a', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'foursquare', 'in_reply_to_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'geo' => '52.477192843264,-1.484333726346'));
     $post_key = $post_builder3->columns['last_insert_id'];
     // Add a link for this post
     $link_builder3 = FixtureBuilder::build('links', array('post_key' => $post_key, 'url' => 'http://bit.ly/blahb'));
     /* Add the place information for future foursquare checkin test (We do it this way due to the fixture builder
              not being able to handle the MySQL point type
              // Set all possible fields
              $place['id'] = '12345a';
              $place['place_type'] = "Park";
              $place['name'] = "A Park";
              $place['full_name'] = "The Greatest Park";
              $place['country_code'] = "UK";
              $place['country'] = "United Kingdom";
              $place['icon'] = "http://www.iconlocation.com";
              $place['lat_lng'] = 'POINT(51.514 -0.1167)';
              //        $place['bounding_box'] = 'POLYGON((-0.213503 51.512805,-0.105303 51.512805,-0.105303 51.572068,'.
              //         '-0.213503 51.572068, -0.213503 51.512805)))';
              $place['bounding_box'] = array (
              'type' => 'Polygon',
              'coordinates' => array  (
              array(
              array(-97.73818308, 30.29930703),
              array(-97.710741, 30.29930703),
              array(-97.710741, 30.31480602),
              array(-97.73818308, 30.31480602),
              )
              )
              );
     
              $place['map_image'] = "http://www.mapimage.com";
     
              // Insert the place
              $place_dao = new PlaceMySQLDAO();
              $place_dao->insertPlace($place, '148', 'foursquare');
              */
     //sleep(1000);
     // Query the database for last year's post
     $post_dao = new PostMySQLDAO();
     // Get the year to query for
     $res = $post_dao->getOnThisDayFlashbackPosts(20, 'foursquare');
     $this->debug(Utils::varDumpToString($res));
     // Check only the 1 checkin we inserted is returned
     $this->assertEqual(sizeof($res), 2);
     // Check the author user id was set correctly
     $this->assertEqual($res[0]->author_user_id, '20');
     // Check the username was set correctly
     $this->assertEqual($res[0]->author_username, 'user1');
     // Check the author fullname was set correctly
     $this->assertEqual($res[0]->author_fullname, 'User 1');
     // Check the network was set correctly
     $this->assertEqual($res[0]->network, 'foursquare');
     // Check the post text was set correctly
     $this->assertEqual($res[0]->post_text, 'I just checked in');
     // Check the pub date was set correctly
     $this->assertEqual($res[0]->pub_date, $two_years_ago_date);
     // Check the location was set correctly
     $this->assertEqual($res[0]->location, 'England');
     // Check the place was set correctly
     $this->assertEqual($res[0]->place, 'The Park');
     // Check the place id was set correctly
     $this->assertEqual($res[0]->place_id, '12345a');
     // Check the geo co ordinates were set correctly
     $this->assertEqual($res[0]->geo, '52.477192843264,-1.484333726346');
     /*
     // Check the place id was set correctly
     $this->assertEqual($res[0]->place_obj->place_id, '12345a');
     // Check the place type was set correctly
     $this->assertEqual($res[0]->place_obj->place_type, 'Park');
     // Check the place name was set correctly
     $this->assertEqual($res[0]->place_obj->name, 'A Park');
     // Check the full name was set correctly
     $this->assertEqual($res[0]->place_obj->full_name, 'The Greatest Park');
     // Check the country code was set correctly
     $this->assertEqual($res[0]->place_obj->country_code, 'UK');
     // Check the country was set correctly
     $this->assertEqual($res[0]->place_obj->country, 'United Kingdom');
     // Check the icon was set correctly
     $this->assertEqual($res[0]->place_obj->icon, 'http://www.iconlocation.com');
     // Check the map image was set correctly
     $this->assertEqual($res[0]->place_obj->map_image, 'http://www.mapimage.com');
     */
     // Check the link URL was set correctly
     $this->assertEqual($res[0]->links[0]->url, 'http://bit.ly/blahb');
 }
Example #20
0
 /**
  * Test getMostRepliedToPostsByPublicInstancesInLastWeek
  */
 function testGetMostRepliedToPostsByPublicInstancesInLastWeek()
 {
     //Add posts with retweets by user3, who is on the public timeline with retweet counts in the last 9 days
     $counter = 0;
     $id = 200;
     while ($counter < 40) {
         $id += $counter;
         $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES ({$id}, 23, 'user3', 'User 3', 'avatar.jpg', 'This is post with {$counter} replies', 'web', DATE_SUB(NOW(), INTERVAL " . $counter . " DAY), " . $counter . ", 0 );";
         //echo $q;
         PDODAO::$PDO->exec($q);
         $counter++;
     }
     $pdao = new PostMySQLDAO();
     $page1ofposts = $pdao->getMostRepliedToPostsByPublicInstancesInLastWeek(1, 5);
     $this->assertEqual(sizeof($page1ofposts), 5);
     $this->assertEqual($page1ofposts[0]->mention_count_cache, 7);
     $this->assertEqual($page1ofposts[1]->mention_count_cache, 6);
     $page2ofposts = $pdao->getMostRepliedToPostsByPublicInstancesInLastWeek(2, 5);
     $this->assertEqual(sizeof($page2ofposts), 2);
     $this->assertEqual($page2ofposts[0]->mention_count_cache, 2);
     $this->assertEqual($page2ofposts[1]->mention_count_cache, 1);
     $totals = $pdao->getTotalPagesAndPostsByPublicInstances(5, 7);
     $this->assertEqual($totals["total_posts"], 7);
     $this->assertEqual($totals["total_pages"], 2);
 }
 public function testAgeAnalysisForFacebookSeniors()
 {
     // Get data ready that insight requires
     $builders = self::buildDataSeniors();
     $instance = new Instance();
     $instance->id = 100;
     $instance->network_user_id = 1;
     $instance->network_username = '******';
     $instance->network = 'facebook';
     $post_dao = new PostMySQLDAO();
     $last_week_of_posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $network = $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = $number_days, $iterator = false, $is_public = false);
     $insight_plugin = new AgeAnalysisInsight();
     $insight_plugin->generateInsight($instance, null, $last_week_of_posts, 1);
     // Assert that insight got inserted
     $insight_dao = new InsightMySQLDAO();
     $today = date('Y-m-d');
     $result = $insight_dao->getInsight('age_analysis', 100, $today);
     $related_data = unserialize($result->related_data);
     $this->assertNotNull($result);
     $this->assertIsA($result, "Insight");
     $this->assertEqual($result->headline, 'Old Man resonated with Baby Boomers');
     $this->assertEqual($result->text, "Baby Boomers — people 45+ years old — had the most to say in response " . "to Old Man's posts on Facebook this week.");
     $this->assertEqual($related_data['age_data']['18'], 1);
     $this->assertEqual($related_data['age_data']['18_25'], 0);
     $this->assertEqual($related_data['age_data']['25_35'], 0);
     $this->assertEqual($related_data['age_data']['35_45'], 0);
     $this->assertEqual($related_data['age_data']['45'], 2);
     $result->id = 5;
     $this->debug($this->getRenderedInsightInHTML($result));
     $this->debug($this->getRenderedInsightInEmail($result));
 }
 public function testExportRepliesToRetweetsOfServiceUser()
 {
     $post_dao = new PostMySQLDAO();
     $posts_to_process = $post_dao->getAllPosts(13, 'twitter', 500, 1);
     $replies_rts_exported = $this->dao->exportRepliesRetweetsOfPosts($posts_to_process);
     //2 replies and 1 retweet
     $this->assertEqual($replies_rts_exported, 3);
 }
Example #23
0
 public function testPaginatedPostLikes()
 {
     $fbc = new FacebookCrawler($this->profile5_instance, 'fauxaccesstoken', 10);
     $fbc->fetchPostsAndReplies('501771984', 'facebook');
     $post_dao = new PostMySQLDAO();
     $post = $post_dao->getPost('10151734003261985', 'facebook');
     $this->assertEqual($post->favlike_count_cache, 27);
 }
Example #24
0
 public function testFetchInstanceUserCheckinsFullArchive()
 {
     $builders = self::buildData();
     // Tell ThinkUp we haven't loaded old posts yet
     $this->profile1_instance->is_archive_loaded_posts = false;
     // Create a new foursquare crawler for this instance with a valid access token
     $fsc = new FoursquareCrawler($this->profile1_instance, 'secret', 10);
     // Make a request for this users checkins
     $fsc->fetchInstanceUserCheckins();
     // Get a new post dao
     $post_dao = new PostMySQLDAO();
     // Get a new place DAO
     $place_dao = new PlaceMySQLDAO();
     // Get a new link DAO
     $link_dao = new LinkMySQLDAO();
     // Get the first checkin from the database that the fetchInstanceUserCheckins method should have saved
     $post = $post_dao->getPost('4efa01068b81ef98d2e9cd0b', 'foursquare', true);
     // Get the first place information from the database that fetchInstanceUserCheckins method should have saved
     $place = $place_dao->getPlaceByID('4e22eac31838712abe8186e3');
     // Check the post was actually set
     $this->assertIsA($post, 'Post');
     // Check these values were set as blank, as they can't be null but we dont use them
     $this->assertEqual($post->reply_count_cache, 1);
     $this->assertEqual($post->favlike_count_cache, 0);
     $this->assertEqual($post->retweet_count_cache, 0);
     $this->assertEqual($post->author_follower_count, 0);
     // Check the source was set
     $this->assertEqual($post->source, 'foursquare for iPhone');
     // Check the username was set
     $this->assertEqual($post->author_username, '*****@*****.**');
     // Check the fullname was set
     $this->assertEqual($post->author_fullname, 'Bob Cats');
     // Check the avatar was set
     $this->assertEqual($post->author_avatar, 'https://foursquare.com/img/100x100/blank_boy.png');
     // Check the author used id was set
     $this->assertEqual($post->author_user_id, '113612142759476883204');
     // Check the publication date was set
     //$this->assertEqual($post->pub_date, '2011-12-27 17:31:50');
     $this->assertEqual($post->pub_date, date('Y-m-d H:i:s', '1325007110'));
     // Check the checkin was set as public
     $this->assertFalse($post->is_protected);
     // Check the place name was set
     $this->assertEqual($post->place, 'Bedworth Sloughs');
     // Check the location was set
     $this->assertEqual($post->location, 'Bedworth, CV12 0AS');
     // Check the place ID was set
     $this->assertEqual($post->place_id, '4e22eac31838712abe8186e3');
     // Check the geo co ordinates were set
     //$this->assertEqual($post->geo, '52.477241961421,-1.4845029364055');
     $this->assertPattern('/52.4772419614/', $post->geo);
     $this->assertPattern('/-1.4845029364/', $post->geo);
     // Now check the details about the place were stored in the places table
     // Check all the fields were returned
     $this->assertEqual(sizeof($place), 12);
     // Check the place type was set
     $this->assertEqual($place['place_type'], 'Field');
     // Check the place name was set
     $this->assertEqual($place['name'], 'Bedworth Sloughs');
     // Check the fullname was set
     $this->assertEqual($place['full_name'], 'Bedworth Sloughs');
     // Check the network was set
     $this->assertEqual($place['network'], 'foursquare');
     // Build the map url to check against like this to meet code style guidelines
     $map_url = "http://maps.googleapis.com/maps/api/staticmap?size=150x150&zoom=15&maptype=roadmap&markers";
     $map_url .= "=color:blue%7C" . $post->geo . "&sensor=false";
     // Check the map image was set
     $this->assertEqual($place['map_image'], $map_url);
     // Check the lat long co ordinates were set
     $this->assertPattern('/POINT\\(52.4772419614/', $place['longlat']);
     $this->assertPattern('/ -1.4845029364/', $place['longlat']);
     // Check the comment for this post was set
     // Get the comment from the database
     $comment = $post_dao->getPost('4f4135f9e4b028f640ef42eb', 'foursquare', true);
     // Check the post was actually set
     $this->assertIsA($comment, 'Post');
     // Check these values were set as blank, as they can't be null but we dont use them
     $this->assertEqual($comment->reply_count_cache, 0);
     $this->assertEqual($comment->favlike_count_cache, 0);
     $this->assertEqual($comment->retweet_count_cache, 0);
     $this->assertEqual($comment->author_follower_count, 0);
     $this->assertEqual($comment->source, '');
     // Check the username was set
     $this->assertEqual($comment->author_username, '*****@*****.**');
     // Check the fullname was set
     $this->assertEqual($comment->author_fullname, 'Bob Cats');
     // Check the avatar was set
     $this->assertEqual($comment->author_avatar, 'https://foursquare.com/img/100x100/blank_boy.png');
     // Check the author used id was set
     $this->assertEqual($comment->author_user_id, '113612142759476883204');
     // Check the publication date was set
     //$this->assertEqual($comment->pub_date, '2012-02-19 17:48:41');
     $this->assertEqual($comment->pub_date, date('Y-m-d H:i:s', '1329673721'));
     // Check the checkin was set as public
     $this->assertFalse($comment->is_protected);
     // Check the place name was set
     $this->assertEqual($comment->place, 'Bedworth Sloughs');
     // Check the location was set
     $this->assertEqual($comment->location, 'Bedworth, CV12 0AS');
     // Check the place ID was set
     $this->assertEqual($comment->place_id, '4e22eac31838712abe8186e3');
     // Check the geo co ordinates were set
     //$this->assertEqual($comment->geo, '52.477241961421,-1.4845029364055');
     $this->assertPattern('/52.4772419614/', $comment->geo);
     $this->assertPattern('/-1.484502936/', $comment->geo);
     // Check the link for this checkin was set
     // Link string
     $link_string = 'https://img-s.foursquare.com/pix/noTc5a0afTgqTuLlsi3a33tLR0iUOZaa2hLm7LsNn1Q.jpg';
     $link = $link_dao->getLinkByUrl($link_string);
     // Check the expanded url was set correctly
     // Expanded URL string
     $expanded_url = 'https://img-s.foursquare.com/pix/noTc5a0afTgqTuLlsi3a33tLR0iUOZaa2hLm7LsNn1Q.jpg';
     $this->assertEqual($link->expanded_url, $expanded_url);
     // Check the title was set
     $this->assertEqual($link->title, ' ');
     // Check the description was set
     $this->assertEqual($link->description, ' ');
     // Check the img_src was set
     // img_src string
     $img_src = 'https://img-s.foursquare.com/pix/noTc5a0afTgqTuLlsi3a33tLR0iUOZaa2hLm7LsNn1Q.jpg';
     $this->assertEqual($link->image_src, $img_src);
     // Check the caption was set
     $this->assertEqual($link->caption, ' ');
     // Check the post key is correct
     $this->assertEqual($link->post_key, 1);
     // Check the checkin from the second page of results was inserted correctly
     // Get the first checkin from the database that the fetchInstanceUserCheckins method should have saved
     $post = $post_dao->getPost('4efa01068b81ef98d679cd0b', 'foursquare', true);
     // Get the first place information from the database that fetchInstanceUserCheckins method should have saved
     $place = $place_dao->getPlaceByID('4e22eac31838712aui8186e3');
     // Check the post was actually set
     $this->assertIsA($post, 'Post');
     // Check these values were set as blank, as they can't be null but we dont use them
     $this->assertEqual($post->reply_count_cache, 0);
     $this->assertEqual($post->favlike_count_cache, 0);
     $this->assertEqual($post->retweet_count_cache, 0);
     $this->assertEqual($post->author_follower_count, 0);
     // Check the source was set
     $this->assertEqual($post->source, 'foursquare for iPhone');
     // Check the username was set
     $this->assertEqual($post->author_username, '*****@*****.**');
     // Check the fullname was set
     $this->assertEqual($post->author_fullname, 'Bob Cats');
     // Check the avatar was set
     $this->assertEqual($post->author_avatar, 'https://foursquare.com/img/100x100/blank_boy.png');
     // Check the author used id was set
     $this->assertEqual($post->author_user_id, '113612142759476883204');
     // Check the publication date was set
     //$this->assertEqual($post->pub_date, '2011-12-27 17:31:59');
     $this->assertEqual($post->pub_date, date('Y-m-d H:i:s', '1325007119'));
     // Check the checkin was set as public
     $this->assertFalse($post->is_protected);
     // Check the place name was set
     $this->assertEqual($post->place, 'Empire State Building');
     // Check the location was set
     $this->assertEqual($post->location, 'New York');
     // Check the place ID was set
     $this->assertEqual($post->place_id, '4e22eac31838712aui8186e3');
     // Check the geo co ordinates were set
     //$this->assertEqual($post->geo, '82.476241961421,-6.4845029364055');
     $this->assertPattern('/82.4762419614/', $post->geo);
     $this->assertPattern('/-6.4845029364/', $post->geo);
     // Now check the details about the place were stored in the places table
     // Check all the fields were returned
     $this->assertEqual(sizeof($place), 12);
     // Check the place type was set
     $this->assertEqual($place['place_type'], 'Building');
     // Check the place name was set
     $this->assertEqual($place['name'], 'Empire State Building');
     // Check the fullname was set
     $this->assertEqual($place['full_name'], 'Empire State Building');
     // Check the network was set
     $this->assertEqual($place['network'], 'foursquare');
     // Check we set the old posts loaded bit
     $this->assertTrue($this->profile1_instance->is_archive_loaded_posts);
 }
Example #25
0
 public function testPostReplyPaging()
 {
     $fbc = new FacebookCrawler($this->instance, 'fauxaccesstoken');
     $fbc->fetchPostsAndReplies('133954286636768', true);
     $post_dao = new PostMySQLDAO();
     $post = $post_dao->getPost('144568048938151', 'facebook page');
     $this->assertEqual($post->reply_count_cache, 70);
 }
 public function testAddAndDeleteHashtagSearch()
 {
     $this->debug(__METHOD__);
     //Hashtag does not exist
     $hashtag_dao = new HashtagMySQLDAO();
     $instance_hashtag_dao = new InstanceHashtagMySQLDAO();
     $hashtag = $hashtag_dao->getHashtag($_POST['new_hashtag_name'], 'twitter');
     $this->assertNull($hashtag);
     $instance_hashtag = $instance_hashtag_dao->getByInstance(1);
     $this->assertEqual(sizeof($instance_hashtag), 0);
     //Add hashtag
     $this->simulateLogin('*****@*****.**', true, true);
     $_POST['action'] = 'Save search';
     $_POST['new_hashtag_name'] = '#Messi';
     $_POST['instance_id'] = 1;
     $_POST['csrf_token'] = parent::CSRF_TOKEN;
     $controller = new AccountConfigurationController(true);
     $results = $controller->go();
     $this->debug($results);
     $hashtag = $hashtag_dao->getHashtag($_POST['new_hashtag_name'], 'twitter');
     $this->assertNotNull($hashtag);
     $this->assertEqual($hashtag->id, 1);
     $this->assertEqual($hashtag->hashtag, $_POST['new_hashtag_name']);
     $this->assertEqual($hashtag->network, 'twitter');
     $this->assertEqual($hashtag->count_cache, 0);
     $instance_hashtag = $instance_hashtag_dao->getByInstance(1);
     $this->assertNotNull($instance_hashtag);
     $this->assertEqual(sizeof($instance_hashtag), 1);
     $this->assertEqual($instance_hashtag[0]->instance_id, 1);
     $this->assertEqual($instance_hashtag[0]->hashtag_id, 1);
     $this->assertEqual($instance_hashtag[0]->last_post_id, 0);
     $this->assertEqual($instance_hashtag[0]->earliest_post_id, 0);
     $v_mgr = $controller->getViewManager();
     $success_msgs = $v_mgr->getTemplateDataItem('success_msgs');
     $this->assertNotNull($success_msgs);
     $this->assertEqual($success_msgs['account'], 'Saved search for #Messi.');
     $this->assertNull($v_mgr->getTemplateDataItem('error_msg'));
     //Search tweets
     //Saved search tweets do not exist
     $posts_dao = new PostMySQLDAO();
     $links_dao = new LinkMySQLDAO();
     $users_dao = new UserMySQLDAO();
     $hashtagpost_dao = new HashtagPostMySQLDAO();
     $hashtags_posts = $hashtagpost_dao->getHashtagsForPost(1, 'twitter');
     $this->assertEqual(sizeof($hashtags_posts), 0);
     $posts = $posts_dao->getAllPostsByHashtagId(1, 'twitter', 20);
     $this->assertEqual(sizeof($posts), 0);
     $posts = $posts_dao->getAllPostsByUsername('vetcastellnou', 'twitter');
     $this->assertEqual(sizeof($posts), 0);
     $links = $links_dao->getLinksForPost(1);
     $this->assertEqual(sizeof($links), 0);
     $this->assertFalse($users_dao->isUserInDB(100, 'twitter'));
     $this->assertFalse($users_dao->isUserInDB(101, 'twitter'));
     $builder = $this->buildSearchData();
     //Saved search tweets do exist
     $hashtags_posts = $hashtagpost_dao->getHashtagsForPost(1, 'twitter');
     $this->assertEqual(sizeof($hashtags_posts), 1);
     $posts = $posts_dao->getAllPostsByHashtagId(1, 'twitter', 20);
     $this->assertEqual(sizeof($posts), 2);
     $posts = $posts_dao->getAllPostsByUsername('vetcastellnou', 'twitter');
     $this->assertEqual(sizeof($posts), 1);
     $links = $links_dao->getLinksForPost(1);
     $this->assertEqual(sizeof($links), 2);
     $this->assertTrue($users_dao->isUserInDB(100, 'twitter'));
     $this->assertTrue($users_dao->isUserInDB(101, 'twitter'));
     //Delete hashtag
     $new_hashtag_name = $_POST['new_hashtag_name'];
     unset($_POST['new_hashtag_name']);
     $_POST['action'] = 'Delete';
     $_POST['instance_id'] = 1;
     $_POST['hashtag_id'] = 1;
     $_POST['csrf_token'] = parent::CSRF_TOKEN;
     $controller = new AccountConfigurationController(true);
     $controller->go();
     $hashtags_posts = $hashtagpost_dao->getHashtagsForPost(1, 'twitter');
     $this->assertEqual(sizeof($hashtags_posts), 0);
     $posts = $posts_dao->getAllPostsByHashtagId(1, 'twitter', 20);
     $this->assertEqual(sizeof($posts), 0);
     $posts = $posts_dao->getAllPostsByUsername('vetcastellnou', 'twitter');
     $this->assertEqual(sizeof($posts), 1);
     $links = $links_dao->getLinksForPost(1);
     //Don't delete links
     $this->assertEqual(sizeof($links), 2);
     //Don't delete users
     $this->assertTrue($users_dao->isUserInDB(100, 'twitter'));
     $this->assertTrue($users_dao->isUserInDB(101, 'twitter'));
     $hashtag = $hashtag_dao->getHashtag($new_hashtag_name);
     $this->assertNull($hashtag);
     $instance_hashtag = $instance_hashtag_dao->getByInstance(1);
     $this->assertEqual(sizeof($instance_hashtag), 0);
     $v_mgr = $controller->getViewManager();
     $success_msgs = $v_mgr->getTemplateDataItem('success_msgs');
     $this->assertNotNull($success_msgs);
     $this->assertEqual($success_msgs['account'], 'Deleted saved search.');
     $this->assertNull($v_mgr->getTemplateDataItem('error_msg'));
 }
 /**
  * This test checks 'old-style' rt handling and mentions
  */
 public function testAddPostOldStyleRTNoPostID()
 {
     list($post, $entities, $user_array) = $this->buildStreamPostArray3();
     $dao = new PostMySQLDAO();
     $user_dao = new UserMySQLDAO();
     $dao->addPostAndAssociatedInfo($post, $entities, $user_array);
     $post = $dao->getPost('39088041628934144', 'twitter');
     $this->assertEqual($post->in_rt_of_user_id, 40025121);
     $user = $user_dao->getDetails(140955302, 'twitter');
     $this->assertEqual($user->username, 'DAaronovitch');
     $m_dao = new MentionMySQLDAO();
     $mention = $m_dao->getMentionInfoUserID(40025121);
     $mp = $m_dao->getMentionsForPost('39088041628934144');
     $this->assertTrue($mention != null);
     $this->assertEqual($mention['user_name'], 'RSAMatthew');
     $this->assertEqual($mention['count_cache'], 1);
     $this->assertEqual($mp[0]['author_user_id'], 140955302);
 }
Example #28
0
    public function testFetchPageStream() {
        $fbc = new FacebookCrawler($this->instance, 'fauxaccesstoken');

        $fbc->fetchPagePostsAndReplies(7568536355);

        $pd = new PostMySQLDAO();
        $post = $pd->getPost('437900891355', 'facebook page');
        $this->assertEqual($post->post_text, 'Top 10 iOS Jailbreak Hacks');
        $this->assertEqual($post->reply_count_cache, 8);

        //assert user network is set to Facebook, not Facebook Page
        $ud = new UserMySQLDAO();
        $user = $ud->getUserByName('Matthew Fleisher', 'facebook');
        $this->assertEqual($user->full_name, 'Matthew Fleisher');
        $this->assertEqual($user->network, 'facebook');

        $user = $ud->getUserByName('Matthew Fleisher', 'facebook page');
        $this->assertEqual($user, null);
    }
 public function testFetchFavoritesOfInstanceuser()
 {
     self::setUpInstanceUserAmygdala();
     $this->api->available_api_calls_for_crawler = 3;
     $this->api->to->setDataPath('webapp/plugins/twitter/tests/testdata/favs_tests/favs_stage1/');
     $twitter_crawler = new TwitterCrawler($this->instance, $this->api);
     $twitter_crawler->fetchInstanceUserInfo();
     $twitter_crawler->fetchInstanceFavorites();
     // Save instance
     $instance_dao = DAOFactory::getDAO('TwitterInstanceDAO');
     if (isset($twitter_crawler->user)) {
         $instance_dao->save($this->instance, $twitter_crawler->user->post_count, $this->logger);
     }
     $this->instance = $instance_dao->getByUsernameOnNetwork("amygdala", "twitter");
     $this->assertEqual($this->instance->owner_favs_in_system, 22);
     $this->assertEqual($this->instance->last_page_fetched_favorites, 4);
     $this->assertEqual($this->instance->favorites_profile, 82);
     $this->logger->logInfo("second round of archiving", __METHOD__ . ',' . __LINE__);
     $this->api->available_api_calls_for_crawler = 10;
     $this->api->to->setDataPath('webapp/plugins/twitter/tests/testdata/favs_tests/favs_stage2/');
     $twitter_crawler = new TwitterCrawler($this->instance, $this->api);
     $twitter_crawler->fetchInstanceUserInfo();
     $twitter_crawler->fetchInstanceFavorites();
     // Save instance
     if (isset($twitter_crawler->user)) {
         $instance_dao->save($this->instance, $twitter_crawler->user->post_count, $this->logger);
     }
     $this->instance = $instance_dao->getByUsernameOnNetwork("amygdala", "twitter");
     $this->assertEqual($this->instance->owner_favs_in_system, 84);
     $this->assertEqual($this->instance->last_page_fetched_favorites, 1);
     $this->logger->logInfo("now in maintenance mode", __METHOD__ . ',' . __LINE__);
     $this->api->available_api_calls_for_crawler = 4;
     $this->api->to->setDataPath('webapp/plugins/twitter/tests/testdata/favs_tests/favs_stage3/');
     $twitter_crawler = new TwitterCrawler($this->instance, $this->api);
     $twitter_crawler->fetchInstanceUserInfo();
     $retval = $twitter_crawler->fetchInstanceFavorites();
     // Save instance
     if (isset($twitter_crawler->user)) {
         $instance_dao->save($this->instance, $twitter_crawler->user->post_count, $this->logger);
     }
     $this->instance = $instance_dao->getByUsernameOnNetwork("amygdala", "twitter");
     $this->assertEqual($this->instance->owner_favs_in_system, 87);
     $this->assertEqual($this->instance->last_page_fetched_favorites, 1);
     $this->assertEqual($retval, true);
     // now test case where there are 'extra' favs being reported by twitter,
     // not findable via the N pages searched back through, with existing pages < N
     // override a cfg value
     $this->logger->logInfo("now in maintenance mode, second pass", __METHOD__ . ',' . __LINE__);
     $this->api->available_api_calls_for_crawler = 10;
     $this->api->to->setDataPath('webapp/plugins/twitter/tests/testdata/favs_tests/favs_stage5/');
     $twitter_crawler = new TwitterCrawler($this->instance, $this->api);
     $twitter_crawler->fetchInstanceUserInfo();
     $retval = $twitter_crawler->fetchInstanceFavorites();
     // Save instance
     if (isset($twitter_crawler->user)) {
         $instance_dao->save($this->instance, $twitter_crawler->user->post_count, $this->logger);
     }
     $this->instance = $instance_dao->getByUsernameOnNetwork("amygdala", "twitter");
     $this->assertEqual($this->instance->owner_favs_in_system, 88);
     $this->assertEqual($this->instance->last_page_fetched_favorites, 1);
     $this->assertEqual($retval, true);
     $builder2 = null;
     //Assert links got saved
     $post_dao = new PostMySQLDAO();
     $post = $post_dao->getPost('25138632577', 'twitter');
     $this->assertIsA($post->links[0], "Link");
     $this->assertEqual($post->post_text, "Raw RSS feed of independent neuroblogs " . "http://friendfeed.com/neuroghetto Now also listed at scienceblogging.org Yay!");
     $this->assertEqual($post->links[0]->url, "http://friendfeed.com/neuroghetto");
     $this->assertEqual($post->links[0]->expanded_url, '');
     $post = $post_dao->getPost('25598018110', 'twitter');
     $this->assertIsA($post->links[0], "Link");
     $this->assertEqual($post->post_text, "Wal-mart: People line up at midnight to buy baby formula, waiting for " . "monthly govt checks to hit accounts http://bit.ly/aK5pCQ");
     $this->assertEqual($post->links[0]->url, "http://bit.ly/aK5pCQ");
     $this->assertEqual($post->links[0]->expanded_url, '');
 }
Example #30
0
 public function testUpdateFavLikeCount()
 {
     $dao = new PostMySQLDAO();
     $post = $dao->getPost(10, 'twitter');
     $this->assertEqual($post->favlike_count_cache, 0);
     // bad id
     $update_cnt = $dao->updateFavLikeCount(-99, 'twitter', 25);
     $this->assertEqual($update_cnt, 0);
     // bad network
     $update_cnt = $dao->updateFavLikeCount(10, 'no-net', 25);
     $this->assertEqual($update_cnt, 0);
     // good id
     $update_cnt = $dao->updateFavLikeCount(10, 'twitter', 25);
     $this->assertEqual($update_cnt, 1);
     $post = $dao->getPost(10, 'twitter');
     $this->assertEqual($post->favlike_count_cache, 25);
 }