]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/javascript/Bug56694v2Test.php
Release 6.5.6
[Github/sugarcrm.git] / tests / include / javascript / Bug56694v2Test.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 Bug56694v2Test extends Sugar_PHPUnit_Framework_TestCase
49 {
50     /**
51      * @var TemplateInt
52      */
53     protected $templateInt = null;
54
55     /**
56      * @var javascript56694
57      */
58     protected $javascript = null;
59
60     /**
61      * @var SugarBean
62      */
63     protected $bean = null;
64
65     public function setUp()
66     {
67         $this->templateInt = new TemplateInt();
68         $this->templateInt->importable = "true";
69         $this->templateInt->label = "LBL_TEST";
70         $this->templateInt->name = "bug_c";
71         $this->templateInt->no_default = 1;
72         $this->templateInt->reportable = "1";
73         $this->templateInt->supports_unified_search = true;
74         $this->templateInt->vname = $this->templateInt->label;
75
76         $this->bean = new SugarBean();
77
78         $this->javascript = new javascript56694();
79         $this->javascript->setSugarBean($this->bean);
80     }
81
82     /**
83      * Test asserts that after addField call validator is not added
84      *
85      * @group 56694
86      */
87     public function testAddFieldForFieldWithoutValidator()
88     {
89         $this->bean->field_name_map[$this->templateInt->name] = $this->templateInt->get_field_def();
90         $this->javascript->addField($this->templateInt->name, $this->templateInt->required);
91
92         $this->assertEmpty($this->javascript->getData(), 'Validator is added');
93     }
94
95     /**
96      * Test asserts that after addField call validator is added with empty values
97      *
98      * @group 56694
99      */
100     public function testAddFieldForFieldWithoutRealValidator()
101     {
102         $this->templateInt->min = 5;
103         $this->bean->field_name_map[$this->templateInt->name] = $this->templateInt->get_field_def();
104         $this->bean->field_name_map[$this->templateInt->name]['validation']['min'] = null;
105         $this->bean->field_name_map[$this->templateInt->name]['validation']['max'] = null;
106         $this->javascript->addField($this->templateInt->name, $this->templateInt->required);
107
108         $this->assertNotEmpty($this->javascript->getData(), 'Validator is not added');
109
110         $actual = $this->javascript->getData();
111         $this->assertSame(array(false, false), $actual, 'Values are incorrect');
112     }
113
114     /**
115      * Test asserts that after addField call validator is added only for min value, max value should be false
116      *
117      * @group 56694
118      */
119     public function testAddFieldForFieldWithMinOnly()
120     {
121         $this->templateInt->min = 5;
122         $this->bean->field_name_map[$this->templateInt->name] = $this->templateInt->get_field_def();
123         $this->javascript->addField($this->templateInt->name, $this->templateInt->required);
124
125         $this->assertNotEmpty($this->javascript->getData(), 'Validator is not added');
126
127         $actual = $this->javascript->getData();
128         $this->assertSame(array($this->templateInt->min,false), $actual, 'Values are incorrect');
129     }
130
131     /**
132      * Test asserts that after addField call validator is added only to max value, min value should be false
133      *
134      * @group 56694
135      */
136     public function testAddFieldForFieldWithMaxOnly()
137     {
138         $this->templateInt->max = 5;
139         $this->bean->field_name_map[$this->templateInt->name] = $this->templateInt->get_field_def();
140         $this->javascript->addField($this->templateInt->name, $this->templateInt->required);
141
142         $this->assertNotEmpty($this->javascript->getData(), 'Validator is not added');
143
144         $actual = $this->javascript->getData();
145         $this->assertSame(array(false, $this->templateInt->max), $actual, 'Values are incorrect');
146     }
147
148     /**
149      * Test asserts that after addField call validator is added with both values
150      *
151      * @group 56694
152      */
153     public function testAddFieldForFieldWithMaxMin()
154     {
155         $this->templateInt->min = 5;
156         $this->templateInt->max = 6;
157         $this->bean->field_name_map[$this->templateInt->name] = $this->templateInt->get_field_def();
158         $this->javascript->addField($this->templateInt->name, $this->templateInt->required);
159
160         $this->assertNotEmpty($this->javascript->getData(), 'Validator is not added');
161         $actual = $this->javascript->getData();
162         $this->assertEquals(array($this->templateInt->min, $this->templateInt->max), $actual, 'Values are incorrect');
163     }
164
165     /**
166      * Test asserts that after addField call validator added to both values and has min value, because of min value more than max
167      *
168      * @group 56694
169      */
170     public function testAddFieldForFieldWithInvertedMaxMin()
171     {
172         $this->templateInt->min = 6;
173         $this->templateInt->max = 5;
174         $this->bean->field_name_map[$this->templateInt->name] = $this->templateInt->get_field_def();
175         $this->javascript->addField($this->templateInt->name, $this->templateInt->required);
176
177         $this->assertNotEmpty($this->javascript->getData(), 'Validator is not added');
178         $actual = $this->javascript->getData();
179         $this->assertSame(array($this->templateInt->min, $this->templateInt->min), $actual, 'Min value is incorrect');
180     }
181 }
182
183 /**
184  * Mock of javascript class
185  */
186 class javascript56694 extends javascript
187 {
188     /**
189      * @var array
190      */
191     protected $data = array();
192
193     /**
194      * @return array
195      */
196     public function getData()
197     {
198         return $this->data;
199     }
200
201     public function addFieldRange($field, $type, $displayName, $required, $prefix = '', $min, $max)
202     {
203         $this->data = array($min, $max);
204     }
205 }