]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/SOAPTestCase.php
Added unit tests.
[Github/sugarcrm.git] / tests / service / SOAPTestCase.php
1 <?php
2 require_once('include/nusoap/nusoap.php');
3
4 abstract class SOAPTestCase extends Sugar_PHPUnit_Framework_TestCase
5 {
6         public $_user = null;
7         public $_soapClient = null;
8         public $_session = null;
9         public $_sessionId = '';
10     public $_soapURL = '';
11
12     /**
13      * Create test user
14      *
15      */
16         public function setUp()
17     {
18         $beanList = array();
19                 $beanFiles = array();
20                 require('include/modules.php');
21                 $GLOBALS['beanList'] = $beanList;
22                 $GLOBALS['beanFiles'] = $beanFiles;
23                 
24         $this->_soapClient = new nusoapclient($this->_soapURL,false,false,false,false,false,600,600);
25         $this->_setupTestUser();
26         parent::setUp();
27     }
28
29     /**
30      * Remove anything that was used during this test
31      *
32      */
33     public function tearDown()
34     {
35         $this->_tearDownTestUser();
36         $this->_user = null;
37         $this->_sessionId = '';
38         
39                 unset($GLOBALS['beanList']);
40                 unset($GLOBALS['beanFiles']);
41         parent::tearDown();
42     }
43
44     protected function _login()
45     {
46         $result = $this->_soapClient->call('login',
47             array('user_auth' =>
48                 array('user_name' => $this->_user->user_name,
49                     'password' => $this->_user->user_hash,
50                     'version' => '.01'),
51                 'application_name' => 'SoapTest')
52             );
53         $this->_sessionId = $result['id'];
54                 return $result;
55     }
56
57     /**
58      * Create a test user
59      *
60      */
61         public function _setupTestUser() {
62         $this->_user = SugarTestUserUtilities::createAnonymousUser();
63         $this->_user->status = 'Active';
64         $this->_user->is_admin = 1;
65         $this->_user->save();
66         $GLOBALS['current_user'] = $this->_user;
67     }
68
69     /**
70      * Remove user created for test
71      *
72      */
73         public function _tearDownTestUser() {
74        SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
75        unset($GLOBALS['current_user']);
76     }
77
78 }
79