3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 require_once('modules/DynamicFields/templates/Fields/TemplateInt.php');
43 * Integer fields preset to max of 100 after upgrade
45 * @author mgusev@sugarcrm.com
48 class Bug56694v2Test extends Sugar_PHPUnit_Framework_TestCase
53 protected $templateInt = null;
56 * @var javascript56694
58 protected $javascript = null;
63 protected $bean = null;
65 public function setUp()
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;
76 $this->bean = new SugarBean();
78 $this->javascript = new javascript56694();
79 $this->javascript->setSugarBean($this->bean);
83 * Test asserts that after addField call validator is not added
87 public function testAddFieldForFieldWithoutValidator()
89 $this->bean->field_name_map[$this->templateInt->name] = $this->templateInt->get_field_def();
90 $this->javascript->addField($this->templateInt->name, $this->templateInt->required);
92 $this->assertEmpty($this->javascript->getData(), 'Validator is added');
96 * Test asserts that after addField call validator is added with empty values
100 public function testAddFieldForFieldWithoutRealValidator()
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);
108 $this->assertNotEmpty($this->javascript->getData(), 'Validator is not added');
110 $actual = $this->javascript->getData();
111 $this->assertSame(array(false, false), $actual, 'Values are incorrect');
115 * Test asserts that after addField call validator is added only for min value, max value should be false
119 public function testAddFieldForFieldWithMinOnly()
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);
125 $this->assertNotEmpty($this->javascript->getData(), 'Validator is not added');
127 $actual = $this->javascript->getData();
128 $this->assertSame(array($this->templateInt->min,false), $actual, 'Values are incorrect');
132 * Test asserts that after addField call validator is added only to max value, min value should be false
136 public function testAddFieldForFieldWithMaxOnly()
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);
142 $this->assertNotEmpty($this->javascript->getData(), 'Validator is not added');
144 $actual = $this->javascript->getData();
145 $this->assertSame(array(false, $this->templateInt->max), $actual, 'Values are incorrect');
149 * Test asserts that after addField call validator is added with both values
153 public function testAddFieldForFieldWithMaxMin()
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);
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');
166 * Test asserts that after addField call validator added to both values and has min value, because of min value more than max
170 public function testAddFieldForFieldWithInvertedMaxMin()
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);
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');
184 * Mock of javascript class
186 class javascript56694 extends javascript
191 protected $data = array();
196 public function getData()
201 public function addFieldRange($field, $type, $displayName, $required, $prefix = '', $min, $max)
203 $this->data = array($min, $max);