]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/SearchForm/Bug43452Test.php
Release 6.4.1
[Github/sugarcrm.git] / tests / include / SearchForm / Bug43452Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 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  * SugarCRM Community Edition is a customer relationship management program developed by
40  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
41  * 
42  * This program is free software; you can redistribute it and/or modify it under
43  * the terms of the GNU Affero General Public License version 3 as published by the
44  * Free Software Foundation with the addition of the following permission added
45  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
46  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
47  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
48  * 
49  * This program is distributed in the hope that it will be useful, but WITHOUT
50  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
51  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
52  * details.
53  * 
54  * You should have received a copy of the GNU Affero General Public License along with
55  * this program; if not, see http://www.gnu.org/licenses or write to the Free
56  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
57  * 02110-1301 USA.
58  * 
59  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
60  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
61  * 
62  * The interactive user interfaces in modified source and object code versions
63  * of this program must display Appropriate Legal Notices, as required under
64  * Section 5 of the GNU Affero General Public License version 3.
65  * 
66  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
67  * these Appropriate Legal Notices must retain the display of the "Powered by
68  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
69  * technical reasons, the Appropriate Legal Notices must display the words
70  * "Powered by SugarCRM".
71  ********************************************************************************/
72
73
74 require_once "modules/Leads/Lead.php";
75 require_once "include/Popups/PopupSmarty.php";
76
77 class Bug43452Test extends Sugar_PHPUnit_Framework_TestCase
78 {
79     public function setUp()
80     {
81         $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']); 
82     }
83     
84     public function tearDown()
85     {
86         unset($GLOBALS['app_strings']);
87     }
88     
89     /**
90      * @ticket 43452
91      */
92     public function testGenerateSearchWhereWithUnsetBool()
93     {
94         // Looking for a NON Converted Lead named "Fabio".
95         // Without changes, PopupSmarty return a bad query, with AND and OR at the same level.
96         // With this fix we get parenthesis:
97         //     1) From SearchForm2->generateSearchWhere, in case of 'bool' (they surround "converted = '0' or converted IS NULL")
98         //     2) From PopupSmarty->_get_where_clause, when items of where's array are imploded.
99
100         $tGoodWhere = "( leads.first_name like 'Fabio%' and ( leads.converted = '0' OR leads.converted IS NULL ) )";
101
102         $_searchFields['Leads'] = array ('first_name'=> array('value' => 'Fabio', 'query_type'=>'default'),
103                                          'converted'=> array('value' => '0', 'query_type'=>'default'),
104                                         );
105         // provides $searchdefs['Leads']
106         require "modules/Leads/metadata/searchdefs.php";
107         
108         $bean = $this->getMock('Lead');
109         $popup = new PopupSmarty($bean, "Leads");
110         $popup->searchForm->searchdefs =  $searchdefs['Leads'];
111         $popup->searchForm->searchFields = $_searchFields['Leads'];
112         $tWhere = $popup->_get_where_clause();
113
114         $this->assertEquals($tGoodWhere, $tWhere);
115     }
116 }