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 Bug56694Test extends Sugar_PHPUnit_Framework_TestCase
53 protected $templateInt = null;
55 public function setUp()
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;
68 * Test asserts that min & max properties more important than ext1 & ext2
72 public function testMinMaxWinExt()
74 $this->templateInt->ext1 = 3;
75 $this->templateInt->ext2 = 4;
76 $vardef = $this->templateInt->get_field_def();
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');
82 $this->templateInt->min = 1;
83 $this->templateInt->max = 2;
84 $vardef = $this->templateInt->get_field_def();
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');
92 * Method returns data for tests
95 * should validator be present
96 * should min value be present
97 * should max value be present
101 public function getMaxMin()
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)
118 * Test checks min & max range for validator for int field
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
126 * @dataProvider getMaxMin
129 public function testGetFieldDefByMinMax($min, $max, $isValidation, $isMin, $isMax)
131 $this->templateInt->min = $min;
132 $this->templateInt->max = $max;
133 $vardef = $this->templateInt->get_field_def();
135 if ($isValidation == false)
137 $this->assertArrayNotHasKey('validation', $vardef, 'Validation is required');
141 $this->assertArrayHasKey('validation', $vardef, 'Validation is not required');
144 $this->assertEquals($min, $vardef['validation']['min'], 'Min value is incorrect');
148 $this->assertEquals(false, $vardef['validation']['min'], 'Min value is present');
152 $this->assertEquals($max, $vardef['validation']['max'], 'Max value is incorrect');
156 $this->assertEquals(false, $vardef['validation']['max'], 'Max value is present');
162 * Test checks min & max range for validator for int field
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
170 * @dataProvider getMaxMin
173 public function testGetFieldDefByExt($min, $max, $isValidation, $isMin, $isMax)
175 $this->templateInt->ext1 = $min;
176 $this->templateInt->ext2 = $max;
177 $vardef = $this->templateInt->get_field_def();
179 if ($isValidation == false)
181 $this->assertArrayNotHasKey('validation', $vardef, 'Validation is required');
185 $this->assertArrayHasKey('validation', $vardef, 'Validation is not required');
188 $this->assertEquals($min, $vardef['validation']['min'], 'Min value is incorrect');
192 $this->assertEquals(false, $vardef['validation']['min'], 'Min value is present');
196 $this->assertEquals($max, $vardef['validation']['max'], 'Max value is incorrect');
200 $this->assertEquals(false, $vardef['validation']['max'], 'Max value is present');