]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Leads/Bug40209Test.php
Release 6.1.5
[Github/sugarcrm.git] / tests / modules / Leads / Bug40209Test.php
1 <?php
2
3 class Bug40209Test extends Sugar_PHPUnit_Framework_TestCase
4 {
5     var $user;
6     var $account;
7     var $lead;
8     var $contact;
9
10     public function setUp()
11     {
12         //create user
13         $this->user = $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
14
15         //create account
16         $this->account = new Account();
17         $this->account->name = 'bug40209 account '.date('Y-m-d-H-i-s');
18         $this->account->save();
19
20         //create contact
21         $this->contact = new Contact();
22         $this->lead = SugarTestLeadUtilities::createLead();
23
24     }
25     
26     public function tearDown()
27     {
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();
33
34         //unset values
35         unset($GLOBALS['current_user']);
36         unset($this->user);
37         unset($this->account);
38         unset($this->contact);
39     }
40     
41
42
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
46         ob_start();
47
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;
54
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();
58         $vc->display();
59
60         //retrieve the lead again to make sure we have the latest converted lead in memory
61         $this->lead->retrieve($this->lead->id);
62
63         //retrieve the new contact id from the conversion
64         $contact_id = $this->lead->contact_id;
65
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)){
69             return;
70         }
71
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();
76     }
77 }