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