コード例 #1
0
    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 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');
    }
コード例 #3
0
 public function testGetOwnerInstance()
 {
     $builder = FixtureBuilder::build(self::TEST_TABLE_OI, array('instance_id' => 20));
     $dao = new OwnerInstanceMySQLDAO();
     // no record
     $owner_instance = $dao->get(1, 20);
     $this->assertNull($owner_instance);
     $owner_instance = $dao->get($builder->columns['owner_id'], 21);
     $this->assertNull($owner_instance);
     // valid record
     $owner_instance = $dao->get($builder->columns['owner_id'], 20);
     $this->assertIsA($owner_instance, 'OwnerInstance');
     $columns = $builder->columns;
     $this->assertEqual($owner_instance->owner_id, $columns['owner_id'], 'valid owner id');
     $this->assertEqual($owner_instance->instance_id, $columns['instance_id'], 'valid instance id');
     $this->assertEqual($owner_instance->oauth_access_token, $columns['oauth_access_token'], 'valid oauth_access_token');
     $this->assertEqual($owner_instance->oauth_access_token_secret, $columns['oauth_access_token_secret'], 'valid oauth_access_token_secret');
 }
 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');
 }
コード例 #5
0
 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);
 }
コード例 #7
0
 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');
 }
コード例 #8
0
    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);
    }
コード例 #9
0
ファイル: TestOfFacebookPlugin.php プロジェクト: dgw/ThinkUp
 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, '');
 }
コード例 #10
0
 public function testSetAuthErrorByTokens()
 {
     $builder = FixtureBuilder::build(self::TEST_TABLE_OI, array('instance_id' => 20, 'owner_id' => 50, 'auth_error' => '', 'oauth_access_token' => '1234', 'oauth_access_token_secret' => ''));
     $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->setAuthErrorByTokens(20, '1234', '', '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->setAuthErrorByTokens(20, '1234', 'dfdfd', 'Error validating access token: Session has expired ' . 'at unix time SOME_TIME. The current unix time is SOME_TIME.');
     $this->assertFalse($res);
     $res = $dao->setAuthErrorByTokens(20, '1234', '');
     $this->assertTrue($res);
     $owner_instance = $dao->get(50, 20);
     $this->assertIsA($owner_instance, 'OwnerInstance');
     $this->assertEqual($owner_instance->auth_error, '');
 }