]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/Bug40250Test.php
Added unit tests.
[Github/sugarcrm.git] / tests / service / Bug40250Test.php
1 <?php 
2 require_once('include/nusoap/nusoap.php');
3 require_once('modules/Users/User.php');
4
5
6 /**
7  * @group bug40250
8  */
9 class Bug40250Test extends Sugar_PHPUnit_Framework_TestCase
10 {
11         public $_user = null;
12         public $_soapClient = null;
13         public $_session = null;
14         public $_sessionId = '';
15     /**
16      * Create test user
17      *
18      */
19         public function setUp() 
20     {
21         
22         $this->_setupTestUser();
23                 $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'].'/soap.php',false,false,false,false,false,60,60);
24         $this->_login();
25     }
26
27     /**
28      * Remove anything that was used during this test
29      *
30      */
31     public function tearDown() {
32         global $soap_version_test_accountId, $soap_version_test_opportunityId, $soap_version_test_contactId;
33         $this->_tearDownTestUser();
34         $this->_user = null;
35         $this->_sessionId = '';
36     }   
37     
38     public function testRetrieveUsersList() {
39         //First retrieve the users count (should be at least 1)
40                 $countArr  = $this->_soapClient->call('get_entries_count',array('session'=>$this->_sessionId,'module_name'=>'Users','query'=>" users.status = 'active' ",0));
41         $count = $countArr['result_count'];
42         $this->assertTrue($count > 1, 'no users were retrieved so the test user was not set up correctly');
43         
44                 //now retrieve the list of users
45         $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));
46         $usersCount = $usersArr['result_count'];
47         
48         //the count from both functions should be the same
49         $this->assertTrue($count == $usersCount ,'count is not the same which means that the 2 calls are generating different results.');
50         
51                 //logout
52         $result =  $this->_soapClient->call('logout',array('session' => $this->_sessionId));
53     }
54
55         /**********************************
56      * HELPER PUBLIC FUNCTIONS
57      **********************************/
58     
59     /**
60      * Attempt to login to the soap server
61      *
62      * @return $set_entry_result - this should contain an id and error.  The id corresponds
63      * to the session_id.
64      */
65     public function _login(){
66                 global $current_user;   
67         $result = $this->_soapClient->call('login',
68             array('user_auth' => 
69                 array('user_name' => $this->_user->user_name,
70                     'password' => $this->_user->user_hash, 
71                     'version' => '.01'), 
72                 'application_name' => 'SoapTest')
73             );
74         $this->_sessionId = $result['id'];
75                 return $result;
76                 
77     }
78     
79  /**
80      * Create a test user
81      *
82      */
83         public function _setupTestUser() {
84         $this->_user = SugarTestUserUtilities::createAnonymousUser();
85         $this->_user->status = 'Active';
86         $this->_user->is_admin = 1;
87         $this->_user->save();
88     }
89     
90
91         
92     /**
93      * Remove user created for test
94      *
95      */
96         public function _tearDownTestUser() {
97        SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
98     }
99         
100 }
101 ?>