]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/SugarObjects/forms/LeadFormBaseTest.php
Release 6.4.0
[Github/sugarcrm.git] / tests / include / SugarObjects / forms / LeadFormBaseTest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37
38 /**
39  * LeadFormBaseTest.php
40  *
41  */
42
43 require_once('modules/Leads/LeadFormBase.php');
44
45 class LeadFormBaseTest extends Sugar_PHPUnit_Framework_TestCase {
46
47 var $form;
48 var $lead1;
49
50 public function setup()
51 {
52     $GLOBALS['db']->query("DELETE FROM leads WHERE first_name = 'Mike' AND last_name = 'TheSituationSorrentino'");
53     $this->form = new LeadFormBase();
54     $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
55     $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
56     $GLOBALS['mod_strings'] = return_module_language($GLOBALS['current_language'], 'Leads');
57
58     //Create a test Lead
59     $this->lead1 = SugarTestLeadUtilities::createLead();
60     $this->lead1->first_name = 'Collin';
61     $this->lead1->last_name = 'Lee';
62     $this->lead1->save();
63     $this->lead1->emailAddress->addAddress('clee@sugarcrm.com', true, false);
64     $this->lead1->emailAddress->save($this->lead1->id, $this->lead1->module_dir);
65 }
66
67 public function tearDown()
68 {
69     SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
70     SugarTestLeadUtilities::removeAllCreatedLeads();
71     SugarTestLeadUtilities::removeCreatedLeadsEmailAddresses();
72     unset($this->form);
73     unset($this->lead1);
74 }
75
76
77 /**
78  * leadsProvider
79  *
80  */
81 public function leadsProvider()
82 {
83     return array(
84         array('Collin', 'Lee', true),
85         array('', 'Lee', true),
86         array('Mike', 'TheSituationSorrentino', false)
87     );
88     
89 }
90
91
92 /**
93  * testCreatingDuplicateLead
94  *
95  * @dataProvider leadsProvider
96  */
97 public function testCreatingDuplicateLead($first_name, $last_name, $hasDuplicate)
98 {
99     $_POST['first_name'] = $first_name;
100     $_POST['last_name'] = $last_name;
101     $_POST['Leads0emailAddresss0'] = 'clee@sugarcrm.com';
102
103     $rows = $this->form->checkForDuplicates();
104
105     if($hasDuplicate)
106     {
107         $this->assertTrue(count($rows) > 0, 'Assert that checkForDuplicates returned matches');
108         $this->assertEquals($rows[0]['last_name'], $last_name, 'Assert duplicate row entry last_name is ' . $last_name);
109         $output = $this->form->buildTableForm($rows);
110         $this->assertRegExp('/\&action\=DetailView\&record/', $output, 'Assert we have the DetailView links to records');
111     } else {
112         $this->assertTrue(empty($rows), 'Assert that checkForDuplicates returned no matches');
113     }
114 }
115
116 }