]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/Bug44280Test.php
Release 6.4.0
[Github/sugarcrm.git] / tests / service / Bug44280Test.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 'tests/service/SOAPTestCase.php';
39
40
41 /**
42  * @group bug44280
43  */
44 class Bug44280Test extends SOAPTestCase
45 {
46     public $accnt1;
47     public $accnt2;
48     public $cont1;
49     public $cont2;
50
51         public function setUp()
52     {
53         $this->_soapURL = $GLOBALS['sugar_config']['site_url'].'/service/v2/soap.php';
54         parent::setUp();
55     }
56
57     /**
58      * Remove anything that was used during this test
59      *
60      */
61     public function tearDown() {
62         $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->cont1->id}'");
63         $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->cont2->id}'");
64         $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id= '{$this->cont1->id}'");
65         $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id= '{$this->cont2->id}'");
66         $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$this->accnt1->id}'");
67         $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$this->accnt2->id}'");
68
69         unset($this->accnt1); unset($this->accnt2);
70         unset($this->cont1); unset($this->cont2);
71         parent::tearDown();
72     }
73
74     public function createAccount($name,$user_id) {
75         $account = new Account();
76                 $account->id = uniqid();
77         $account->name = $name;
78         $account->assigned_user_id = $user_id;
79         $account->new_with_id = true;
80         $account->disable_custom_fields = true;
81         $account->save();
82         $GLOBALS['db']->commit();
83         return $account;
84     }
85
86     public function createContact($first_name, $last_name, $email){
87         $contact = new Contact();
88                 $contact->id = uniqid();
89         $contact->first_name = $first_name;
90         $contact->last_name = $last_name;
91         $contact->email1 = $email;
92         $contact->new_with_id = true;
93         $contact->disable_custom_fields = true;
94         $contact->save();
95         $GLOBALS['db']->commit();
96         return $contact;
97     }
98
99     public function testSetEntries() {
100         $this->_login();
101
102         // first create two accounts with identical account names
103         $this->accnt1 = $this->createAccount("sugar_account_name","sugarUser1");
104         $this->accnt2 = $this->createAccount("sugar_account_name","sugarUser2");
105
106         // now creating two contacts and relate them to the above accounts
107
108         $this->cont1 = $this->createContact("first1", "last1", "adsf@asdf.com");
109         $this->cont2 = $this->createContact("first2", "last2", "adsf@asdf.com");
110
111          // this will be used in set_entries call
112         $accounts_list=array( 'session'=>$this->_sessionId, 'module_name' => 'Accounts',
113                                    'name_value_lists' => array(
114                                         array(
115                                            array('name'=>'id','value'=>$this->accnt1->id),
116                                            array('name'=>'first_name','value'=>$this->accnt1->name),
117                                            array('name'=>'account_id','value'=>$this->accnt1->id),
118                                            array('name'=>'team_id','value'=>'1'),
119                                            array('name'=>'soap_dts_c','value'=>'2011-06-02 17:37:49'),
120                                            array('name'=>'contactid_4d_c','value'=>'123456'),
121                                            array('name'=>'phone_work','value'=>'1234567890'),
122                                            array('name'=>'title','value'=>''),
123                                        ),
124                                         array(
125                                            array('name'=>'id','value'=>$this->accnt2->id),
126                                            array('name'=>'first_name','value'=>$this->accnt2->name),
127                                            array('name'=>'account_id','value'=>$this->accnt2->id),
128                                            array('name'=>'team_id','value'=>'1'),
129                                            array('name'=>'soap_dts_c','value'=>'2011-06-02 16:37:49'),
130                                            array('name'=>'contactid_4d_c','value'=>'999991'),
131                                            array('name'=>'phone_work','value'=>'987654321'),
132                                            array('name'=>'title','value'=>''),
133                                        )
134                                         )
135                                        );
136         // add the accounts
137          $result = $this->_soapClient->call('set_entries', $accounts_list);
138
139         // add the contacts & set the relationship to account
140         $contacts_list = array( 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
141                                    'name_value_lists' => array(
142                                         array(
143                                            array('name'=>'last_name','value'=>$this->cont1->last_name),
144                                            array('name'=>'email','value'=>$this->cont1->email1),
145                                            array('name'=>'first_name','value'=>$this->cont1->first_name),
146                                            array('name'=>'id','value'=>$this->cont1->id),
147                                            array('name'=>'account_name','value'=>$this->accnt1->name),
148                                            array('name'=>'account_id','value'=>$this->accnt1->id),
149
150
151                                        ),
152                                         array(
153                                             array('name'=>'last_name','value'=>$this->cont2->last_name),
154                                             array('name'=>'email','value'=>$this->cont2->email1),
155                                             array('name'=>'first_name','value'=>$this->cont2->first_name),
156                                             array('name'=>'id','value'=>$this->cont2->id),
157                                             array('name'=>'account_name','value'=>$this->accnt2->name),
158                                             array('name'=>'account_id','value'=>$this->accnt2->id),
159
160                                        )
161                                         )
162                                        );
163
164
165         $result2 = $this->_soapClient->call('set_entries', $contacts_list);
166
167          // lets check first relationship
168         $query1 = "SELECT account_id FROM accounts_contacts WHERE contact_id='{$this->cont1->id}'";
169         $cont1_account_result = $GLOBALS['db']->query($query1,true,"");
170         $row1 = $GLOBALS['db']->fetchByAssoc($cont1_account_result);
171         if(isset($row1) ){
172
173             $this->assertEquals($this->accnt1->id, $row1["account_id"], "check first account-contact relationship");
174
175           }
176
177
178           // lets check second relationship
179         $query2 = "SELECT account_id FROM accounts_contacts WHERE contact_id='{$this->cont2->id}'";
180         $cont2_account_result = $GLOBALS['db']->query($query2,true,"");
181         $row2 = $GLOBALS['db']->fetchByAssoc($cont2_account_result);
182         if(isset($row2) ){
183
184             $this->assertEquals($this->accnt2->id, $row2["account_id"], "check second account-contact relationship");
185
186           }
187
188
189     }
190
191
192     /**
193      * Attempt to login to the soap server
194      *
195      * @return $set_entry_result - this should contain an id and error.  The id corresponds
196      * to the session_id.
197      */
198     public function _login(){
199                 global $current_user;
200         $result = $this->_soapClient->call('login',
201             array('user_auth' =>
202                 array('user_name' => $current_user->user_name,
203                     'password' => $current_user->user_hash,
204                     'version' => '1.0'),
205                 'application_name' => 'SoapTest')
206             );
207          $this->_sessionId = $result['id'];
208                 return $result;
209     }
210
211
212
213 }
214 ?>