]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/Bug40250Test.php
Release 6.4.0
[Github/sugarcrm.git] / tests / service / Bug40250Test.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  
38 require_once('include/nusoap/nusoap.php');
39 require_once('modules/Users/User.php');
40
41
42 /**
43  * @group bug40250
44  */
45 class Bug40250Test extends Sugar_PHPUnit_Framework_TestCase
46 {
47         public $_user = null;
48         public $_soapClient = null;
49         public $_session = null;
50         public $_sessionId = '';
51     /**
52      * Create test user
53      *
54      */
55         public function setUp() 
56     {
57         
58         $this->_setupTestUser();
59                 $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'].'/soap.php',false,false,false,false,false,60,60);
60         $this->_login();
61     }
62
63     /**
64      * Remove anything that was used during this test
65      *
66      */
67     public function tearDown() {
68         global $soap_version_test_accountId, $soap_version_test_opportunityId, $soap_version_test_contactId;
69         $this->_tearDownTestUser();
70         $this->_user = null;
71         $this->_sessionId = '';
72     }   
73     
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');
80         
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'];
84         
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.');
87         
88                 //logout
89         $result =  $this->_soapClient->call('logout',array('session' => $this->_sessionId));
90     }
91
92         /**********************************
93      * HELPER PUBLIC FUNCTIONS
94      **********************************/
95     
96     /**
97      * Attempt to login to the soap server
98      *
99      * @return $set_entry_result - this should contain an id and error.  The id corresponds
100      * to the session_id.
101      */
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',
106             array('user_auth' => 
107                 array('user_name' => $this->_user->user_name,
108                     'password' => $this->_user->user_hash, 
109                     'version' => '.01'), 
110                 'application_name' => 'SoapTest')
111             );
112         $this->_sessionId = $result['id'];
113                 return $result;
114                 
115     }
116     
117  /**
118      * Create a test user
119      *
120      */
121         public function _setupTestUser() {
122         $this->_user = SugarTestUserUtilities::createAnonymousUser();
123         $this->_user->status = 'Active';
124         $this->_user->is_admin = 1;
125         $this->_user->save();
126     }
127     
128
129         
130     /**
131      * Remove user created for test
132      *
133      */
134         public function _tearDownTestUser() {
135        SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
136     }
137         
138 }
139 ?>