public function testInsertHashtag() { $this->debug("Begin testInsertHashtagByHashtagName"); $res = $this->dao->getHashtag('#mwc2013', 'twitter'); $this->assertNull($res); $res = $this->dao->insertHashtag('#mwc2013', 'twitter'); $this->assertEqual($res, 4); $res = $this->dao->getHashtag('#mwc2013', 'twitter'); $this->assertNotNull($res); $this->assertEqual($res->hashtag, '#mwc2013'); $this->debug("End testInsertHashtagByHashtagName"); }
public function testInsertHashtags() { $ht = array('bob', 'dole'); $this->hashtagpost_dao->insertHashtagPosts($ht, '39089424330978176', 'twitter'); $this->hashtagpost_dao->insertHashtagPosts($ht, '39089424330978177', 'twitter'); $res1 = $this->hashtagpost_dao->getHashtagsForPost('39089424330978176', 'twitter'); $res2 = $this->hashtagpost_dao->getHashtagsForPost('39089424330978177', 'twitter'); $this->assertEqual(sizeof($res1), 2); $this->assertEqual(sizeof($res2), 2); $this->assertEqual($res2[1]['hashtag_id'], 3); //setup generated 1 prev hashtag $res3 = $this->hashtag_dao->getHashtag('dole', 'twitter'); $this->assertEqual($res3->count_cache, 2); $res4 = $this->hashtagpost_dao->getHashtagPostsByHashtagID(2); //setup has generated 2 prev hashtags $this->assertEqual(sizeof($res4), 2); $this->assertEqual($res4[0]['post_id'], '39089424330978176'); }
/** * 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 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')); }