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 ********************************************************************************/
38 require_once("modules/Accounts/Account.php");
40 class Bug34993Test extends Sugar_PHPUnit_Framework_TestCase
43 private $_old_installing;
45 public function setUp()
47 $this->accountMockBean = $this->getMock('Account' , array('hasCustomFields'));
48 $this->_tablename = 'test' . date("YmdHis");
49 if ( isset($GLOBALS['installing']) )
51 $this->_old_installing = $GLOBALS['installing'];
53 $GLOBALS['installing'] = true;
55 $GLOBALS['db']->createTableParams($this->_tablename . '_cstm',
64 $GLOBALS['db']->query("INSERT INTO {$this->_tablename}_cstm (id_c) VALUES ('12345')");
66 //Safety check in case the previous run had failed
67 $GLOBALS['db']->query("DELETE FROM fields_meta_data WHERE id in ('Accountsbug34993_test_c', 'Accountsbug34993_test2_c')");
70 public function tearDown()
72 $GLOBALS['db']->dropTableName($this->_tablename . '_cstm');
73 $GLOBALS['db']->query("DELETE FROM fields_meta_data WHERE id in ('Accountsbug34993_test_c', 'Accountsbug34993_test2_c')");
74 if ( isset($this->_old_installing) ) {
75 $GLOBALS['installing'] = $this->_old_installing;
77 unset($GLOBALS['installing']);
80 if(file_exists('custom/Extension/modules/Accounts/Ext/Vardefs/sugarfield_bug34993_test_c.php'))
82 unlink('custom/Extension/modules/Accounts/Ext/Vardefs/sugarfield_bug34993_test_c.php');
85 if(file_exists('custom/Extension/modules/Accounts/Ext/Vardefs/sugarfield_bug34993_test2_c.php'))
87 unlink('custom/Extension/modules/Accounts/Ext/Vardefs/sugarfield_bug34993_test2_c.php');
90 VardefManager::clearVardef('Accounts', 'Account');
91 VardefManager::refreshVardefs('Accounts', 'Account');
94 public function testCustomFieldDefaultValue()
96 require_once('modules/DynamicFields/templates/Fields/TemplateText.php');
97 require_once('modules/DynamicFields/DynamicField.php');
98 require_once('modules/DynamicFields/FieldCases.php');
100 //Simulate create a custom text field with a default value set to 123
101 $templateText = get_widget('varchar');
102 $templateText->type = 'varchar';
103 $templateText->view = 'edit';
104 $templateText->label = 'CUSTOM TEST';
105 $templateText->name = 'bug34993_test';
106 $templateText->size = 20;
107 $templateText->len = 255;
108 $templateText->required = false;
109 $templateText->default = '123';
110 $templateText->default_value = '123';
111 $templateText->comment = '';
112 $templateText->audited = 0;
113 $templateText->massupdate = 0;
114 $templateText->importable = true;
115 $templateText->duplicate_merge = 0;
116 $templateText->reportable = 1;
117 $templateText->ext1 = NULL;
118 $templateText->ext2 = NULL;
119 $templateText->ext3 = NULL;
120 $templateText->ext4 = NULL;
122 $bean = $this->accountMockBean;
123 $bean->custom_fields = new DynamicField($bean->module_dir);
124 $bean->custom_fields->setup($bean);
126 $bean->expects($this->any())
127 ->method('hasCustomFields')
128 ->will($this->returnValue(true));
129 $bean->table_name = $this->_tablename;
131 $bean->custom_fields->addFieldObject($templateText);
132 $bean->custom_fields->retrieve();
133 $this->assertEquals($bean->id_c, '12345', "Assert that the custom table exists");
134 $this->assertEquals($bean->bug34993_test_c, NULL, "Assert that the custom text field has a default value set to NULL");
137 //Simulate create a custom text field with a default value set to 123
138 $templateText = get_widget('enum');
139 $templateText->type = 'enum';
140 $templateText->view = 'edit';
141 $templateText->label = 'CUSTOM TEST2';
142 $templateText->name = 'bug34993_test2';
143 $templateText->size = 20;
144 $templateText->len = 255;
145 $templateText->required = false;
146 $templateText->default = '123';
147 $templateText->default_value = '123';
148 $templateText->comment = '';
149 $templateText->audited = 0;
150 $templateText->massupdate = 0;
151 $templateText->importable = true;
152 $templateText->duplicate_merge = 0;
153 $templateText->reportable = 1;
154 $templateText->ext1 = 'account_type_dom';
155 $templateText->ext2 = NULL;
156 $templateText->ext3 = NULL;
157 $templateText->ext4 = NULL;
159 $bean = $this->accountMockBean;
160 $bean->custom_fields = new DynamicField($bean->module_dir);
161 $bean->custom_fields->setup($bean);
163 $bean->expects($this->any())
164 ->method('hasCustomFields')
165 ->will($this->returnValue(true));
166 $bean->table_name = $this->_tablename;
168 $bean->custom_fields->addFieldObject($templateText);
169 $bean->custom_fields->retrieve();
170 $this->assertEquals($bean->id_c, '12345', "Assert that the custom table exists");
171 $this->assertEquals($bean->bug34993_test2_c, NULL, "Assert that the custom enum field has a default value set to NULL");