Copyright (c) 2009-2010 Gina Trapani, Mark Wilkie
LICENSE:
This file is part of ThinkUp (http://thinkupapp.com).
ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
later version.
ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
.
public function authControl() { $config = Config::getInstance(); Loader::definePathConstants(); $this->setViewTemplate(THINKUP_WEBAPP_PATH . 'plugins/facebook/view/facebook.account.index.tpl'); $this->view_mgr->addHelp('facebook', 'userguide/settings/plugins/facebook'); /** set option fields **/ // Application ID text field $this->addPluginOption(self::FORM_TEXT_ELEMENT, array('name' => 'facebook_app_id', 'label' => 'App ID', 'size' => 18)); // add element // set a special required message $this->addPluginOptionRequiredMessage('facebook_app_id', 'The Facebook plugin requires a valid App ID.'); // Application Secret text field $this->addPluginOption(self::FORM_TEXT_ELEMENT, array('name' => 'facebook_api_secret', 'label' => 'App Secret', 'size' => 37)); // add element // set a special required message $this->addPluginOptionRequiredMessage('facebook_api_secret', 'The Facebook plugin requires a valid App Secret.'); $max_crawl_time_label = 'Max crawl time in minutes'; $max_crawl_time = array('name' => 'max_crawl_time', 'label' => $max_crawl_time_label, 'default_value' => '20', 'advanced' => true, 'size' => 3); $this->addPluginOption(self::FORM_TEXT_ELEMENT, $max_crawl_time); $this->addToView('thinkup_site_url', Utils::getApplicationURL()); $facebook_plugin = new FacebookPlugin(); if ($facebook_plugin->isConfigured()) { $this->setUpFacebookInteractions($facebook_plugin->getOptionsHash()); $this->addToView('is_configured', true); } else { $this->addInfoMessage('Please complete plugin setup to start using it.', 'setup'); $this->addToView('is_configured', false); } return $this->generateView(); }
public function testDeactivate() { //all facebook and facebook page accounts should be set to inactive on plugin deactivation $webapp = Webapp::getInstance(); $logger = Logger::getInstance(); $pd = DAOFactory::getDAO('PostDAO'); $instance = new Instance(); $instance->network_user_id = 1; $instance_builder_1 = FixtureBuilder::build('instances', array('network_username' => 'julie', 'network' => 'facebook', 'crawler_last_run' => '-1d', 'is_activated' => '1', 'is_public' => '1')); $instance_builder_2 = FixtureBuilder::build('instances', array('network_username' => 'julie', 'network' => 'facebook page', 'crawler_last_run' => '-1d', 'is_activated' => '1', 'is_public' => '1')); $instance_dao = DAOFactory::getDAO('InstanceDAO'); $fb_active_instances = $instance_dao->getAllInstances("DESC", true, "facebook"); $this->assertEqual(sizeof($fb_active_instances), 1); $fb_active_instances = $instance_dao->getAllInstances("DESC", true, "facebook page"); $this->assertEqual(sizeof($fb_active_instances), 1); $fb_plugin = new FacebookPlugin(); $fb_plugin->deactivate(); $fb_active_instances = $instance_dao->getAllInstances("DESC", true, "facebook"); $this->assertEqual(sizeof($fb_active_instances), 0); $fb_active_instances = $instance_dao->getAllInstances("DESC", true, "facebook page"); $this->assertEqual(sizeof($fb_active_instances), 0); $logger->close(); }
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 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 testForProfileUpdated() { $builders = array(); $builders[] = FixtureBuilder::build('owners', array('id' => 1, 'full_name' => 'ThinkUp J. User', 'email' => '*****@*****.**', 'is_activated' => 1, 'is_admin' => 1)); $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 1, 'instance_id' => 1, 'auth_error' => '', 'oauth_access_token' => 'zL11BPY2fZPPyYY', 'oauth_access_token_secret' => '')); $builders[] = FixtureBuilder::build('instances', array('id' => 1, 'network_username' => 'Gina Trapani', 'network_user_id' => '606837591', 'network_viewer_id' => '606837591', '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' => '0', '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', 'is_active' => 1)); $instance_dao = DAOFactory::getDAO('FacebookInstanceDAO'); $instance = $instance_dao->getByUsername('Gina Trapani', 'facebook'); $this->assertNull($instance->profile_updated); $this->simulateLogin('*****@*****.**'); $fb_plugin = new FacebookPlugin(); $fb_plugin->crawl(); $instance = $instance_dao->getByUsername('Gina Trapani', 'facebook'); $this->assertNotNull($instance->profile_updated); $this->assertEqual($instance->profile_updated, '2014-01-30 17:28:18'); }