2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 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('include/nusoap/nusoap.php');
39 require_once('modules/Users/User.php');
45 class Bug40250Test extends Sugar_PHPUnit_Framework_TestCase
48 public $_soapClient = null;
49 public $_session = null;
50 public $_sessionId = '';
55 public function setUp()
58 $this->_setupTestUser();
59 $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'].'/soap.php',false,false,false,false,false,60,60);
64 * Remove anything that was used during this test
67 public function tearDown() {
68 global $soap_version_test_accountId, $soap_version_test_opportunityId, $soap_version_test_contactId;
69 $this->_tearDownTestUser();
71 $this->_sessionId = '';
74 public function testRetrieveUsersList() {
75 //First retrieve the users count (should be at least 1)
76 // 20110707 Frank Steegmans: DB2 by default is case sensitive. Note http://www.db2ude.com/?q=node/79
77 $countArr = $this->_soapClient->call('get_entries_count',array('session'=>$this->_sessionId,'module_name'=>'Users','query'=>" users.status = 'Active' ",0));
78 $count = $countArr['result_count'];
79 $this->assertGreaterThanOrEqual(1, $count, 'no users were retrieved so the test user was not set up correctly');
81 //now retrieve the list of users
82 $usersArr = $this->_soapClient->call('get_entry_list',array('session'=>$this->_sessionId,'module_name'=>'Users','query'=>" users.status = 'Active' ", 'user_name','0' ,'select_field'=>array('user_name'),10000,0));
83 $usersCount = $usersArr['result_count'];
85 //the count from both functions should be the same
86 $this->assertEquals($count, $usersCount ,'count is not the same which means that the 2 calls are generating different results.');
89 $result = $this->_soapClient->call('logout',array('session' => $this->_sessionId));
92 /**********************************
93 * HELPER PUBLIC FUNCTIONS
94 **********************************/
97 * Attempt to login to the soap server
99 * @return $set_entry_result - this should contain an id and error. The id corresponds
102 public function _login(){
103 global $current_user;
104 $GLOBALS['db']->commit(); // Making sure we commit any changes before logging in
105 $result = $this->_soapClient->call('login',
107 array('user_name' => $this->_user->user_name,
108 'password' => $this->_user->user_hash,
110 'application_name' => 'SoapTest')
112 $this->_sessionId = $result['id'];
121 public function _setupTestUser() {
122 $this->_user = SugarTestUserUtilities::createAnonymousUser();
123 $this->_user->status = 'Active';
124 $this->_user->is_admin = 1;
125 $this->_user->save();
131 * Remove user created for test
134 public function _tearDownTestUser() {
135 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();