]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/Bug40250Test.php
Release 6.2.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                 $countArr  = $this->_soapClient->call('get_entries_count',array('session'=>$this->_sessionId,'module_name'=>'Users','query'=>" users.status = 'active' ",0));
77         $count = $countArr['result_count'];
78         $this->assertTrue($count > 1, 'no users were retrieved so the test user was not set up correctly');
79         
80                 //now retrieve the list of users
81         $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'),100,0));
82         $usersCount = $usersArr['result_count'];
83         
84         //the count from both functions should be the same
85         $this->assertTrue($count == $usersCount ,'count is not the same which means that the 2 calls are generating different results.');
86         
87                 //logout
88         $result =  $this->_soapClient->call('logout',array('session' => $this->_sessionId));
89     }
90
91         /**********************************
92      * HELPER PUBLIC FUNCTIONS
93      **********************************/
94     
95     /**
96      * Attempt to login to the soap server
97      *
98      * @return $set_entry_result - this should contain an id and error.  The id corresponds
99      * to the session_id.
100      */
101     public function _login(){
102                 global $current_user;   
103         $result = $this->_soapClient->call('login',
104             array('user_auth' => 
105                 array('user_name' => $this->_user->user_name,
106                     'password' => $this->_user->user_hash, 
107                     'version' => '.01'), 
108                 'application_name' => 'SoapTest')
109             );
110         $this->_sessionId = $result['id'];
111                 return $result;
112                 
113     }
114     
115  /**
116      * Create a test user
117      *
118      */
119         public function _setupTestUser() {
120         $this->_user = SugarTestUserUtilities::createAnonymousUser();
121         $this->_user->status = 'Active';
122         $this->_user->is_admin = 1;
123         $this->_user->save();
124     }
125     
126
127         
128     /**
129      * Remove user created for test
130      *
131      */
132         public function _tearDownTestUser() {
133        SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
134     }
135         
136 }
137 ?>