]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/DynamicFields/Bug51427Test.php
Release 6.5.1
[Github/sugarcrm.git] / tests / modules / DynamicFields / Bug51427Test.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 require_once("modules/ModuleBuilder/parsers/StandardField.php");
40 require_once("modules/DynamicFields/FieldCases.php");
41
42
43 /**
44  *  Bug #51427: Setting a "name" field to calculated removes it from Global Search
45  *
46  *  StandardField class didn't have functionality for checking `unified_search`
47  *  option. `unified_search` was always `false` for non-custom fields.
48  */
49
50 class Bug51427Test extends Sugar_PHPUnit_Framework_TestCase
51 {
52     private $old_dictionary;
53     private $old_bean_list;
54     private $bean_name;
55     private $test_field;
56     private $test_standart_field;
57
58     public function setUp()
59     {
60         global $dictionary, $bean_list;
61
62         $this->old_dictionary=$dictionary;
63         $this->old_bean_list=$bean_list;
64         $this->test_standart_field = new TestStandardField();
65         $this->test_standart_field->module='Accounts';
66         loadBean($this->test_standart_field->module);
67         $this->test_field=get_widget('varchar');
68         $this->test_field->name='name';
69         $this->bean_name = get_valid_bean_name($this->test_standart_field->module);
70     }
71
72     public function tearDown()
73     {
74         global $dictionary, $bean_list;
75
76         $dictionary=$this->old_dictionary;
77         $bean_list=$this->old_bean_list;
78         VardefManager::clearVardef('Accounts', 'Account');
79         VardefManager::refreshVardefs('Accounts', 'Account');
80     }
81
82     /**
83      * Test different combinations of the options
84      *
85      * @dataProvider providerUnifiedSearchOptions
86      */
87     public function testIfUnifiedSearchEnabledByDefault(array $opt_common, array $opt_field, $assert)
88     {
89         $this->test_field->unified_search=false;
90         $this->setOptions($opt_common, $opt_field);
91         $this->test_standart_field->addFieldObject($this->test_field);
92         $this->assertEquals($assert,(boolean)$this->test_field->unified_search,
93                 "\r\n"
94                 .'Assertion error: field->unified_search should be `'.($assert ? 'true' : 'false').'` with the following vardef options:'
95
96                 ."\r\nvardef[<module>][unified_search_default_enabled] "
97                     .($opt_common['unified_search_default_enabled']===-1 ? 'is undefined' : ($opt_common['unified_search_default_enabled'] ? '= true' : '= false'))
98
99                 ."\r\nvardef[<module>][unified_search] "
100                     .($opt_common['unified_search']===-1 ? 'is undefined' : ($opt_common['unified_search'] ? '= true' : '= false'))
101
102                 ."\r\nvardef[<module>][fields][<field_name>][unified_search] "
103                     .($opt_field['unified_search']===-1 ? 'is undefined' : ($opt_field['unified_search'] ? '= true' : '= false'))
104                 ."\r\n"
105         );
106     }
107
108     public function providerUnifiedSearchOptions()
109     {
110         return array(
111             array(
112                 'options_common'=>array(
113                     'unified_search_default_enabled'=>1,
114                     'unified_search'=>1,
115                 ),
116                 'options_field'=>array(
117                     'unified_search'=>1,
118                 ),
119                 'assert'=>true,
120             ),
121             array(
122                 'options_common'=>array(
123                     'unified_search_default_enabled'=>0,
124                     'unified_search'=>1,
125                 ),
126                 'options_field'=>array(
127                     'unified_search'=>1,
128                 ),
129                 'assert'=>false,
130             ),
131             array(
132                 'options_common'=>array(
133                     'unified_search_default_enabled'=>0,
134                     'unified_search'=>0,
135                 ),
136                 'options_field'=>array(
137                     'unified_search'=>1,
138                 ),
139                 'assert'=>false,
140             ),
141             array(
142                 'options_common'=>array(
143                     'unified_search_default_enabled'=>0,
144                     'unified_search'=>0,
145                 ),
146                 'options_field'=>array(
147                     'unified_search'=>0,
148                 ),
149                 'assert'=>false,
150             ),
151             array(
152                 'options_common'=>array(
153                     'unified_search_default_enabled'=>0,
154                     'unified_search'=>1,
155                 ),
156                 'options_field'=>array(
157                     'unified_search'=>0,
158                 ),
159                 'assert'=>false,
160             ),
161             array(
162                 'options_common'=>array(
163                     'unified_search_default_enabled'=>0,
164                     'unified_search'=>0,
165                 ),
166                 'options_field'=>array(
167                     'unified_search'=>1,
168                 ),
169                 'assert'=>false,
170             ),
171             array(
172                 'options_common'=>array(
173                     'unified_search_default_enabled'=>1,
174                     'unified_search'=>1,
175                 ),
176                 'options_field'=>array(
177                      'unified_search'=>-1,
178                 ),
179                 'assert'=>true,
180             ),
181             array(
182                 'options_common'=>array(
183                     'unified_search_default_enabled'=>1,
184                     'unified_search'=>-1,
185                 ),
186                 'options_field'=>array(
187                     'unified_search'=>1,
188                 ),
189                 'assert'=>false,
190             ),
191             array(
192                 'options_common'=>array(
193                     'unified_search_default_enabled'=>-1,
194                     'unified_search'=>1,
195                 ),
196                 'options_field'=>array(
197                     'unified_search'=>1,
198                 ),
199                 'assert'=>false,
200             ),
201         );
202     }
203
204     private function setOptions(array $opt_common, array $opt_field)
205     {
206         global $dictionary;
207         $dictionary=$this->old_dictionary;
208         if(!empty($opt_common))
209         {
210             foreach($opt_common as $k=>$v)
211             {
212                 if($v===-1)
213                 {
214                     unset($dictionary[$this->bean_name][$k]);
215                 }
216                 else
217                 {
218                     $dictionary[$this->bean_name][$k]=$v;
219                 }
220             }
221         }
222         if(!empty($opt_field))
223         {
224             foreach($opt_field as $k=>$v)
225             {
226                 if($v===-1)
227                 {
228                     unset($dictionary[$this->bean_name]['fields'][$this->test_field->name][$k]);
229                 }
230                 else
231                 {
232                     $dictionary[$this->bean_name]['fields'][$this->test_field->name][$k]=$v;
233                 }
234             }
235         }
236     }
237 }
238
239
240 /*
241  * inherits StandardField
242  * some methods aren't used in the test
243  */
244 class TestStandardField extends StandardField
245 {
246     function writeVardefExtension()
247     {
248     }
249
250     function loadCustomDef()
251     {
252         $this->custom_def=array();
253     }
254 }