public function testBadQuery() { $lead = SugarTestLeadUtilities::createLead(); $this->_login(); $result = $this->_soapClient->call('get_entry_list', array('session' => $this->_sessionId, "module_name" => 'Leads', "query" => "leads.id = '{$lead->id}'", 'order_by' => '', 'offset' => 0, 'select_fields' => array('name'), 'link_name_to_fields_array' => array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address'))), 'max_results' => 1, 'deleted' => 0)); $this->assertEquals('primary_address', $result['relationship_list'][0][0]['records'][0][3]['name']); }
/** * Create a lead and convert it to an existing Account and Contact */ public function testConvertLinkingExistingContact() { // Create records $lead = SugarTestLeadUtilities::createLead(); $account = SugarTestAccountUtilities::createAccount(); $contact = SugarTestContactUtilities::createContact(); // ConvertLead to an existing Contact and Account $_REQUEST = array('module' => 'Leads', 'record' => $lead->id, 'isDuplicate' => 'false', 'action' => 'ConvertLead', 'convert_create_Contacts' => 'false', 'report_to_name' => $contact->name, 'reports_to_id' => $contact->id, 'convert_create_Accounts' => 'false', 'account_name' => $account->name, 'account_id' => $account->id, 'handle' => 'save'); // Call display to trigger conversion $vc = new ViewConvertLead(); $vc->display(); // Refresh Lead $leadId = $lead->id; $lead = new Lead(); $lead->retrieve($leadId); // Refresh Contact $contactId = $contact->id; $contact = new Contact(); $contact->retrieve($contactId); // Check if contact it's linked properly $this->assertEquals($contact->id, $lead->contact_id, 'Contact not linked with Lead successfully.'); // Check if account is linked with lead properly $this->assertEquals($account->id, $lead->account_id, 'Account not linked with Lead successfully.'); // Check if account is linked with contact properly $this->assertEquals($account->id, $contact->account_id, 'Account not linked with Contact successfully.'); // Check Lead Status, should be converted $this->assertEquals('Converted', $lead->status, "Lead status should be 'Converted'."); }
public function testBadQuery() { $lead = SugarTestLeadUtilities::createLead(); $this->_login(); $result = $this->_soapClient->call('get_entry_list', array('session' => $this->_sessionId, "module_name" => 'Leads', "query" => "leads.id = '{$lead->id}'", '', 0, array(), array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address'))))); $this->assertEquals('primary_address', $result['relationship_list'][0][0]['records'][0][3]['name']); }
/** * @group bug45187 */ public function testActivityModuleLabel() { global $sugar_config; global $app_list_strings; // init $lead = SugarTestLeadUtilities::createLead(); $account = SugarTestAccountUtilities::createAccount(); // simulate module renaming $org_name = $app_list_strings['moduleListSingular']['Contacts']; $app_list_strings['moduleListSingular']['Contacts'] = 'People'; // set the request/post parameters before converting the lead $_REQUEST['module'] = 'Leads'; $_REQUEST['action'] = 'ConvertLead'; $_REQUEST['record'] = $lead->id; unset($_REQUEST['handle']); $_REQUEST['selectedAccount'] = $account->id; $sugar_config['lead_conv_activity_opt'] = 'move'; // call display to trigger conversion $vc = new ViewConvertLead(); $vc->init($lead); $vc->display(); // the activity options dropdown should use the renamed module label $this->expectOutputRegex('/.*People<\\/OPTION>.*/'); // cleanup $app_list_strings['moduleListSingular']['Contacts'] = $org_name; unset($_REQUEST['module']); unset($_REQUEST['action']); unset($_REQUEST['record']); unset($_REQUEST['selectedAccount']); SugarTestAccountUtilities::removeAllCreatedAccounts(); SugarTestLeadUtilities::removeAllCreatedLeads(); }
public function setUp() { SugarTestHelper::setUp('beanFiles'); SugarTestHelper::setUp('beanList'); SugarTestHelper::setUp('current_user'); $this->Accounts = SugarTestAccountUtilities::createAccount(); $this->Contacts = SugarTestContactUtilities::createContact(); $this->Leads = SugarTestLeadUtilities::createLead(); }
public function setUp() { //create user $this->user = $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser(); //create account $this->account = new Account(); $this->account->name = 'bug40209 account ' . date('Y-m-d-H-i-s'); $this->account->save(); //create contact $this->contact = new Contact(); $this->lead = SugarTestLeadUtilities::createLead(); }
public function setup() { $GLOBALS['db']->query("DELETE FROM leads WHERE first_name = 'Mike' AND last_name = 'TheSituationSorrentino'"); $this->form = new LeadFormBase(); $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser(); $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']); $GLOBALS['mod_strings'] = return_module_language($GLOBALS['current_language'], 'Leads'); //Create a test Lead $this->lead1 = SugarTestLeadUtilities::createLead(); $this->lead1->first_name = 'Collin'; $this->lead1->last_name = 'Lee'; $this->lead1->save(); $this->lead1->emailAddress->addAddress('*****@*****.**', true, false); $this->lead1->emailAddress->save($this->lead1->id, $this->lead1->module_dir); }
public function setUp() { global $_POST; $_POST = array(); $reloadVardefs = isset($GLOBALS['reload_vardefs']) ? $GLOBALS['reload_vardefs'] : false; $GLOBALS['reload_vardefs'] = true; //create user $this->user = $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser(); //create account $this->account = new Account(); $this->account->name = 'bug40209 account ' . date('Y-m-d-H-i-s'); $this->account->save(); //create contact $this->contact = new Contact(); $this->lead = SugarTestLeadUtilities::createLead(); $GLOBALS['reload_vardefs'] = $reloadVardefs; }
/** * setUp * Override the setup from SoapTestCase to also create the seed search data for Accounts and Contacts. */ public function setUp() { $this->_soapURL = $GLOBALS['sugar_config']['site_url'] . '/soap.php'; parent::setUp(); $this->_login(); // Logging in just before the SOAP call as this will also commit any pending DB changes $this->contact = SugarTestContactUtilities::createContact(); $this->contact->contacts_users_id = $GLOBALS['current_user']->id; $this->contact->save(); $this->account = SugarTestAccountUtilities::createAccount(); $this->account->email1 = $this->contact->email1; $this->account->save(); $this->lead = SugarTestLeadUtilities::createLead(); $this->lead->email1 = $this->contact->email1; $this->lead->save(); $GLOBALS['db']->commit(); // Making sure these changes are committed to the database }
/** * @group bug39787 */ public function testOpportunityNameValueFilled() { $lead = SugarTestLeadUtilities::createLead(); $lead->opportunity_name = 'SBizzle Dollar Store'; $lead->save(); $_REQUEST['module'] = 'Leads'; $_REQUEST['action'] = 'ConvertLead'; $_REQUEST['record'] = $lead->id; // Check that the opportunity name doesn't get populated when it's not in the Leads editview layout require_once 'include/MVC/Controller/ControllerFactory.php'; require_once 'include/MVC/View/ViewFactory.php'; $GLOBALS['app']->controller = ControllerFactory::getController($_REQUEST['module']); ob_start(); $GLOBALS['app']->controller->execute(); $output = ob_get_clean(); $matches_one = array(); $pattern = '/SBizzle Dollar Store/'; preg_match($pattern, $output, $matches_one); $this->assertTrue(count($matches_one) == 0, "Opportunity name got carried over to the Convert Leads page when it shouldn't have."); // Add the opportunity_name to the Leads EditView SugarTestStudioUtilities::addFieldToLayout('Leads', 'editview', 'opportunity_name'); // Check that the opportunity name now DOES get populated now that it's in the Leads editview layout ob_start(); $GLOBALS['app']->controller = ControllerFactory::getController($_REQUEST['module']); $GLOBALS['app']->controller->execute(); $output = ob_get_clean(); $matches_two = array(); $pattern = '/SBizzle Dollar Store/'; preg_match($pattern, $output, $matches_two); $this->assertTrue(count($matches_two) > 0, "Opportunity name did not carry over to the Convert Leads page when it should have."); SugarTestStudioUtilities::removeAllCreatedFields(); unset($GLOBALS['app']->controller); unset($_REQUEST['module']); unset($_REQUEST['action']); unset($_REQUEST['record']); SugarTestLeadUtilities::removeAllCreatedLeads(); }
public function setUp() { $this->markTestIncomplete('Marking this skipped until we figure out why it is causing the SQL server connection to go away.'); $this->clear_database = true; $this->remove_beans = true; $this->saved_current_user = $GLOBALS['current_user']; $user = new User(); $user->retrieve('1'); $GLOBALS['current_user'] = $user; $this->campaign = new Campaign(); $this->campaign->name = 'Bug39665Test ' . time(); $this->campaign->campaign_type = 'Email'; $this->campaign->status = 'Active'; $timeDate = new TimeDate(); $this->campaign->end_date = $timeDate->to_display_date(date('Y') + 1 . '-01-01'); $this->campaign->assigned_id = $user->id; $this->campaign->team_id = '1'; $this->campaign->team_set_id = '1'; $this->campaign->save(); $this->emailmarketing = new EmailMarketing(); $this->emailmarketing->name = $this->campaign->name . ' Email1'; $this->emailmarketing->campaign_id = $this->campaign->id; $this->emailmarketing->from_name = 'SugarCRM'; $this->emailmarketing->from_addr = '*****@*****.**'; $this->emailmarketing->reply_to_name = 'SugarCRM'; $this->emailmarketing->reply_to_addr = '*****@*****.**'; $this->emailmarketing->status = 'active'; $this->emailmarketing->all_prospect_lists = 1; $this->emailmarketing->date_start = $timeDate->to_display_date(date('Y') + 1 . '-01-01') . ' 00:00:00'; $this->emailmarketing2 = new EmailMarketing(); $this->emailmarketing2->name = $this->campaign->name . ' Email2'; $this->emailmarketing2->campaign_id = $this->campaign->id; $this->emailmarketing2->from_name = 'SugarCRM'; $this->emailmarketing2->from_addr = '*****@*****.**'; $this->emailmarketing2->reply_to_name = 'SugarCRM'; $this->emailmarketing2->reply_to_addr = '*****@*****.**'; $this->emailmarketing2->status = 'active'; $this->emailmarketing2->all_prospect_lists = 1; $this->emailmarketing2->date_start = $timeDate->to_display_date(date('Y') + 1 . '-01-01') . ' 00:00:00'; $query = 'SELECT id FROM inbound_email WHERE deleted=0'; $result = $GLOBALS['db']->query($query); while ($row = $GLOBALS['db']->fetchByAssoc($result)) { $this->emailmarketing->inbound_email_id = $row['id']; $this->emailmarketing2->inbound_email_id = $row['id']; break; } $query = 'SELECT id FROM email_templates WHERE deleted=0'; while ($row = $GLOBALS['db']->fetchByAssoc($result)) { $this->emailmarketing->template_id = $row['id']; $this->emailmarketing2->template_id = $row['id']; break; } $this->emailmarketing->save(); $this->emailmarketing2->save(); $this->campaign->load_relationship('prospectlists'); $this->prospectlist = new ProspectList(); $this->prospectlist->name = $this->campaign->name . ' Prospect List1'; $this->prospectlist->assigned_user_id = $GLOBALS['current_user']->id; $this->prospectlist->list_type = "default"; $this->prospectlist->save(); $this->campaign->prospectlists->add($this->prospectlist->id); $this->campaign->load_relationship('prospectlists'); $this->prospectlist2 = new ProspectList(); $this->prospectlist2->name = $this->campaign->name . ' Prospect List2'; $this->prospectlist2->assigned_user_id = $GLOBALS['current_user']->id; $this->prospectlist2->list_type = "default"; $this->prospectlist2->save(); $this->campaign->prospectlists->add($this->prospectlist2->id); $campaign_log_states = array(0 => 'viewed', 1 => 'link', 2 => 'invalid email', 3 => 'send error', 4 => 'removed', 5 => 'blocked', 6 => 'lead', 7 => 'contact'); for ($i = 0; $i < 10; $i++) { $contact = SugarTestContactUtilities::createContact(); $contact->campaign_id = $this->campaign->id; $contact->email2 = 'contact' . mt_rand() . '@sugar.com'; //Simulate a secondary email $contact->save(); $contact->load_relationship('prospect_lists'); $contact->prospect_lists->add($this->prospectlist->id); $contact->prospect_lists->add($this->prospectlist2->id); $this->create_campaign_log($this->campaign, $contact, $this->emailmarketing, $this->prospectlist, 'targeted'); $this->create_campaign_log($this->campaign, $contact, $this->emailmarketing, $this->prospectlist, $campaign_log_states[mt_rand(0, 7)]); $this->create_campaign_log($this->campaign, $contact, $this->emailmarketing2, $this->prospectlist, 'targeted'); $this->create_campaign_log($this->campaign, $contact, $this->emailmarketing2, $this->prospectlist, $campaign_log_states[mt_rand(0, 7)]); } for ($i = 0; $i < 10; $i++) { $lead = SugarTestLeadUtilities::createLead(); $lead->campaign_id = $this->campaign->id; $lead->email2 = 'lead2' . mt_rand() . '@sugar.com'; //Simulate a secondary email $lead->save(); $lead->load_relationship('prospect_lists'); $lead->prospect_lists->add($this->prospectlist->id); $lead->prospect_lists->add($this->prospectlist2->id); $this->create_campaign_log($this->campaign, $lead, $this->emailmarketing, $this->prospectlist, 'targeted'); $this->create_campaign_log($this->campaign, $lead, $this->emailmarketing, $this->prospectlist, $campaign_log_states[mt_rand(0, 7)]); $this->create_campaign_log($this->campaign, $lead, $this->emailmarketing2, $this->prospectlist, 'targeted'); $this->create_campaign_log($this->campaign, $lead, $this->emailmarketing2, $this->prospectlist, $campaign_log_states[mt_rand(0, 7)]); } //But wait, there's more... now we email the friggin thing to place it in the queue if ($this->campaign->db->dbType == 'oci8') { } else { $current_date = "'" . gmdate($GLOBALS['timedate']->get_db_date_time_format()) . "'"; } //start scheduling now..... $emailmarketing_beans = array($this->emailmarketing, $this->emailmarketing2); foreach ($emailmarketing_beans as $marketing) { $mergedvalue = $GLOBALS['timedate']->merge_date_time($marketing->date_start, $marketing->time_start); if ($this->campaign->db->dbType == 'oci8') { } else { $send_date_time = "'" . $GLOBALS['timedate']->to_db_date($mergedvalue) . ' ' . $GLOBALS['timedate']->to_db_time($mergedvalue) . "'"; } //find all prospect lists associated with this email marketing message. if ($marketing->all_prospect_lists == 1) { $query = "SELECT prospect_lists.id prospect_list_id from prospect_lists "; $query .= " INNER JOIN prospect_list_campaigns plc ON plc.prospect_list_id = prospect_lists.id"; $query .= " WHERE plc.campaign_id='{$this->campaign->id}'"; $query .= " AND prospect_lists.deleted=0"; $query .= " AND plc.deleted=0"; $query .= " AND prospect_lists.list_type!='test' AND prospect_lists.list_type not like 'exempt%'"; } else { $query = "select email_marketing_prospect_lists.* FROM email_marketing_prospect_lists "; $query .= " inner join prospect_lists on prospect_lists.id = email_marketing_prospect_lists.prospect_list_id"; $query .= " WHERE prospect_lists.deleted=0 and email_marketing_id = '{$marketing->id}' and email_marketing_prospect_lists.deleted=0"; $query .= " AND prospect_lists.list_type!='test' AND prospect_lists.list_type not like 'exempt%'"; } $result = $this->campaign->db->query($query); while (($row = $this->campaign->db->fetchByAssoc($result)) != null) { $prospect_list_id = $row['prospect_list_id']; //delete all messages for the current campaign and current email marketing message. $delete_emailman_query = "delete from emailman where campaign_id='{$this->campaign->id}' and marketing_id='{$marketing->id}' and list_id='{$prospect_list_id}'"; $this->campaign->db->query($delete_emailman_query); $insert_query = "INSERT INTO emailman (date_entered, user_id, campaign_id, marketing_id,list_id, related_id, related_type, send_date_time"; if ($this->campaign->db->dbType == 'oci8') { } $insert_query .= ')'; $insert_query .= " SELECT {$current_date},'{$GLOBALS['current_user']->id}',plc.campaign_id,'{$marketing->id}',plp.prospect_list_id, plp.related_id, plp.related_type,{$send_date_time} "; if ($this->campaign->db->dbType == 'oci8') { } $insert_query .= "FROM prospect_lists_prospects plp "; $insert_query .= "INNER JOIN prospect_list_campaigns plc ON plc.prospect_list_id = plp.prospect_list_id "; $insert_query .= "WHERE plp.prospect_list_id = '{$prospect_list_id}' "; $insert_query .= "AND plp.deleted=0 "; $insert_query .= "AND plc.deleted=0 "; $insert_query .= "AND plc.campaign_id='{$this->campaign->id}'"; if ($this->campaign->db->dbType == 'oci8') { } $this->campaign->db->query($insert_query); } } }
public function testConversionAndDoNothing() { global $sugar_config; // init $lead = SugarTestLeadUtilities::createLead(); $account = SugarTestAccountUtilities::createAccount(); $meeting = SugarTestMeetingUtilities::createMeeting(); SugarTestMeetingUtilities::addMeetingParent($meeting->id, $lead->id); $relation_id = SugarTestMeetingUtilities::addMeetingLeadRelation($meeting->id, $lead->id); $_REQUEST['record'] = $lead->id; // set the request/post parameters before converting the lead $_REQUEST['module'] = 'Leads'; $_REQUEST['action'] = 'ConvertLead'; $_REQUEST['record'] = $lead->id; $_REQUEST['handle'] = 'save'; $_REQUEST['selectedAccount'] = $account->id; $sugar_config['lead_conv_activity_opt'] = 'none'; // call display to trigger conversion $vc = new ViewConvertLead(); $vc->display(); // refresh meeting $meeting_id = $meeting->id; $meeting = new Meeting(); $meeting->retrieve($meeting_id); // refresh lead $lead_id = $lead->id; $lead = new Lead(); $lead->retrieve($lead_id); // retrieve the new contact id from the conversion $contact_id = $lead->contact_id; // 1. Lead's contact_id should not be null $this->assertNotNull($contact_id, 'Lead has null contact id after conversion.'); // 2. Lead status should be 'Converted' $this->assertEquals('Converted', $lead->status, "Lead atatus should be 'Converted'."); // 3. parent_type of the original meeting should be Leads $this->assertEquals('Leads', $meeting->parent_type, 'Meeting parent should be Leads'); // 4. parent_id of the original meeting should be contact id $this->assertEquals($lead_id, $meeting->parent_id, 'Meeting parent id should be lead id.'); // 5. record should NOT be deleted from meetings_leads table $sql = "select id from meetings_leads where meeting_id='{$meeting->id}' and lead_id='{$lead->id}' and deleted=0"; $result = $GLOBALS['db']->query($sql); $row = $GLOBALS['db']->fetchByAssoc($result); $this->assertFalse(empty($row), "Meeting-Lead relationship is removed."); // 6. record should NOT be added to meetings_contacts table $sql = "select meeting_id from meetings_contacts where contact_id='{$contact_id}' and deleted=0"; $result = $GLOBALS['db']->query($sql); $row = $GLOBALS['db']->fetchByAssoc($result); $this->assertFalse($row, "Meeting-Contact relationship should not be added."); // clean up unset($_REQUEST['record']); $GLOBALS['db']->query("delete from meetings where parent_id='{$lead->id}' and parent_type= 'Leads'"); $GLOBALS['db']->query("delete from meetings where parent_id='{$contact_id}' and parent_type= 'Contacts'"); $GLOBALS['db']->query("delete from contacts where id='{$contact_id}'"); $GLOBALS['db']->query("delete from meetings_leads where meeting_id='{$meeting->id}' and lead_id= '{$lead_id}'"); $GLOBALS['db']->query("delete from meetings_contacts where contact_id= '{$contact_id}'"); SugarTestMeetingUtilities::deleteMeetingLeadRelation($relation_id); SugarTestMeetingUtilities::removeMeetingContacts(); SugarTestMeetingUtilities::removeAllCreatedMeetings(); SugarTestAccountUtilities::removeAllCreatedAccounts(); SugarTestLeadUtilities::removeAllCreatedLeads(); }
public function testMissingFields() { $bean = $this->getMock('Call', array('get_importable_fields', 'populateDefaultValues', 'beforeImportSave', 'save', 'afterImportSave', 'writeRowToLastImport')); $bean->expects($this->any())->method('get_importable_fields')->will($this->returnValue(array('account_id' => 'accounts', 'opportunity_id' => 'opportunities', 'contact_id' => 'contacts', 'case_id' => 'cases', 'user_id' => 'users', 'assigned_user_id' => 'users', 'note_id' => 'notes', 'lead_id' => 'leads'))); $bean->expects($this->any())->method('populateDefaultValues')->will($this->returnValue('foo')); $bean->expects($this->any())->method('beforeImportSave')->will($this->returnValue('foo')); $bean->expects($this->any())->method('save')->will($this->returnValue('foo')); $bean->expects($this->any())->method('afterImportSave')->will($this->returnValue('foo')); $bean->expects($this->any())->method('writeRowToLastImport')->will($this->returnValue('foo')); $bean->date_modified = 'true'; $bean->fetched_row = array('date_modified' => ''); $bean->object_name = ''; $lead = SugarTestLeadUtilities::createLead(); $a = new bug46411_Importer_mock($this->importSource, $bean); // $b = new Call(); $bean->parent_type = 'leads'; $bean->parent_id = $lead->id; // $bean->relationship_fields = $b->relationship_fields; $a->saveImportBean($bean, false); $this->assertEquals($bean->parent_id, $bean->lead_id); }
/** * @group bug44831 */ public function testJSInjection() { $this->markTestIncomplete('Marked as skipped for now... too problematic'); return; require_once 'include/utils/layout_utils.php'; $_SERVER['REQUEST_METHOD'] = "POST"; $lead = SugarTestLeadUtilities::createLead(); $lead->name = 'LeadName'; $lead->save(); $_REQUEST['module'] = 'Leads'; $_REQUEST['action'] = 'EditView'; $_REQUEST['record'] = $lead->id; require_once 'include/MVC/Controller/ControllerFactory.php'; require_once 'include/MVC/View/ViewFactory.php'; $GLOBALS['app']->controller = ControllerFactory::getController($_REQUEST['module']); //ob_start(); $GLOBALS['app']->controller->execute(); //$tStr = ob_get_clean(); // First of all, need to be sure that I'm actually dealing with my new custom DetailView Layout $this->expectOutputRegex('/.*HiddenPlaceHolder.*/'); // Then check inclusion of LeadJS1.js $this->expectOutputRegex('/.*<script src=\\"custom\\/modules\\/Leads\\/javascript\\/LeadJS1\\.js.*\\"><\\/script>.*/'); // Then check inclusion of LeadJS2.js $this->expectOutputRegex('/.*<script src=\\"custom\\/modules\\/Leads\\/javascript\\/LeadJS2\\.js.*\\"><\\/script>.*/'); //unset($GLOBALS['app']->controller); unset($_REQUEST['module']); unset($_REQUEST['action']); unset($_REQUEST['record']); SugarTestLeadUtilities::removeAllCreatedLeads(); }