2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 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';
41 * Test is used for testing returnOrderBy() through limitQuery() because returnOrderBy() is private
42 * In MSSQL we use a different way of limiting a query using TOP and ROW_NUMBER() OVER( ORDER BY ordering )
43 * the 'ordering' attribute is tested on correctness with this test
45 * @author avucinic@sugarcrm.com
48 class Bug52783Test extends Sugar_PHPUnit_Framework_TestCase
52 public function setUp()
54 $this->_db = new MssqlManager();
57 public function tearDown()
62 * Test if returnOrderBy() inside limitQuery() method returns a valid MSSQL ordering column for use in OVER()
63 * @dataProvider orderProvider
65 public function testReturnOrderBy($sql, $expected)
67 $expected = strtolower($expected);
68 $result = strtolower($this->_db->limitQuery($sql, 21, 20, false, '', false));
69 $this->assertContains($expected, $result);
72 public function orderProvider()
76 "SELECT contacts.id , LTRIM(RTRIM(ISNULL(contacts.first_name,'')+' '+ISNULL(contacts.last_name,''))) as name, contacts.first_name , contacts.last_name , contacts.salutation , accounts.name account_name, jtl0.account_id account_id, contacts.title , contacts.phone_work , LTRIM(RTRIM(ISNULL(jt1.first_name,'')+' '+ISNULL(jt1.last_name,''))) assigned_user_name , jt1.created_by assigned_user_name_owner , 'Users' assigned_user_name_mod, contacts.date_entered , contacts.assigned_user_id , sfav.id is_favorite FROM contacts LEFT JOIN accounts_contacts jtl0 ON contacts.id=jtl0.contact_id AND jtl0.deleted=0
77 LEFT JOIN accounts accounts ON accounts.id=jtl0.account_id AND accounts.deleted=0
78 AND accounts.deleted=0 LEFT JOIN users jt1 ON contacts.assigned_user_id=jt1.id AND jt1.deleted=0
79 AND jt1.deleted=0 LEFT JOIN sugarfavorites sfav ON sfav.module ='Contacts' AND sfav.record_id=contacts.id AND sfav.created_by='1' AND sfav.deleted=0 where contacts.deleted=0 ORDER BY name",
81 "LTRIM(RTRIM(ISNULL(contacts.first_name,'')+' '+ISNULL(contacts.last_name,'')))"
84 "SELECT contacts.id , LTRIM(RTRIM(ISNULL(contacts.first_name,'')+' '+ISNULL(contacts.last_name,''))) as name, contacts.first_name , contacts.last_name , contacts.salutation , accounts.name account_name, jtl0.account_id account_id, contacts.title , contacts.phone_work , LTRIM(RTRIM(ISNULL(jt1.first_name,'')+' '+ISNULL(jt1.last_name,''))) assigned_user_name , jt1.created_by assigned_user_name_owner , 'Users' assigned_user_name_mod, contacts.date_entered , contacts.assigned_user_id , sfav.id is_favorite FROM contacts LEFT JOIN accounts_contacts jtl0 ON contacts.id=jtl0.contact_id AND jtl0.deleted=0
85 LEFT JOIN accounts accounts ON accounts.id=jtl0.account_id AND accounts.deleted=0
86 AND accounts.deleted=0 LEFT JOIN users jt1 ON contacts.assigned_user_id=jt1.id AND jt1.deleted=0
87 AND jt1.deleted=0 LEFT JOIN sugarfavorites sfav ON sfav.module ='Contacts' AND sfav.record_id=contacts.id AND sfav.created_by='1' AND sfav.deleted=0 where contacts.deleted=0 ORDER BY name ASC",
89 "LTRIM(RTRIM(ISNULL(contacts.first_name,'')+' '+ISNULL(contacts.last_name,'')))"
92 "SELECT contacts.id , LTRIM(RTRIM(ISNULL(contacts.first_name,'')+' '+ISNULL(contacts.last_name,''))) as name, contacts.first_name , contacts.last_name , contacts.salutation , accounts.name account_name, jtl0.account_id account_id, contacts.title , contacts.phone_work , LTRIM(RTRIM(ISNULL(jt1.first_name,'')+' '+ISNULL(jt1.last_name,''))) assigned_user_name , jt1.created_by assigned_user_name_owner , 'Users' assigned_user_name_mod, contacts.date_entered , contacts.assigned_user_id , sfav.id is_favorite FROM contacts LEFT JOIN accounts_contacts jtl0 ON contacts.id=jtl0.contact_id AND jtl0.deleted=0
93 LEFT JOIN accounts accounts ON accounts.id=jtl0.account_id AND accounts.deleted=0
94 AND accounts.deleted=0 LEFT JOIN users jt1 ON contacts.assigned_user_id=jt1.id AND jt1.deleted=0
95 AND jt1.deleted=0 LEFT JOIN sugarfavorites sfav ON sfav.module ='Contacts' AND sfav.record_id=contacts.id AND sfav.created_by='1' AND sfav.deleted=0 where contacts.deleted=0 ORDER BY contacts.name ASC",
100 "SELECT contacts.id , ISNULL(contacts.last_name,''))) as name, contacts.first_name , contacts.last_name , contacts.salutation , accounts.name account_name, jtl0.account_id account_id, contacts.title , contacts.phone_work , LTRIM(RTRIM(ISNULL(jt1.first_name,'')+' '+ISNULL(jt1.last_name,''))) assigned_user_name , jt1.created_by assigned_user_name_owner , 'Users' assigned_user_name_mod, contacts.date_entered , contacts.assigned_user_id , sfav.id is_favorite FROM contacts LEFT JOIN accounts_contacts jtl0 ON contacts.id=jtl0.contact_id AND jtl0.deleted=0
101 LEFT JOIN accounts accounts ON accounts.id=jtl0.account_id AND accounts.deleted=0
102 AND accounts.deleted=0 LEFT JOIN users jt1 ON contacts.assigned_user_id=jt1.id AND jt1.deleted=0
103 AND jt1.deleted=0 LEFT JOIN sugarfavorites sfav ON sfav.module ='Contacts' AND sfav.record_id=contacts.id AND sfav.created_by='1' AND sfav.deleted=0 where contacts.deleted=0 ORDER BY name ASC",
105 "ISNULL(contacts.last_name,'')))"