]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/Bug39855Test.php
Added unit tests.
[Github/sugarcrm.git] / tests / service / Bug39855Test.php
1 <?php 
2 require_once('include/nusoap/nusoap.php');
3 require_once('modules/Cases/Case.php');
4 require_once('modules/Accounts/Account.php');
5
6
7 /**
8  * @group bug39234
9  */
10 class Bug39855Test extends Sugar_PHPUnit_Framework_TestCase
11 {
12         public $_user = null;
13         public $_case1 = null;
14         public $_case2 = null;
15         public $_acc = null;
16         public $_soapClient = null;
17         public $_session = null;
18         public $_sessionId = '';
19     /**
20      * Create test user
21      *
22      */
23         public function setUp() 
24     {
25         
26         $this->markTestSkipped('Skipping for now while investigating');         
27         //setup test portal user
28         $this->_setupTestUser();
29         $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'].'/soap.php',false,false,false,false,false,600,600);
30         $this->_login();
31         
32         //setup test account
33                 $account = new Account();
34         $account->name = 'test account for bug 39855';
35         $account->assigned_user_id = 'SugarUser';
36         $account->save();
37         $this->_acc = $account;
38         
39         //setup test cases
40                 $case1 = new aCase();
41         $case1->name = 'test case for bug 39855 ASDF';
42         $case1->account_id = $this->_acc->id;
43         $case1->status = 'New';
44         $case1->save();
45         $this->_case1 = $case1;
46
47         $case2 = new aCase();
48                 //$account->id = 'a_'.$unid;
49         $case2->name = 'test case for bug 39855 QWER';
50         $case2->account_id = $this->_acc->id;
51         $case2->status = 'Rejected';
52         $case2->save();
53         $this->_case2 = $case2;
54         
55         
56     }
57
58     /**
59      * Remove anything that was used during this test
60      *
61      */
62     public function tearDown() {
63         global $soap_version_test_accountId, $soap_version_test_opportunityId, $soap_version_test_contactId;
64         $this->_tearDownTestUser();
65         $this->_user = null;
66         $this->_sessionId = '';
67         $GLOBALS['db']->query("DELETE FROM cases WHERE name like 'test case for bug 39855%'");
68         $GLOBALS['db']->query("DELETE FROM accounts WHERE name like 'test account for bug 39855%'");
69         
70         unset($this->_case1);
71         unset($this->_case2);
72         unset($this->_acc1);
73         
74     }   
75     
76     public function testGetEntry() {
77         //test retrieving a case by id
78         $result =  $this->_soapClient->call('portal_get_entry',array('session'=>$this->_sessionId,'module_name'=>'Cases','id'=>$this->_case1->id ,'select_field'=>array('case_number','status', 'name','description')));
79                 $this->assertTrue($result['entry_list'][0]['id'] == $this->_case1->id,'portal_get_entry was not able to retrieve a case record by id');
80
81         $result =  $this->_soapClient->call('portal_logout',array('session' => $this->_sessionId));
82     }
83     
84      public function testGetEntryList() {
85         $w = " name LIKE 'test case for bug 39855 %' ";
86         
87         $result =  $this->_soapClient->call('portal_get_entry_list',array('session'=>$this->_sessionId,'module_name'=>'Cases','where'=>$w ,'', 'select_field'=>array('case_number','status', 'name','description')));
88                 $this->assertTrue($result['result_count'] > 1,'portal_get_entry_list was not able to retrieve both cases using the following where clause: '.$w);
89
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         $result = $this->_soapClient->call('portal_login',
105             array('user_auth' => 
106                 array('user_name' => $this->_user->user_name,
107                     'password' => $this->_user->user_hash, 
108                     'version' => '.01'), 
109                         'user_name' =>'portal',
110                 'application_name' => 'SoapTestPortal')
111             );
112         $this->_sessionId = $result['id'];
113                 return $result;
114                 
115     }
116     
117  /**
118      * Create a test portal user
119      *
120      */
121         public function _setupTestUser() {
122         $this->_user = SugarTestUserUtilities::createAnonymousUser();
123         $this->_user->status = 'Active';
124         $this->_user->portal_only = 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 ?>