]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/Bug39855Test.php
Release 6.2.0
[Github/sugarcrm.git] / tests / service / Bug39855Test.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/Cases/Case.php');
40 require_once('modules/Accounts/Account.php');
41
42
43 /**
44  * @group bug39234
45  */
46 class Bug39855Test extends Sugar_PHPUnit_Framework_TestCase
47 {
48         public $_user = null;
49         public $_case1 = null;
50         public $_case2 = null;
51         public $_acc = null;
52         public $_soapClient = null;
53         public $_session = null;
54         public $_sessionId = '';
55     /**
56      * Create test user
57      *
58      */
59         public function setUp() 
60     {
61         
62         $this->markTestSkipped('Skipping for now while investigating');         
63         //setup test portal user
64         $this->_setupTestUser();
65         $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'].'/soap.php',false,false,false,false,false,600,600);
66         $this->_login();
67         
68         //setup test account
69                 $account = new Account();
70         $account->name = 'test account for bug 39855';
71         $account->assigned_user_id = 'SugarUser';
72         $account->save();
73         $this->_acc = $account;
74         
75         //setup test cases
76                 $case1 = new aCase();
77         $case1->name = 'test case for bug 39855 ASDF';
78         $case1->account_id = $this->_acc->id;
79         $case1->status = 'New';
80         $case1->save();
81         $this->_case1 = $case1;
82
83         $case2 = new aCase();
84                 //$account->id = 'a_'.$unid;
85         $case2->name = 'test case for bug 39855 QWER';
86         $case2->account_id = $this->_acc->id;
87         $case2->status = 'Rejected';
88         $case2->save();
89         $this->_case2 = $case2;
90         
91         
92     }
93
94     /**
95      * Remove anything that was used during this test
96      *
97      */
98     public function tearDown() {
99         global $soap_version_test_accountId, $soap_version_test_opportunityId, $soap_version_test_contactId;
100         $this->_tearDownTestUser();
101         $this->_user = null;
102         $this->_sessionId = '';
103         $GLOBALS['db']->query("DELETE FROM cases WHERE name like 'test case for bug 39855%'");
104         $GLOBALS['db']->query("DELETE FROM accounts WHERE name like 'test account for bug 39855%'");
105         
106         unset($this->_case1);
107         unset($this->_case2);
108         unset($this->_acc1);
109         
110     }   
111     
112     public function testGetEntry() {
113         //test retrieving a case by id
114         $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')));
115                 $this->assertTrue($result['entry_list'][0]['id'] == $this->_case1->id,'portal_get_entry was not able to retrieve a case record by id');
116
117         $result =  $this->_soapClient->call('portal_logout',array('session' => $this->_sessionId));
118     }
119     
120      public function testGetEntryList() {
121         $w = " name LIKE 'test case for bug 39855 %' ";
122         
123         $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')));
124                 $this->assertTrue($result['result_count'] > 1,'portal_get_entry_list was not able to retrieve both cases using the following where clause: '.$w);
125
126     } 
127     
128         /**********************************
129      * HELPER PUBLIC FUNCTIONS
130      **********************************/
131     
132     /**
133      * Attempt to login to the soap server
134      *
135      * @return $set_entry_result - this should contain an id and error.  The id corresponds
136      * to the session_id.
137      */
138     public function _login(){
139                 global $current_user;   
140         $result = $this->_soapClient->call('portal_login',
141             array('user_auth' => 
142                 array('user_name' => $this->_user->user_name,
143                     'password' => $this->_user->user_hash, 
144                     'version' => '.01'), 
145                         'user_name' =>'portal',
146                 'application_name' => 'SoapTestPortal')
147             );
148         $this->_sessionId = $result['id'];
149                 return $result;
150                 
151     }
152     
153  /**
154      * Create a test portal user
155      *
156      */
157         public function _setupTestUser() {
158         $this->_user = SugarTestUserUtilities::createAnonymousUser();
159         $this->_user->status = 'Active';
160         $this->_user->portal_only = 1;
161         $this->_user->save();
162     }
163     
164
165         
166     /**
167      * Remove user created for test
168      *
169      */
170         public function _tearDownTestUser() {
171        SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
172     }
173         
174 }
175 ?>