2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 require_once("modules/ModuleBuilder/parsers/StandardField.php");
40 require_once("modules/DynamicFields/FieldCases.php");
44 * Bug #51427: Setting a "name" field to calculated removes it from Global Search
46 * StandardField class didn't have functionality for checking `unified_search`
47 * option. `unified_search` was always `false` for non-custom fields.
50 class Bug51427Test extends Sugar_PHPUnit_Framework_TestCase
52 private $old_dictionary;
53 private $old_bean_list;
56 private $test_standart_field;
58 public function setUp()
60 global $dictionary, $bean_list;
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);
72 public function tearDown()
74 global $dictionary, $bean_list;
76 $dictionary=$this->old_dictionary;
77 $bean_list=$this->old_bean_list;
78 VardefManager::clearVardef('Accounts', 'Account');
79 VardefManager::refreshVardefs('Accounts', 'Account');
83 * Test different combinations of the options
85 * @dataProvider providerUnifiedSearchOptions
87 public function testIfUnifiedSearchEnabledByDefault(array $opt_common, array $opt_field, $assert)
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,
94 .'Assertion error: field->unified_search should be `'.($assert ? 'true' : 'false').'` with the following vardef options:'
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'))
99 ."\r\nvardef[<module>][unified_search] "
100 .($opt_common['unified_search']===-1 ? 'is undefined' : ($opt_common['unified_search'] ? '= true' : '= false'))
102 ."\r\nvardef[<module>][fields][<field_name>][unified_search] "
103 .($opt_field['unified_search']===-1 ? 'is undefined' : ($opt_field['unified_search'] ? '= true' : '= false'))
108 public function providerUnifiedSearchOptions()
112 'options_common'=>array(
113 'unified_search_default_enabled'=>1,
116 'options_field'=>array(
122 'options_common'=>array(
123 'unified_search_default_enabled'=>0,
126 'options_field'=>array(
132 'options_common'=>array(
133 'unified_search_default_enabled'=>0,
136 'options_field'=>array(
142 'options_common'=>array(
143 'unified_search_default_enabled'=>0,
146 'options_field'=>array(
152 'options_common'=>array(
153 'unified_search_default_enabled'=>0,
156 'options_field'=>array(
162 'options_common'=>array(
163 'unified_search_default_enabled'=>0,
166 'options_field'=>array(
172 'options_common'=>array(
173 'unified_search_default_enabled'=>1,
176 'options_field'=>array(
177 'unified_search'=>-1,
182 'options_common'=>array(
183 'unified_search_default_enabled'=>1,
184 'unified_search'=>-1,
186 'options_field'=>array(
192 'options_common'=>array(
193 'unified_search_default_enabled'=>-1,
196 'options_field'=>array(
204 private function setOptions(array $opt_common, array $opt_field)
207 $dictionary=$this->old_dictionary;
208 if(!empty($opt_common))
210 foreach($opt_common as $k=>$v)
214 unset($dictionary[$this->bean_name][$k]);
218 $dictionary[$this->bean_name][$k]=$v;
222 if(!empty($opt_field))
224 foreach($opt_field as $k=>$v)
228 unset($dictionary[$this->bean_name]['fields'][$this->test_field->name][$k]);
232 $dictionary[$this->bean_name]['fields'][$this->test_field->name][$k]=$v;
241 * inherits StandardField
242 * some methods aren't used in the test
244 class TestStandardField extends StandardField
246 function writeVardefExtension()
250 function loadCustomDef()
252 $this->custom_def=array();