]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/data/fixUpFormatting.php
Added unit tests.
[Github/sugarcrm.git] / tests / data / fixUpFormatting.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37
38 require_once('data/SugarBean.php');
39 require_once('modules/Accounts/Account.php');
40
41 class fixUpFormattingTest extends Sugar_PHPUnit_Framework_TestCase
42 {
43     private $myBean;
44
45         public function setUp()
46         {
47         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
48         
49         $myBean = new SugarBean();
50         
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', ),
60         );
61
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';
70
71         }
72
73         public function tearDown()
74         {
75                 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
76         unset($GLOBALS['current_user']);
77         unset($this->time_date);
78         }
79
80         public function providerBoolFixups()
81         {
82             return array(
83             array(true,1),
84             array(false,0),
85             array('',0),
86             array(1,1),
87             array(0,0),
88             array('1',1),
89             array('0',0),
90             array('true',1),
91             array('false',0),
92             array('on',1),
93             array('off',0),
94             array('yes',1),
95             array('no',0),
96                 );
97         }
98
99         /**
100      * @group bug34562
101      * @dataProvider providerBoolFixups
102      */
103         public function testBoolFixups($from, $to)
104         {
105         $bean = new SugarBean();
106
107         $bean->bool_field = $from;
108         $bean->fixUpFormatting();
109         $this->assertEquals($to,$bean->bool_field,'fixUpFormatting did not adjust from ('.gettype($from).') "'.$from.'"');
110     }
111 }