public function testGetTotalPostsByHashtagAndDate()
 {
     $this->debug("Begin testGetTotalPostsByHashtagAndDate");
     $builders = array();
     $builders[] = FixtureBuilder::build('hashtags', array('id' => 102, 'hashtag' => 'thinkupsavedsearch', 'network' => 'facebook'));
     //Test specified date
     $count = 0;
     while ($count < 12) {
         // Add 12 posts for a hashtag on 4/1
         $builders[] = FixtureBuilder::build('posts', array('post_id' => $count + 2, 'author_user_id' => '1', 'author_username' => 'aun', 'author_fullname' => 'afn', 'author_avatar' => 'http://aa.com', 'author_follower_count' => 0, 'post_text' => 'pt', 'is_protected' => 0, 'source' => '<a href=""></a>', 'location' => 'BCN', 'place' => '', 'place_id' => '', 'geo' => '', 'pub_date' => '2013-04-01 11:02:34', 'in_reply_to_user_id' => '1', 'in_reply_to_post_id' => '1', 'reply_count_cache' => 1, 'is_reply_by_friend' => 0, 'in_retweet_of_post_id' => '', 'old_retweet_count_cache' => 0, 'is_retweet_by_friend' => 0, 'reply_retweet_distance' => 0, 'network' => 'facebook', 'is_geo_encoded' => 0, 'in_rt_of_user_id' => '', 'retweet_count_cache' => 0, 'retweet_count_api' => 0, 'favlike_count_cache' => 0));
         $builders[] = FixtureBuilder::build('hashtags_posts', array('post_id' => $count + 2, 'hashtag_id' => 102, 'network' => 'facebook'));
         $count++;
     }
     $count = $this->hashtagpost_dao->getTotalPostsByHashtagAndDate(102, '2013-04-01');
     $this->assertEqual($count, 12);
     //Test today
     $today = date('Y-m-d H:i:s');
     $count = 0;
     while ($count < 7) {
         // Add 7 posts for a hashtag today
         $builders[] = FixtureBuilder::build('posts', array('post_id' => $count + 14, 'author_user_id' => '1', 'author_username' => 'aun', 'author_fullname' => 'afn', 'author_avatar' => 'http://aa.com', 'author_follower_count' => 0, 'post_text' => 'pt', 'is_protected' => 0, 'source' => '<a href=""></a>', 'location' => 'BCN', 'place' => '', 'place_id' => '', 'geo' => '', 'pub_date' => $today, 'in_reply_to_user_id' => '1', 'in_reply_to_post_id' => '1', 'reply_count_cache' => 1, 'is_reply_by_friend' => 0, 'in_retweet_of_post_id' => '', 'old_retweet_count_cache' => 0, 'is_retweet_by_friend' => 0, 'reply_retweet_distance' => 0, 'network' => 'facebook', 'is_geo_encoded' => 0, 'in_rt_of_user_id' => '', 'retweet_count_cache' => 0, 'retweet_count_api' => 0, 'favlike_count_cache' => 0));
         $builders[] = FixtureBuilder::build('hashtags_posts', array('post_id' => $count + 14, 'hashtag_id' => 102, 'network' => 'facebook'));
         $count++;
     }
     $count = $this->hashtagpost_dao->getTotalPostsByHashtagAndDate(102);
     $this->assertEqual($count, 7);
     $this->debug("End testGetTotalPostsByHashtagAndDate");
 }
 /**
  * This method tests basic handling of the data structures generated by the json parser, including entity and
  * user information. In add'n, it tests new-style rt handling.
  */
 public function testAddPostAndAssociatedInfo()
 {
     list($post, $entities, $user_array) = $this->buildStreamPostArray1();
     $dao = new PostMySQLDAO();
     $dao->addPostAndAssociatedInfo($post, $entities, $user_array);
     $post_orig = $dao->getPost('39088587140108288', 'twitter');
     $this->assertEqual($post_orig->post_text, '@joanwalsh RT @AntDeRosa Hillary #Clinton provides perhaps the best argument defending Planned ' . 'Parenthood (Video, 2009) http://j.mp/eZbWh0');
     $this->assertEqual($post_orig->post_id, '39088587140108288');
     $this->assertEqual($post_orig->retweet_count_cache, 1);
     $this->assertEqual($post_orig->old_retweet_count_cache, 0);
     $this->assertEqual($post_orig->in_retweet_of_post_id, null);
     $post_rt = $dao->getPost('39089424620978176', 'twitter');
     $this->assertEqual($post_rt->post_id, '39089424620978176');
     $this->assertEqual($post_rt->post_text, 'RT @HeyJacquiDey: @joanwalsh RT @AntDeRosa ' . 'Hillary #Clinton provides perhaps the best argument defending Planned Parenthood (Video, 2009) ...');
     $this->assertEqual($post_rt->retweet_count_cache, 0);
     $this->assertEqual($post_rt->old_retweet_count_cache, 0);
     $this->assertEqual($post_rt->in_retweet_of_post_id, '39088587140108288');
     $this->assertEqual($post_rt->in_rt_of_user_id, '136881432');
     $hashtag_dao = new HashtagMySQLDAO();
     $hashtagpost_dao = new HashtagPostMySQLDAO();
     $m_dao = new MentionMySQLDAO();
     $h = $hashtag_dao->getHashtag('Clinton', 'twitter');
     $this->assertEqual($h->count_cache, 2);
     $hp = $hashtagpost_dao->getHashtagsForPost('39088587140108288', 'twitter');
     $this->assertEqual(sizeof($hp), 1);
     $this->assertEqual($hp[0]['post_id'], '39088587140108288');
     $hp = $hashtagpost_dao->getHashtagsForPost('39089424620978176', 'twitter');
     $this->assertEqual($hp[0]['post_id'], '39089424620978176');
     $this->assertEqual($hp[0]['hashtag_id'], 3);
     $hph = $hashtagpost_dao->getHashtagPostsByHashtagID(3);
     $this->assertEqual(sizeof($hph), 2);
     $this->assertEqual($hph[1]['post_id'], '39089424620978176');
     $m = $m_dao->getMentionInfoUserName('joanwalsh');
     $this->assertEqual($m['count_cache'], 2);
     $mp = $m_dao->getMentionsForPost('39089424620978176');
     $this->assertEqual(sizeof($mp), 3);
     $this->assertEqual($mp[1]['mention_id'], 2);
     $mpm = $m_dao->getMentionsForPostMID(2);
     $this->assertEqual(sizeof($mpm), 2);
     $this->assertEqual($mpm[0]['post_id'], '39088587140108288');
 }
 public function testDeleteExistingInstanceWithTweetSearchWithPrivilegesWithOtherOwners()
 {
     $this->debug(__METHOD__);
     //Not admin with access privs, with other owners (delete owner instance and NOT instance)
     $builders = array();
     $builders[] = FixtureBuilder::build('instances', array('id' => 2, 'network_user_id' => 12, 'network_username' => 'tuinstance', 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 1, 'instance_id' => 2, 'oauth_access_token' => 'xxx', 'oauth_access_token_secret' => 'yyy'));
     $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 2, 'instance_id' => 2, 'oauth_access_token' => 'xxx', 'oauth_access_token_secret' => 'yyy'));
     $instance_dao = new InstanceMySQLDAO();
     $owner_instance_dao = new OwnerInstanceMySQLDAO();
     $instance_hashtag_dao = new InstanceHashtagMySQLDAO();
     //before builder
     $instance = $instance_dao->get(2);
     $this->assertNotNull($instance);
     $instances_hashtags = $instance_hashtag_dao->getByInstance($instance->id);
     $this->assertEqual(sizeof($instances_hashtags), 0);
     $builder = $this->buildHashtagData(2);
     //after builder
     $hashtag_dao = new HashtagMySQLDAO();
     $hashtagpost_dao = new HashtagPostMySQLDAO();
     $hashtags = $hashtagpost_dao->getHashtagsForPost(1, 'twitter');
     $this->assertEqual(sizeof($hashtags), 1);
     $hashtags = $hashtagpost_dao->getHashtagsForPost(2, 'twitter');
     $this->assertEqual(sizeof($hashtags), 1);
     //instances hashtags should be deleted
     $instances_hashtags = $instance_hashtag_dao->getByInstance(2);
     $this->assertEqual(sizeof($instances_hashtags), 2);
     //hashtag should be deleted
     $hashtag = $hashtag_dao->getHashtagByID(1);
     $this->assertEqual(sizeof($hashtag), 1);
     $hashtag = $hashtag_dao->getHashtagByID(2);
     $this->assertEqual(sizeof($hashtag), 1);
     //Should delete the owner instance but leave the instance alone
     $this->simulateLogin('me@example.com', false, true);
     $_POST['action'] = "Delete";
     $_POST["instance_id"] = 2;
     $_POST['csrf_token'] = parent::CSRF_TOKEN;
     $controller = new AccountConfigurationController(true);
     //before
     $instance = $instance_dao->get(2);
     $this->assertNotNull($instance);
     $owner_instances = $owner_instance_dao->getByInstance(2);
     $this->assertNotNull($owner_instances);
     $this->assertIsA($owner_instances, 'Array');
     $this->assertEqual(sizeof($owner_instances), 2);
     //process controller
     $controller->go();
     //hashtags posts should be deleted
     $hashtags = $hashtagpost_dao->getHashtagsForPost(1, 'twitter');
     $this->assertEqual(sizeof($hashtags), 1);
     $hashtags = $hashtagpost_dao->getHashtagsForPost(2, 'twitter');
     $this->assertEqual(sizeof($hashtags), 1);
     //instances hashtags should NOT be deleted
     $instances_hashtags = $instance_hashtag_dao->getByInstance(2);
     $this->assertEqual(sizeof($instances_hashtags), 2);
     //hashtag should NOT be deleted
     $hashtag = $hashtag_dao->getHashtagByID(1);
     $this->assertEqual(sizeof($hashtag), 1);
     $hashtag = $hashtag_dao->getHashtagByID(2);
     $this->assertEqual(sizeof($hashtag), 1);
     $this->debug('Still running');
     //instance should NOT be deleted
     $instance = $instance_dao->get(2);
     $this->assertNotNull($instance);
     //just one owner_instance should be deleted
     $owner_instances = $owner_instance_dao->getByInstance(2);
     $this->assertIsA($owner_instances, 'Array');
     $this->assertEqual(sizeof($owner_instances), 1);
     $v_mgr = $controller->getViewManager();
     $success_msgs = $v_mgr->getTemplateDataItem('success_msgs');
     $this->assertNotNull($success_msgs);
     $this->assertEqual($success_msgs['account'], 'Account deleted.');
     $this->assertNull($v_mgr->getTemplateDataItem('error_msg'));
 }