2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 require_once 'tests/service/SOAPTestCase.php';
44 class Bug44280Test extends SOAPTestCase
51 public function setUp()
53 $this->_soapURL = $GLOBALS['sugar_config']['site_url'].'/service/v2/soap.php';
58 * Remove anything that was used during this test
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}'");
69 unset($this->accnt1); unset($this->accnt2);
70 unset($this->cont1); unset($this->cont2);
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;
82 $GLOBALS['db']->commit();
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;
95 $GLOBALS['db']->commit();
99 public function testSetEntries() {
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");
106 // now creating two contacts and relate them to the above accounts
108 $this->cont1 = $this->createContact("first1", "last1", "adsf@asdf.com");
109 $this->cont2 = $this->createContact("first2", "last2", "adsf@asdf.com");
111 // this will be used in set_entries call
112 $accounts_list=array( 'session'=>$this->_sessionId, 'module_name' => 'Accounts',
113 'name_value_lists' => 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'=>''),
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'=>''),
137 $result = $this->_soapClient->call('set_entries', $accounts_list);
139 // add the contacts & set the relationship to account
140 $contacts_list = array( 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
141 'name_value_lists' => 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),
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),
165 $result2 = $this->_soapClient->call('set_entries', $contacts_list);
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);
173 $this->assertEquals($this->accnt1->id, $row1["account_id"], "check first account-contact relationship");
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);
184 $this->assertEquals($this->accnt2->id, $row2["account_id"], "check second account-contact relationship");
193 * Attempt to login to the soap server
195 * @return $set_entry_result - this should contain an id and error. The id corresponds
198 public function _login(){
199 global $current_user;
200 $result = $this->_soapClient->call('login',
202 array('user_name' => $current_user->user_name,
203 'password' => $current_user->user_hash,
205 'application_name' => 'SoapTest')
207 $this->_sessionId = $result['id'];