3 class Bug40209Test extends Sugar_PHPUnit_Framework_TestCase
10 public function setUp()
13 $this->user = $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
16 $this->account = new Account();
17 $this->account->name = 'bug40209 account '.date('Y-m-d-H-i-s');
18 $this->account->save();
21 $this->contact = new Contact();
22 $this->lead = SugarTestLeadUtilities::createLead();
26 public function tearDown()
28 //delete records created from db
29 $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$this->account->id}'");
30 $GLOBALS['db']->query("DELETE FROM leads WHERE id= '{$this->lead->id}'");
31 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->contact->id}'");
32 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
35 unset($GLOBALS['current_user']);
37 unset($this->account);
38 unset($this->contact);
43 //run test to make sure accounts related to leads record are copied over to contact recor during conversion (bug 40209)
44 public function testConvertAccountCopied(){
45 //there will be output from display function, so call ob_start to trap it
48 //set the request parameters and convert the lead
49 $_REQUEST['module'] = 'Leads';
50 $_REQUEST['action'] = 'ConvertLead';
51 $_REQUEST['record'] = $this->lead->id;
52 $_REQUEST['handle'] = 'save';
53 $_REQUEST['selectedAccount'] = $this->account->id;
55 //require view and call display class so that convert functionality is called
56 require_once('modules/Leads/views/view.convertlead.php');
57 $vc = new ViewConvertLead();
60 //retrieve the lead again to make sure we have the latest converted lead in memory
61 $this->lead->retrieve($this->lead->id);
63 //retrieve the new contact id from the conversion
64 $contact_id = $this->lead->contact_id;
66 //throw error if contact id was not retrieved and exit test
67 $this->assertTrue(!empty($contact_id), "contact id was not created during conversion process. An error has ocurred, aborting rest of test.");
68 if (empty($contact_id)){
72 //make sure the new contact has the account related and that it matches the lead account
73 $this->contact->retrieve($contact_id);
74 $this->assertTrue($this->contact->account_id == $this->lead->account_id, "Account id from converted lead does not match the new contact account id, there was an error during conversion.");
75 $output = ob_get_clean();