2 /*********************************************************************************
3 * SugarCRM Community Edition 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 ********************************************************************************/
37 require_once 'include/database/MssqlManager.php';
39 class MssqlManagerTest extends Sugar_PHPUnit_Framework_TestCase
41 static public function setupBeforeClass()
43 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
44 $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
47 static public function tearDownAfterClass()
49 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
50 unset($GLOBALS['current_user']);
51 unset($GLOBALS['app_strings']);
54 public function setUp()
56 $this->_db = new MssqlManager();
59 public function testQuote()
61 $string = "'dog eat ";
62 $this->assertEquals($this->_db->quote($string),"''dog eat ");
65 public function testArrayQuote()
67 $string = array("'dog eat ");
68 $this->_db->arrayQuote($string);
69 $this->assertEquals($string,array("''dog eat "));
72 public function providerConvert()
84 array('foo','left',array('1','2','3')),
88 array('foo','date_format'),
89 'LEFT(CONVERT(varchar(10),foo,120),10)'
92 array('foo','date_format',array('1','2','3')),
93 'LEFT(CONVERT(varchar(10),foo,120),10)'
96 array('foo','date_format',array("'%Y-%m'")),
97 'LEFT(CONVERT(varchar(7),foo,120),7)'
100 array('foo','IFNULL'),
104 array('foo','IFNULL',array('1','2','3')),
108 array('foo','CONCAT',array('1','2','3')),
112 array(array('1','2','3'),'CONCAT'),
116 array(array('1','2','3'),'CONCAT',array('foo', 'bar')),
120 array('foo','text2char'),
121 'CAST(foo AS varchar(8000))'
124 array('foo','length'),
128 array('foo','month'),
132 array('foo','quarter'),
133 "DATEPART(quarter, foo)"
136 array('foo','add_date',array(1,'day')),
140 array('foo','add_date',array(2,'week')),
141 "DATEADD(week,2,foo)"
144 array('foo','add_date',array(3,'month')),
145 "DATEADD(month,3,foo)"
148 array('foo','add_date',array(4,'quarter')),
149 "DATEADD(quarter,4,foo)"
152 array('foo','add_date',array(5,'year')),
153 "DATEADD(year,5,foo)"
161 * @dataProvider providerConvert
163 public function testConvert(array $parameters, $result)
165 $this->assertEquals($result, call_user_func_array(array($this->_db, "convert"), $parameters));
171 public function testConcat()
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);
177 public function providerFromConvert()
179 $returnArray = array(
181 array('foo','nothing'),
185 array('2009-01-01 12:00:00','date'),
189 array('2009-01-01 12:00:00','time'),
199 * @dataProvider providerFromConvert
201 public function testFromConvert(
207 $this->_db->fromConvert($parameters[0],$parameters[1]),