]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/DynamicFields/Bug43471Test.php
Release 6.2.3
[Github/sugarcrm.git] / tests / modules / DynamicFields / Bug43471Test.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  * @ticket 43471
39  */
40 class Bug43471Test extends Sugar_PHPUnit_Framework_TestCase
41 {
42     private $_tablename;
43     private $_old_installing;
44     
45     public function setUp()
46     {
47         $this->accountMockBean = $this->getMock('TestBean');
48         $this->_tablename = 'test' . date("YmdHis");
49     }
50     
51     public function tearDown()
52     {
53     }
54     
55     public function testDynamicFieldsRepairCustomFields()
56     {
57         $bean = $this->accountMockBean;
58
59         /** @var $df DynamicField */
60         $df = $this->getMock('DynamicField', array('createCustomTable'));
61         $bean->table_name = $this->_tablename;
62         $bean->field_defs = array (
63               'id' =>
64               array (
65                 'name' => 'id',
66                 'vname' => 'LBL_ID',
67                 'type' => 'id',
68                 'required' => true,
69                 'reportable' => true,
70                 'comment' => 'Unique identifier',
71               ),
72               'name' =>
73               array (
74                 'name' => 'name',
75                 'type' => 'name',
76                 'dbType' => 'varchar',
77                 'vname' => 'LBL_NAME',
78                 'len' => 150,
79                 'comment' => 'Name of the Company',
80                 'unified_search' => true,
81                 'audited' => true,
82                 'required' => true,
83                 'importable' => 'required',
84                 'merge_filter' => 'selected',
85               ),
86               'FooBar_c' =>
87               array (
88                 'required' => false,
89                 'source' => 'custom_fields',
90                 'name' => 'FooBar_c',
91                 'vname' => 'LBL_FOOBAR',
92                 'type' => 'varchar',
93                 'massupdate' => '0',
94                 'default' => NULL,
95                 'comments' => 'LBL_FOOBAR_COMMENT',
96                 'help' => 'LBL_FOOBAR_HELP',
97                 'importable' => 'true',
98                 'duplicate_merge' => 'disabled',
99                 'duplicate_merge_dom_value' => '0',
100                 'audited' => false,
101                 'reportable' => true,
102                 'calculated' => false,
103                 'len' => '255',
104                 'size' => '20',
105                 'id' => 'AccountsFooBar_c',
106                 'custom_module' => 'Accounts',
107               ),
108             );
109         $df->setup($bean);
110         $df->expects($this->any())
111                 ->method('createCustomTable')
112                 ->will($this->returnValue(null));
113
114         $helper = $this->getMock('MysqliHelper');
115         $helper->expects($this->any())
116                 ->method('get_columns')
117                 ->will($this->returnValue(array(
118                 'foobar_c' => array (
119                     'name' => 'FooBar_c',
120                     'type' => 'varchar',
121                     'len' => '255',
122                     ),
123                 )));
124         // set the new db helper
125         $GLOBALS['db']->helper = $helper;
126
127         $repair = $df->repairCustomFields(false);
128         $this->assertEquals("", $repair);
129
130         // reset the db helper
131         $GLOBALS['db']->helper = null;
132     }
133 }
134
135
136 // test bean class
137 require_once("include/SugarObjects/templates/company/Company.php");
138
139 // Account is used to store account information.
140 class TestBean extends Company {
141 }