2 /*********************************************************************************
3 * SugarCRM is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 require_once('data/SugarBean.php');
39 require_once('modules/Accounts/Account.php');
41 class fixUpFormattingTest extends Sugar_PHPUnit_Framework_TestCase
45 public function setUp()
47 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
49 $myBean = new SugarBean();
51 $myBean->field_defs = array(
52 'id' => array('name' => 'id', 'vname' => 'LBL_ID', 'type' => 'id', 'required' => true, ),
53 'name' => array('name' => 'name', 'vname' => 'LBL_NAME', 'type' => 'varchar', 'len' => '255', 'required' => true, ),
54 'bool_field' => array('name' => 'bool_field', 'vname' => 'LBL_BOOL_FIELD', 'type' => 'bool', ),
55 'int_field' => array('name' => 'int_field', 'vname' => 'LBL_INT_FIELD', 'type' => 'int', ),
56 'float_field' => array('name' => 'float_field', 'vname' => 'LBL_FLOAT_FIELD', 'type' => 'float', 'precision' => 2, ),
57 'date_field' => array('name' => 'date_field', 'vname' => 'LBL_DATE_FIELD', 'type' => 'date', ),
58 'time_field' => array('name' => 'time_field', 'vname' => 'LBL_TIME_FIELD', 'type' => 'time', ),
59 'datetime_field' => array('name' => 'datetime_field', 'vname' => 'LBL_DATETIME_FIELD', 'type' => 'datetime', ),
62 $myBean->id = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
63 $myBean->name = 'Fake Bean';
64 $myBean->bool_field = 1;
65 $myBean->int_field = 2001;
66 $myBean->float_field = 20.01;
67 $myBean->date_field = '2001-07-28';
68 $myBean->time_field = '21:19:37';
69 $myBean->datetime_field = '2001-07-28 21:19:37';
73 public function tearDown()
75 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
76 unset($GLOBALS['current_user']);
77 unset($this->time_date);
80 public function providerBoolFixups()
101 * @dataProvider providerBoolFixups
103 public function testBoolFixups($from, $to)
105 $bean = new SugarBean();
107 $bean->bool_field = $from;
108 $bean->fixUpFormatting();
109 $this->assertEquals($to,$bean->bool_field,'fixUpFormatting did not adjust from ('.gettype($from).') "'.$from.'"');
115 public function testStringNULLFixups()
117 $bean = new SugarBean();
119 $bean->field_defs = array('date_field'=>array('type'=>'date'),
120 'datetime_field'=>array('type'=>'datetime'),
121 'time_field'=>array('type'=>'time'),
122 'datetimecombo_field'=>array('type'=>'datetimecombo')
124 $bean->date_field = 'NULL';
125 $bean->datetime_field = 'NULL';
126 $bean->time_field = 'NULL';
127 $bean->datetimecombo_field = 'NULL';
128 $bean->fixUpFormatting();
129 $this->assertEquals('', $bean->date_field,'fixUpFormatting did not reset string NULL for date');
130 $this->assertEquals('', $bean->datetime_field,'fixUpFormatting did not reset string NULL for time');
131 $this->assertEquals('', $bean->time_field,'fixUpFormatting did not reset string NULL for datetime');
132 $this->assertEquals('', $bean->datetimecombo_field,'fixUpFormatting did not reset string NULL for datetimecombo');