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 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 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 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'); }