]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Leads/ConvertLeadTests.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / Leads / ConvertLeadTests.php
1 <?php
2
3 class ConvertLeadTests extends Sugar_PHPUnit_Framework_TestCase
4 {
5     public function setUp()
6     {
7         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
8         $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
9     }
10     
11     public function tearDown()
12     {
13         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
14         unset($GLOBALS['app_list_strings']);
15         unset($GLOBALS['current_user']);
16     }
17     
18         /**
19          * @group bug39787
20          */
21     public function testOpportunityNameValueFilled(){
22         $lead = SugarTestLeadUtilities::createLead();
23         $lead->opportunity_name = 'SBizzle Dollar Store';
24         $lead->save();
25         
26         $_REQUEST['module'] = 'Leads';
27         $_REQUEST['action'] = 'ConvertLead';
28         $_REQUEST['record'] = $lead->id;
29         
30         // Check that the opportunity name doesn't get populated when it's not in the Leads editview layout
31         require_once('include/MVC/Controller/ControllerFactory.php');
32         require_once('include/MVC/View/ViewFactory.php');
33         $GLOBALS['app']->controller = ControllerFactory::getController($_REQUEST['module']);
34         ob_start();
35         $GLOBALS['app']->controller->execute();
36         $output = ob_get_clean();
37         
38         $matches_one = array();
39         $pattern = '/SBizzle Dollar Store/';
40         preg_match($pattern, $output, $matches_one);
41         $this->assertTrue(count($matches_one) == 0, "Opportunity name got carried over to the Convert Leads page when it shouldn't have.");
42
43         // Add the opportunity_name to the Leads EditView
44         SugarTestStudioUtilities::addFieldToLayout('Leads', 'editview', 'opportunity_name');
45         
46         // Check that the opportunity name now DOES get populated now that it's in the Leads editview layout
47         ob_start();
48         $GLOBALS['app']->controller = ControllerFactory::getController($_REQUEST['module']);
49         $GLOBALS['app']->controller->execute();
50         $output = ob_get_clean();
51         $matches_two = array();
52         $pattern = '/SBizzle Dollar Store/';
53         preg_match($pattern, $output, $matches_two);
54         $this->assertTrue(count($matches_two) > 0, "Opportunity name did not carry over to the Convert Leads page when it should have.");
55         
56         SugarTestStudioUtilities::removeAllCreatedFields();
57         unset($GLOBALS['app']->controller);
58         unset($_REQUEST['module']);
59         unset($_REQUEST['action']);
60         unset($_REQUEST['record']);
61         SugarTestLeadUtilities::removeAllCreatedLeads();
62     }
63 }