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