]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/database/MssqlManagerTest.php
Release 6.4.0
[Github/sugarcrm.git] / tests / include / database / MssqlManagerTest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition 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 require_once 'include/database/MssqlManager.php';
38
39 class MssqlManagerTest extends Sugar_PHPUnit_Framework_TestCase
40 {
41     static public function setupBeforeClass()
42     {
43         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
44         $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
45     }
46
47     static public function tearDownAfterClass()
48     {
49         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
50         unset($GLOBALS['current_user']);
51         unset($GLOBALS['app_strings']);
52     }
53
54     public function setUp()
55     {
56         $this->_db = new MssqlManager();
57     }
58
59     public function testQuote()
60     {
61         $string = "'dog eat ";
62         $this->assertEquals($this->_db->quote($string),"''dog eat ");
63     }
64
65     public function testArrayQuote()
66     {
67         $string = array("'dog eat ");
68         $this->_db->arrayQuote($string);
69         $this->assertEquals($string,array("''dog eat "));
70     }
71
72     public function providerConvert()
73     {
74         $returnArray = array(
75                 array(
76                     array('foo','today'),
77                     'GETDATE()'
78                     ),
79                 array(
80                     array('foo','left'),
81                     'LEFT(foo)'
82                     ),
83                 array(
84                     array('foo','left',array('1','2','3')),
85                     'LEFT(foo,1,2,3)'
86                     ),
87                 array(
88                     array('foo','date_format'),
89                     'LEFT(CONVERT(varchar(10),foo,120),10)'
90                     ),
91                 array(
92                     array('foo','date_format',array('1','2','3')),
93                     'LEFT(CONVERT(varchar(10),foo,120),10)'
94                     ),
95                 array(
96                     array('foo','date_format',array("'%Y-%m'")),
97                     'LEFT(CONVERT(varchar(7),foo,120),7)'
98                     ),
99                 array(
100                     array('foo','IFNULL'),
101                     'ISNULL(foo,\'\')'
102                     ),
103                 array(
104                     array('foo','IFNULL',array('1','2','3')),
105                     'ISNULL(foo,1,2,3)'
106                     ),
107                 array(
108                     array('foo','CONCAT',array('1','2','3')),
109                     'foo+1+2+3'
110                     ),
111                 array(
112                     array(array('1','2','3'),'CONCAT'),
113                     '1+2+3'
114                     ),
115                 array(
116                     array(array('1','2','3'),'CONCAT',array('foo', 'bar')),
117                     '1+2+3+foo+bar'
118                     ),
119                 array(
120                     array('foo','text2char'),
121                     'CAST(foo AS varchar(8000))'
122                 ),
123                 array(
124                     array('foo','length'),
125                     "LEN(foo)"
126                 ),
127                 array(
128                     array('foo','month'),
129                     "MONTH(foo)"
130                 ),
131                 array(
132                     array('foo','quarter'),
133                     "DATEPART(quarter, foo)"
134                 ),
135                 array(
136                     array('foo','add_date',array(1,'day')),
137                     "DATEADD(day,1,foo)"
138                 ),
139                 array(
140                     array('foo','add_date',array(2,'week')),
141                     "DATEADD(week,2,foo)"
142                 ),
143                 array(
144                     array('foo','add_date',array(3,'month')),
145                     "DATEADD(month,3,foo)"
146                 ),
147                 array(
148                     array('foo','add_date',array(4,'quarter')),
149                     "DATEADD(quarter,4,foo)"
150                 ),
151                 array(
152                     array('foo','add_date',array(5,'year')),
153                     "DATEADD(year,5,foo)"
154                 ),
155         );
156         return $returnArray;
157     }
158
159     /**
160      * @ticket 33283
161      * @dataProvider providerConvert
162      */
163     public function testConvert(array $parameters, $result)
164     {
165         $this->assertEquals($result, call_user_func_array(array($this->_db, "convert"), $parameters));
166      }
167
168      /**
169       * @ticket 33283
170       */
171      public function testConcat()
172      {
173          $ret = $this->_db->concat('foo',array('col1','col2','col3'));
174          $this->assertEquals("LTRIM(RTRIM(ISNULL(foo.col1,'')+' '+ISNULL(foo.col2,'')+' '+ISNULL(foo.col3,'')))", $ret);
175      }
176
177      public function providerFromConvert()
178      {
179          $returnArray = array(
180              array(
181                  array('foo','nothing'),
182                  'foo'
183                  ),
184                  array(
185                      array('2009-01-01 12:00:00','date'),
186                      '2009-01-01'
187                      ),
188                  array(
189                      array('2009-01-01 12:00:00','time'),
190                      '12:00:00'
191                      )
192                  );
193
194          return $returnArray;
195      }
196
197      /**
198       * @ticket 33283
199       * @dataProvider providerFromConvert
200       */
201      public function testFromConvert(
202          array $parameters,
203          $result
204          )
205      {
206          $this->assertEquals(
207              $this->_db->fromConvert($parameters[0],$parameters[1]),
208              $result);
209     }
210
211 }