public function tearDown() { parent::tearDown(); //clear doesOwnerHaveAccessToPost query cache OwnerInstanceMySQLDAO::$post_access_query_cache = array(); }
public function testDoesOwnerHaveAccessToPost() { $oi_data = array('owner_id' => 2, 'instance_id' => 20); $oinstances_builder = FixtureBuilder::build(self::TEST_TABLE_OI, $oi_data); $i_data = array('id' => 20, 'network_username' => 'mojojojo', 'network_user_id' => '10', 'network' => 'twitter'); $instances_builder = FixtureBuilder::build(self::TEST_TABLE_I, $i_data); $dao = new OwnerInstanceMySQLDAO(); $post = new Post(array('id' => 1, 'author_user_id' => '20', 'author_username' => 'no one', 'author_fullname' => "No One", 'author_avatar' => 'yo.jpg', 'source' => 'TweetDeck', 'pub_date' => '', 'adj_pub_date' => '', 'in_reply_to_user_id' => '', 'in_reply_to_post_id' => '', 'reply_count_cache' => '', 'in_retweet_of_post_id' => '', 'retweet_count_cache' => '', 'retweet_count_api' => '', 'old_retweet_count_cache' => '', 'in_rt_of_user_id' => '', 'post_id' => '9021481076', 'is_protected' => 1, 'place_id' => 'ece7b97d252718cc', 'favlike_count_cache' => 0, 'post_text' => 'I like cookies', 'network' => 'twitter', 'geo' => '', 'place' => '', 'location' => '', 'is_geo_encoded' => 0, 'is_reply_by_friend' => 0, 'is_retweet_by_friend' => 0, 'reply_retweet_distance' => 0)); // no owner id try { $dao->doesOwnerHaveAccessToPost(new Owner(), $post); $this->fail("should throw BadArgumentException"); } catch (BadArgumentException $e) { $this->assertPattern('/requires an/', $e->getMessage()); } // no match $owner = new Owner(); $owner->id = 1; //public post and owner not admin $post->is_protected = false; $this->assertTrue($dao->doesOwnerHaveAccessToPost($owner, $post)); //protected post and owner not admin $post->is_protected = true; $this->assertFalse($dao->doesOwnerHaveAccessToPost($owner, $post)); // should have empty cache arrays $this->assertEqual(count(OwnerInstanceMySQLDAO::$post_access_query_cache['1-twitter-network_id_cache']), 0); $this->assertEqual(count(OwnerInstanceMySQLDAO::$post_access_query_cache['20-twitter-follower_id_cache']), 0); //protected post but owner is admin $owner->is_admin = true; $this->assertTrue($dao->doesOwnerHaveAccessToPost($owner, $post)); //protected post, owner is not admin, and owner doesn't have an authed instance which follows author $owner->is_admin = false; $this->assertFalse($dao->doesOwnerHaveAccessToPost($owner, $post)); //protected post, owner is not admin, and owner DOES have an authed instance which follows author OwnerInstanceMySQLDAO::$post_access_query_cache = array(); // clear cache $owner->id = 2; $follows_builder = FixtureBuilder::build('follows', array('user_id' => '20', 'follower_id' => '10', 'network' => 'twitter')); $this->assertTrue($dao->doesOwnerHaveAccessToPost($owner, $post)); // should have populated cache arrays $this->assertEqual(count(OwnerInstanceMySQLDAO::$post_access_query_cache['2-twitter-network_id_cache']), 1); $this->assertEqual(count(OwnerInstanceMySQLDAO::$post_access_query_cache['20-twitter-follower_id_cache']), 1); $this->assertEqual(OwnerInstanceMySQLDAO::$post_access_query_cache['2-twitter-network_id_cache'][0]['network_user_id'], 10); $this->assertEqual(OwnerInstanceMySQLDAO::$post_access_query_cache['20-twitter-follower_id_cache'][0]['follower_id'], 10); }
public function testCrawlWithAuthError() { //build active instance owned by a owner $instance_with_autherror = array('id' => 5, 'network_username' => 'Liz Lemon', 'network_user_id' => '123456', 'network_viewer_id' => '123456', 'last_post_id' => '0', 'total_posts_in_system' => '0', 'total_replies_in_system' => '0', 'total_follows_in_system' => '0', 'is_archive_loaded_replies' => '0', 'is_archive_loaded_follows' => '0', 'crawler_last_run' => '', 'earliest_reply_in_system' => '', 'avg_replies_per_day' => '2', 'is_public' => '0', 'is_active' => '1', 'network' => 'facebook', 'last_favorite_id' => '0', 'owner_favs_in_system' => '0', 'total_posts_by_owner' => 0, 'posts_per_day' => 1, 'posts_per_week' => 1, 'percentage_replies' => 50, 'percentage_links' => 50, 'earliest_post_in_system' => '2009-01-01 13:48:05', 'favorites_profile' => '0'); $instance_builder_1 = FixtureBuilder::build('instances', $instance_with_autherror); $builders = array(); $builders[] = FixtureBuilder::build('owners', array('id' => 1, 'full_name' => 'ThinkUp J. User', 'email' => '*****@*****.**', 'is_activated' => 1)); $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 1, 'instance_id' => 5, 'auth_error' => '')); //assert invalid_oauth_email_sent_timestamp option is not set $option_dao = DAOFactory::getDAO('OptionDAO'); $plugin_dao = DAOFactory::getDAO('PluginDAO'); $plugin_id = $plugin_dao->getPluginId('facebook'); $last_email_timestamp = $option_dao->getOptionByName(OptionDAO::PLUGIN_OPTIONS . '-' . $plugin_id, 'invalid_oauth_email_sent_timestamp'); $this->assertNull($last_email_timestamp); //log in as that owner $this->simulateLogin('*****@*****.**'); $_SERVER['HTTP_HOST'] = "mytestthinkup"; //run the crawl $fb_plugin = new FacebookPlugin(); $fb_plugin->crawl(); //assert that APIOAuthException was caught and recorded in owner_instances table $owner_instance_dao = new OwnerInstanceMySQLDAO(); $owner_instance = $owner_instance_dao->get(1, 5); $this->assertEqual($owner_instance->auth_error, 'Error validating access token: Session has expired at unix ' . 'time SOME_TIME. The current unix time is SOME_TIME.'); //assert that the email notification was sent to the user $expected_reg_email_pattern = '/to: me@example.com subject: Please re-authorize ThinkUp to access Liz Lemon on Facebook message: Hi! Your ThinkUp installation is no longer connected to the Liz Lemon Facebook account./'; $actual_reg_email = Mailer::getLastMail(); $this->debug($actual_reg_email); $this->assertPattern($expected_reg_email_pattern, $actual_reg_email); //assert invalid_oauth_email_sent_timestamp option has been set $last_email_timestamp = $option_dao->getOptionByName(OptionDAO::PLUGIN_OPTIONS . '-' . $plugin_id, 'invalid_oauth_email_sent_timestamp'); $this->assertNotNull($last_email_timestamp); //Delete last mail file $test_email_file = FileDataManager::getDataPath(Mailer::EMAIL); unlink($test_email_file); $actual_reg_email = Mailer::getLastMail(); //Assert it's been deleted $this->assertEqual($actual_reg_email, ''); //Crawl again $fb_plugin->crawl(); //Assert email has not been resent $actual_reg_email = Mailer::getLastMail(); $this->debug($actual_reg_email); $this->assertEqual($actual_reg_email, ''); }
public function testConnectAccountThatAlreadyExists() { self::buildInstanceData(); $owner_instance_dao = new OwnerInstanceMySQLDAO(); $instance_dao = new InstanceMySQLDAO(); $owner_dao = new OwnerMySQLDAO(); $config = Config::getInstance(); $config->setValue('site_root_path', '/'); $_SERVER['SERVER_NAME'] = "srvr"; SessionCache::put('facebook_auth_csrf', '123'); $_GET['p'] = 'facebook'; $_GET['code'] = '456'; $_GET['state'] = '123'; $options_arry = $this->buildPluginOptions(); $this->simulateLogin('*****@*****.**', true); $owner = $owner_dao->getByEmail(Session::getLoggedInUser()); $controller = new FacebookPluginConfigurationController($owner, 'facebook'); $output = $controller->go(); $v_mgr = $controller->getViewManager(); $msgs = $v_mgr->getTemplateDataItem('success_msgs'); $this->assertEqual($msgs['user_add'], "Success! You've reconnected your Facebook account. To connect " . "a different account, log out of Facebook in a different browser tab and try again."); $this->debug(Utils::varDumpToString($msgs)); $instance = $instance_dao->getByUserIdOnNetwork('606837591', 'facebook'); $this->assertNotNull($instance); $owner_instance = $owner_instance_dao->get($owner->id, $instance->id); $this->assertNotNull($owner_instance); $this->assertEqual($owner_instance->oauth_access_token, 'newfauxaccesstoken11234567890'); }
public function testReconnectAccount() { $owner_instance_dao = new OwnerInstanceMySQLDAO(); $instance_dao = new InstanceMySQLDAO(); $owner_dao = new OwnerMySQLDAO(); $_GET['p'] = 'facebook'; $_GET['perms'] = 'offline_access,read_stream,user_likes,user_location,user_website,read_friendlists'; $_GET['selected_profiles'] = '606837591'; $_GET['session'] = '{"session_key":"new-faux-access-token","uid":"606837591","expires":0,"secret":'. '"itsasecret","access_token":"new-faux-access-token","sig":"siggysigsig"}'; $options_arry = $this->buildPluginOptions(); $this->simulateLogin('*****@*****.**', true); $owner = $owner_dao->getByEmail(Session::getLoggedInUser()); $controller = new FacebookPluginConfigurationController($owner, 'facebook'); $output = $controller->go(); $v_mgr = $controller->getViewManager(); $this->assertEqual($v_mgr->getTemplateDataItem('successmsg'), "Success! You've reconnected your Facebook ". "account."); $instance = $instance_dao->getByUserIdOnNetwork('606837591', 'facebook'); $this->assertTrue(isset($instance)); $oinstance = $owner_instance_dao->get($owner->id, $instance->id); $this->assertTrue(isset($oinstance)); $this->assertEqual($oinstance->oauth_access_token, 'new-faux-access-token'); }
public function testAccountWithAuthError() { self::buildInstanceData(); $owner_instance_dao = new OwnerInstanceMySQLDAO(); $instance_dao = new InstanceMySQLDAO(); $owner_dao = new OwnerMySQLDAO(); $config = Config::getInstance(); $config->setValue('site_root_path', '/'); $_SERVER['SERVER_NAME'] = "srvr"; $options_array = $this->buildPluginOptions(); $this->simulateLogin('*****@*****.**', true); $owner = $owner_dao->getByEmail(Session::getLoggedInUser()); $instance = $instance_dao->getByUserIdOnNetwork('606837591', 'facebook'); $this->assertNotNull($instance); //assert there is an auth error $owner_instance = $owner_instance_dao->get($owner->id, $instance->id); $this->assertEqual($owner_instance->auth_error, 'Token has expired.'); $controller = new FacebookPluginConfigurationController($owner, 'facebook'); $output = $controller->go(); $this->debug($output); $this->assertPattern('/Facebook connection expired/', $output); }
public function testGetOAuthTokens() { $builders = $this->buildPluginOptions(); $config = Config::getInstance(); $config->setValue('site_root_path', '/'); $plugin_options_dao = DAOFactory::getDAO("PluginOptionDAO"); PluginOptionMySQLDAO::$cached_options = array(); $builders[] = FixtureBuilder::build('owners', array('email' => '*****@*****.**', 'user_activated' => 1)); $this->simulateLogin('*****@*****.**'); $owner_dao = DAOFactory::getDAO('OwnerDAO'); $owner = $owner_dao->getByEmail(Session::getLoggedInUser()); $controller = new GooglePlusPluginConfigurationController($owner); $_GET['code'] = 'test-google-provided-code'; $results = $controller->go(); $v_mgr = $controller->getViewManager(); $msgs = $v_mgr->getTemplateDataItem('success_msgs'); $this->assertEqual($msgs['user_add'], 'Success! Your Google+ account has been added to ThinkUp.'); $this->debug(Utils::varDumpToString($msgs)); $owner_instance_dao = new OwnerInstanceMySQLDAO(); $instance_dao = new InstanceMySQLDAO(); $instance = $instance_dao->getByUserIdOnNetwork('113612142759476883204', 'google+'); $this->assertNotNull($instance); //Instance created $owner_instance = $owner_instance_dao->get($owner->id, $instance->id); $this->assertNotNull($owner_instance); //Owner Instance created //OAuth tokens set $this->assertEqual($owner_instance->oauth_access_token, 'faux-access-token'); $this->assertEqual($owner_instance->oauth_access_token_secret, 'faux-refresh-token'); }
public function testDeleteExistingInstanceNoPrivileges() { //Not admin without access privs (set error messages) $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' => 2, 'instance_id' => 2, 'oauth_access_token' => 'xxx', 'oauth_access_token_secret' => 'yyy')); $instance_dao = new InstanceMySQLDAO(); $owner_instance_dao = new OwnerInstanceMySQLDAO(); //Should delete the owner instance but leave the instance alone $this->simulateLogin('*****@*****.**'); $_POST['action'] = "delete"; $_POST["instance_id"] = 2; $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), 1); //process controller $controller->go(); //instance should NOT be deleted $instance = $instance_dao->get(2); $this->assertNotNull($instance); //owner instance should NOT be deleted $owner_instances = $owner_instance_dao->getByInstance(2); $this->assertIsA($owner_instances, 'Array'); $this->assertEqual(sizeof($owner_instances), 1); $v_mgr = $controller->getViewManager(); $this->assertNull($v_mgr->getTemplateDataItem('successmsg')); $this->assertNotNull($v_mgr->getTemplateDataItem('errormsg')); $this->assertEqual($v_mgr->getTemplateDataItem('errormsg'), 'Insufficient privileges.'); }
public function testGetOAuthTokens() { // Set the plugin options $builders = $this->buildPluginOptions(); // Get an instance $config = Config::getInstance(); // Set the root path $config->setValue('site_root_path', '/'); // Get a plugin options DAO $plugin_options_dao = DAOFactory::getDAO("PluginOptionDAO"); // PluginOptionMySQLDAO::$cached_options = array(); // Build an owner $builders[] = FixtureBuilder::build('owners', array('email' => '*****@*****.**', 'user_activated' => 1)); $instance_builder = FixtureBuilder::build('instances', array('id' => 1, 'network_user_id' => '18127856', 'network_username' => '*****@*****.**', 'network' => 'foursquare', 'is_active' => 1)); //Add owner instance_owner $owner_instance_builder = FixtureBuilder::build('owner_instances', array('owner_id' => 1, 'instance_id' => 1, 'oauth_access_token' => 'secret')); // Log them in $this->simulateLogin('*****@*****.**'); // Get an owner DAO $owner_dao = DAOFactory::getDAO('OwnerDAO'); // Get the logged in owners email $owner = $owner_dao->getByEmail(Session::getLoggedInUser()); // Create a new config controller for the owner $controller = new FoursquarePluginConfigurationController($owner); // Set the code foursquare would return from a real request $_GET['code'] = '5dn'; // Check we get the tokens and tell the user it was a sucess $results = $controller->go(); $v_mgr = $controller->getViewManager(); $msgs = $v_mgr->getTemplateDataItem('success_msgs'); $this->assertEqual($msgs['user_add'], 'Success! Your foursquare account has been added to ThinkUp.'); // Get an owner instance DAO $owner_instance_dao = new OwnerInstanceMySQLDAO(); // Get a instance DAO $instance_dao = new InstanceMySQLDAO(); // Check we created a foursquare instance $instance = $instance_dao->getByUserIdOnNetwork('18127856', 'foursquare'); $this->assertNotNull($instance); // Check a owner instance for this user with the instance ID was created $owner_instance = $owner_instance_dao->get($owner->id, $instance->id); $this->assertNotNull($owner_instance); // OAuth tokens set $this->assertEqual($owner_instance->oauth_access_token, 'secret'); }
public function testCrawlWithAuthError() { //build active instance owned by a owner $instance_with_autherror = array('id' => 5, 'network_username' => 'Liz Lemon', 'network_user_id' => '123456', 'network_viewer_id' => '123456', 'last_post_id' => '0', 'last_page_fetched_replies' => 0, 'last_page_fetched_tweets' => '0', 'total_posts_in_system' => '0', 'total_replies_in_system' => '0', 'total_follows_in_system' => '0', 'is_archive_loaded_replies' => '0', 'is_archive_loaded_follows' => '0', 'crawler_last_run' => '', 'earliest_reply_in_system' => '', 'avg_replies_per_day' => '2', 'is_public' => '0', 'is_active' => '1', 'network' => 'facebook', 'last_favorite_id' => '0', 'last_unfav_page_checked' => '0', 'last_page_fetched_favorites' => '0', 'owner_favs_in_system' => '0', 'total_posts_by_owner' => 0, 'posts_per_day' => 1, 'posts_per_week' => 1, 'percentage_replies' => 50, 'percentage_links' => 50, 'earliest_post_in_system' => '01-01-2009', 'favorites_profile' => '0'); $instance_builder_1 = FixtureBuilder::build('instances', $instance_with_autherror); $builders = array(); $builders[] = FixtureBuilder::build('owners', array('id' => 1, 'full_name' => 'ThinkUp J. User', 'email' => '*****@*****.**', 'is_activated' => 1)); $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 1, 'instance_id' => 5, 'auth_error' => '')); //log in as that owner $this->simulateLogin('*****@*****.**'); $_SERVER['HTTP_HOST'] = "mytestthinkup"; //run the crawl $fb_plugin = new FacebookPlugin(); $fb_plugin->crawl(); //assert that APIOAuthException was caught and recorded in owner_instances table $owner_instance_dao = new OwnerInstanceMySQLDAO(); $owner_instance = $owner_instance_dao->get(1, 5); $this->assertEqual($owner_instance->auth_error, 'Error validating access token: Session has expired at unix ' . 'time SOME_TIME. The current unix time is SOME_TIME.'); //assert that the email notification was sent to the user $expected_reg_email_pattern = '/to: me@example.com subject: Please re-authorize ThinkUp to access Liz Lemon on Facebook message: Hi! Your ThinkUp installation is no longer connected to the Liz Lemon Facebook account./'; $actual_reg_email = Mailer::getLastMail(); $this->debug($actual_reg_email); $this->assertPattern($expected_reg_email_pattern, $actual_reg_email); }
public function testCrawlWithUnexpectedErrorPleaseTryAgain() { //build active instance owned by a owner $instance_with_autherror = array('id' => 5, 'network_username' => 'Liz Lemon', 'network_user_id' => '123456-app-throttled', 'network_viewer_id' => '123456-unexpected-error-try-again', 'last_post_id' => '0', 'total_posts_in_system' => '0', 'total_replies_in_system' => '0', 'total_follows_in_system' => '0', 'is_archive_loaded_replies' => '0', 'is_archive_loaded_follows' => '0', 'crawler_last_run' => '', 'earliest_reply_in_system' => '', 'avg_replies_per_day' => '2', 'is_public' => '0', 'is_active' => '1', 'network' => 'facebook', 'last_favorite_id' => '0', 'owner_favs_in_system' => '0', 'total_posts_by_owner' => 0, 'posts_per_day' => 1, 'posts_per_week' => 1, 'percentage_replies' => 50, 'percentage_links' => 50, 'earliest_post_in_system' => '2009-01-01 13:48:05', 'favorites_profile' => '0'); $instance_builder_1 = FixtureBuilder::build('instances', $instance_with_autherror); $builders = array(); $builders[] = FixtureBuilder::build('owners', array('id' => 1, 'full_name' => 'ThinkUp J. User', 'email' => '*****@*****.**', 'is_activated' => 1, 'is_admin' => 1)); $builders[] = FixtureBuilder::build('owners', array('id' => 2, 'full_name' => 'ThinkUp K. User', 'email' => '*****@*****.**', 'is_activated' => 1)); $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 2, 'instance_id' => 5, 'auth_error' => '', 'oauth_access_token' => 'zL11BPY2fZPPyYY', 'oauth_access_token_secret' => '')); //assert invalid_oauth_email_sent_timestamp option is not set $option_dao = DAOFactory::getDAO('OptionDAO'); $plugin_dao = DAOFactory::getDAO('PluginDAO'); $plugin_id = $plugin_dao->getPluginId('facebook'); $last_email_timestamp = $option_dao->getOptionByName(OptionDAO::PLUGIN_OPTIONS . '-' . $plugin_id, 'invalid_oauth_email_sent_timestamp'); $this->assertNull($last_email_timestamp); //log in as that owner $this->simulateLogin('*****@*****.**'); $_SERVER['HTTP_HOST'] = "mytestthinkup"; //run the crawl $fb_plugin = new FacebookPlugin(); $fb_plugin->crawl(); //assert that APIOAuthException was caught and recorded in owner_instances table $owner_instance_dao = new OwnerInstanceMySQLDAO(); $owner_instance = $owner_instance_dao->get(2, 5); $this->debug(Utils::varDumpToString($owner_instance)); //assert that the application request throttling error was not saved $this->assertEqual($owner_instance->auth_error, ''); //assert that the reauth email notification was not sent to user $actual_reg_email = Mailer::getLastMail(); $this->debug($actual_reg_email); $this->assertEqual($actual_reg_email, ''); }
public function testGetOwnerEmailByInstanceTokens() { $builders = array(); $builders[] = FixtureBuilder::build(self::TEST_TABLE_OI, array('instance_id' => 20, 'owner_id' => 50, 'auth_error' => '', 'oauth_access_token' => '1234', 'oauth_access_token_secret' => '')); $builders[] = FixtureBuilder::build('owners', array('id' => 50, 'email' => '*****@*****.**')); $dao = new OwnerInstanceMySQLDAO(); $email = $dao->getOwnerEmailByInstanceTokens('20', '1234'); $this->assertEqual($email, '*****@*****.**'); $email = $dao->getOwnerEmailByInstanceTokens('20', 'abcd1234'); $this->assertNull($email); $email = $dao->getOwnerEmailByInstanceTokens('21', '1234'); $this->assertNull($email); }
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('*****@*****.**', 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')); }
public function testSetAuthError() { $builder = FixtureBuilder::build(self::TEST_TABLE_OI, array('instance_id' => 20, 'owner_id' => 50, 'auth_error' => '')); $dao = new OwnerInstanceMySQLDAO(); $owner_instance = $dao->get(50, 20); $this->assertNotNull($owner_instance); $this->assertIsA($owner_instance, 'OwnerInstance'); $this->assertEqual($owner_instance->auth_error, ''); $res = $dao->setAuthError(50, 20, 'Error validating access token: Session has expired at unix time SOME_TIME. ' . 'The current unix time is SOME_TIME.'); $this->assertTrue($res); $owner_instance = $dao->get(50, 20); $this->assertNotNull($owner_instance); $this->assertIsA($owner_instance, 'OwnerInstance'); $this->assertEqual($owner_instance->auth_error, 'Error validating access token: Session has expired at ' . 'unix time SOME_TIME. The current unix time is SOME_TIME.'); $res = $dao->setAuthError(49, 20, 'Error validating access token: Session has expired at unix time SOME_TIME. ' . 'The current unix time is SOME_TIME.'); $this->assertFalse($res); $res = $dao->setAuthError(50, 20); $this->assertTrue($res); $owner_instance = $dao->get(50, 20); $this->assertIsA($owner_instance, 'OwnerInstance'); $this->assertEqual($owner_instance->auth_error, ''); }