2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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('include/nusoap/nusoap.php');
44 class Bug44280Test extends Sugar_PHPUnit_Framework_TestCase
47 public $_soapClient = null;
48 public $_session = null;
49 public $_sessionId = null;
57 public function setUp()
59 $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'].'/service/v2/soap.php',false,false,false,false,false,600,600);
61 $this->_user = SugarTestUserUtilities::createAnonymousUser();
62 $this->_user->status = 'Active';
63 $this->_user->is_admin = 1;
65 $GLOBALS['current_user'] = $this->_user;
73 * Remove anything that was used during this test
76 public function tearDown() {
77 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
78 unset($GLOBALS['current_user']);
81 unset($this->_soapClient);
82 unset($this->_session);
83 unset($this->_sessionId);
85 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->cont1->id}'");
86 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->cont2->id}'");
87 $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id= '{$this->cont1->id}'");
88 $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id= '{$this->cont2->id}'");
89 $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$this->accnt1->id}'");
90 $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$this->accnt2->id}'");
92 unset($this->accnt1); unset($this->accnt2);
93 unset($this->cont1); unset($this->cont2);
97 public function createAccount($name,$user_id) {
98 $account = new Account();
99 $account->id = uniqid();
100 $account->name = $name;
101 $account->assigned_user_id = $user_id;
102 $account->new_with_id = true;
103 $account->disable_custom_fields = true;
109 public function createContact($first_name, $last_name, $email){
110 $contact = new Contact();
111 $contact->id = uniqid();
112 $contact->first_name = $first_name;
113 $contact->last_name = $last_name;
114 $contact->email1 = $email;
115 $contact->new_with_id = true;
116 $contact->disable_custom_fields = true;
122 public function testSetEntries() {
125 // first create two accounts with identical account names
126 $this->accnt1 = $this->createAccount("sugar_account_name","sugarUser1");
127 $this->accnt2 = $this->createAccount("sugar_account_name","sugarUser2");
129 // now creating two contacts and relate them to the above accounts
131 $this->cont1 = $this->createContact("first1", "last1", "adsf@asdf.com");
132 $this->cont2 = $this->createContact("first2", "last2", "adsf@asdf.com");
134 // this will be used in set_entries call
135 $accounts_list=array( 'session'=>$this->_sessionId, 'module_name' => 'Accounts',
136 'name_value_lists' => array(
138 array('name'=>'id','value'=>$this->accnt1->id),
139 array('name'=>'first_name','value'=>$this->accnt1->name),
140 array('name'=>'account_id','value'=>$this->accnt1->id),
141 array('name'=>'team_id','value'=>'1'),
142 array('name'=>'soap_dts_c','value'=>'2011-06-02 17:37:49'),
143 array('name'=>'contactid_4d_c','value'=>'123456'),
144 array('name'=>'phone_work','value'=>'1234567890'),
145 array('name'=>'title','value'=>''),
148 array('name'=>'id','value'=>$this->accnt2->id),
149 array('name'=>'first_name','value'=>$this->accnt2->name),
150 array('name'=>'account_id','value'=>$this->accnt2->id),
151 array('name'=>'team_id','value'=>'1'),
152 array('name'=>'soap_dts_c','value'=>'2011-06-02 16:37:49'),
153 array('name'=>'contactid_4d_c','value'=>'999991'),
154 array('name'=>'phone_work','value'=>'987654321'),
155 array('name'=>'title','value'=>''),
160 $result = $this->_soapClient->call('set_entries', $accounts_list);
162 // add the contacts & set the relationship to account
163 $contacts_list = array( 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
164 'name_value_lists' => array(
166 array('name'=>'last_name','value'=>$this->cont1->last_name),
167 array('name'=>'email','value'=>$this->cont1->email1),
168 array('name'=>'first_name','value'=>$this->cont1->first_name),
169 array('name'=>'id','value'=>$this->cont1->id),
170 array('name'=>'account_name','value'=>$this->accnt1->name),
171 array('name'=>'account_id','value'=>$this->accnt1->id),
176 array('name'=>'last_name','value'=>$this->cont2->last_name),
177 array('name'=>'email','value'=>$this->cont2->email1),
178 array('name'=>'first_name','value'=>$this->cont2->first_name),
179 array('name'=>'id','value'=>$this->cont2->id),
180 array('name'=>'account_name','value'=>$this->accnt2->name),
181 array('name'=>'account_id','value'=>$this->accnt2->id),
188 $result2 = $this->_soapClient->call('set_entries', $contacts_list);
190 // lets check first relationship
191 $query1 = "SELECT account_id FROM accounts_contacts WHERE contact_id='{$this->cont1->id}'";
192 $cont1_account_result = $GLOBALS['db']->query($query1,true,"");
193 $row1 = $GLOBALS['db']->fetchByAssoc($cont1_account_result);
196 $this->assertEquals($this->accnt1->id, $row1["account_id"], "check first account-contact relationship");
201 // lets check second relationship
202 $query2 = "SELECT account_id FROM accounts_contacts WHERE contact_id='{$this->cont2->id}'";
203 $cont2_account_result = $GLOBALS['db']->query($query2,true,"");
204 $row2 = $GLOBALS['db']->fetchByAssoc($cont2_account_result);
207 $this->assertEquals($this->accnt2->id, $row2["account_id"], "check second account-contact relationship");
216 * Attempt to login to the soap server
218 * @return $set_entry_result - this should contain an id and error. The id corresponds
221 public function _login(){
222 global $current_user;
223 $result = $this->_soapClient->call('login',
225 array('user_name' => $current_user->user_name,
226 'password' => $current_user->user_hash,
228 'application_name' => 'SoapTest')
230 $this->_sessionId = $result['id'];