]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/DynamicFields/templates/Fields/Bug56694Test.php
Release 6.5.6
[Github/sugarcrm.git] / tests / modules / DynamicFields / templates / Fields / Bug56694Test.php
1 <?php
2
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 require_once('modules/DynamicFields/templates/Fields/TemplateInt.php');
40
41 /**
42  * Bug #56694
43  * Integer fields preset to max of 100 after upgrade
44  *
45  * @author mgusev@sugarcrm.com
46  * @ticked 56694
47  */
48 class Bug56694Test extends Sugar_PHPUnit_Framework_TestCase
49 {
50     /**
51      * @var TemplateInt
52      */
53     protected $templateInt = null;
54
55     public function setUp()
56     {
57         $this->templateInt = new TemplateInt();
58         $this->templateInt->importable = "true";
59         $this->templateInt->label = "LBL_TEST";
60         $this->templateInt->name = "bug_c";
61         $this->templateInt->no_default = 1;
62         $this->templateInt->reportable = "1";
63         $this->templateInt->supports_unified_search = true;
64         $this->templateInt->vname = $this->templateInt->label;
65     }
66
67     /**
68      * Test asserts that min & max properties more important than ext1 & ext2
69      *
70      * @group 53554
71      */
72     public function testMinMaxWinExt()
73     {
74         $this->templateInt->ext1 = 3;
75         $this->templateInt->ext2 = 4;
76         $vardef = $this->templateInt->get_field_def();
77
78         $this->assertArrayHasKey('validation', $vardef, 'Validation is not required');
79         $this->assertEquals(3, $vardef['validation']['min'], 'Ext won');
80         $this->assertEquals(4, $vardef['validation']['max'], 'Ext won');
81
82         $this->templateInt->min = 1;
83         $this->templateInt->max = 2;
84         $vardef = $this->templateInt->get_field_def();
85
86         $this->assertArrayHasKey('validation', $vardef, 'Validation is not required');
87         $this->assertEquals(1, $vardef['validation']['min'], 'Min won');
88         $this->assertEquals(2, $vardef['validation']['max'], 'Max won');
89     }
90
91     /**
92      * Method returns data for tests
93      * min value
94      * max value
95      * should validator be present
96      * should min value be present
97      * should max value be present
98      *
99      * @return array
100      */
101     public function getMaxMin()
102     {
103         return array(
104             array(null, null, false, false, false),
105             array(0, null, true, true, false),
106             array(0, 0, true, true, true),
107             array('0', '0', true, true, true),
108             array(null, 0, true, false, true),
109             array(1, 5, true, true, true, true),
110             array('1', '5', true, true, true, true),
111             array('a', 'b', false, false, false),
112             array('a', 5, true, false, true),
113             array(5, 'a', true, true, false)
114         );
115     }
116
117     /**
118      * Test checks min & max range for validator for int field
119      *
120      * @param mixed $min value
121      * @param mixed $max max
122      * @param bool $isValidation is validation required
123      * @param bool $isMin is min value present
124      * @param bool $isMax is max value present
125      *
126      * @dataProvider getMaxMin
127      * @group 56694
128      */
129     public function testGetFieldDefByMinMax($min, $max, $isValidation, $isMin, $isMax)
130     {
131         $this->templateInt->min = $min;
132         $this->templateInt->max = $max;
133         $vardef = $this->templateInt->get_field_def();
134
135         if ($isValidation == false)
136         {
137             $this->assertArrayNotHasKey('validation', $vardef, 'Validation is required');
138         }
139         else
140         {
141             $this->assertArrayHasKey('validation', $vardef, 'Validation is not required');
142             if ($isMin == true)
143             {
144                 $this->assertEquals($min, $vardef['validation']['min'], 'Min value is incorrect');
145             }
146             else
147             {
148                 $this->assertEquals(false, $vardef['validation']['min'], 'Min value is present');
149             }
150             if ($isMax == true)
151             {
152                 $this->assertEquals($max, $vardef['validation']['max'], 'Max value is incorrect');
153             }
154             else
155             {
156                 $this->assertEquals(false, $vardef['validation']['max'], 'Max value is present');
157             }
158         }
159     }
160
161     /**
162      * Test checks min & max range for validator for int field
163      *
164      * @param mixed $min value
165      * @param mixed $max max
166      * @param bool $isValidation is validation required
167      * @param bool $isMin is min value present
168      * @param bool $isMax is max value present
169      *
170      * @dataProvider getMaxMin
171      * @group 56694
172      */
173     public function testGetFieldDefByExt($min, $max, $isValidation, $isMin, $isMax)
174     {
175         $this->templateInt->ext1 = $min;
176         $this->templateInt->ext2 = $max;
177         $vardef = $this->templateInt->get_field_def();
178
179         if ($isValidation == false)
180         {
181             $this->assertArrayNotHasKey('validation', $vardef, 'Validation is required');
182         }
183         else
184         {
185             $this->assertArrayHasKey('validation', $vardef, 'Validation is not required');
186             if ($isMin == true)
187             {
188                 $this->assertEquals($min, $vardef['validation']['min'], 'Min value is incorrect');
189             }
190             else
191             {
192                 $this->assertEquals(false, $vardef['validation']['min'], 'Min value is present');
193             }
194             if ($isMax == true)
195             {
196                 $this->assertEquals($max, $vardef['validation']['max'], 'Max value is incorrect');
197             }
198             else
199             {
200                 $this->assertEquals(false, $vardef['validation']['max'], 'Max value is present');
201             }
202         }
203     }
204 }