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('include/nusoap/nusoap.php');
44 class Bug39234Test extends Sugar_PHPUnit_Framework_TestCase
47 public $_soapClient = null;
48 public $_session = null;
49 public $_sessionId = '';
50 public $_contactId = '';
59 public function setUp()
61 $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'].'/soap.php',false,false,false,false,false,600,600);
62 $this->_setupTestUser();
66 require('include/modules.php');
67 $GLOBALS['beanList'] = $beanList;
68 $GLOBALS['beanFiles'] = $beanFiles;
71 $time = date('Y-m-d H:i:s');
73 $contact = new Contact();
74 $contact->id = 'c_'.$unid;
75 $contact->first_name = 'testfirst';
76 $contact->last_name = 'testlast';
77 $contact->email1 = 'fred@rogers.com';
78 $contact->new_with_id = true;
79 $contact->disable_custom_fields = true;
83 $account = new Account();
84 $account->id = 'a_'.$unid;
85 $account->name = 'acctfirst';
86 $account->assigned_user_id = 'SugarUser';
87 $account->new_with_id = true;
88 $account->disable_custom_fields = true;
92 $this->c1->load_relationship('accounts');
93 $this->c1->accounts->add($this->a1->id);
95 $contact2 = new Contact();
96 $contact2->id = 'c2_'.$unid;
97 $contact2->first_name = 'testfirst';
98 $contact2->last_name = 'testlast';
99 $contact2->email1 = 'fred@rogers.com';
100 $contact2->new_with_id = true;
101 $contact2->disable_custom_fields = true;
103 $this->c2 = $contact2;
107 * Remove anything that was used during this test
110 public function tearDown() {
111 global $soap_version_test_accountId, $soap_version_test_opportunityId, $soap_version_test_contactId;
112 $this->_tearDownTestUser();
114 $this->_sessionId = '';
115 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->c1->id}'");
116 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->c2->id}'");
117 $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id= '{$this->c1->id}'");
118 $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id= '{$this->c2->id}'");
119 $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$this->a1->id}'");
120 $GLOBALS['db']->query("DELETE FROM accounts WHERE name = 'joe pizza'");
124 unset($soap_version_test_accountId);
125 unset($soap_version_test_opportunityId);
126 unset($soap_version_test_contactId);
128 unset($GLOBALS['beanList']);
129 unset($GLOBALS['beanFiles']);
132 public function testSetEntries() {
134 $result = $this->_soapClient->call('set_entries',array('session'=>$this->_sessionId,'module_name' => 'Contacts','name_value_lists' => array(array(array('name'=>'last_name' , 'value'=>$this->c1->last_name), array('name'=>'email1' , 'value'=>$this->c1->email1), array('name'=>'first_name' , 'value'=>$this->c1->first_name), array('name'=>'account_name' , 'value'=>$this->a1->name)))));
135 $this->assertTrue(isset($result['ids']));
136 $this->assertEquals($result['ids'][0],$this->c1->id);
139 public function testSetEntries2() {
141 $result = $this->_soapClient->call('set_entries',array('session'=>$this->_sessionId,'module_name' => 'Contacts','name_value_lists' => array(array(array('name'=>'last_name' , 'value'=>$this->c2->last_name), array('name'=>'email1' , 'value'=>$this->c2->email1), array('name'=>'first_name' , 'value'=>$this->c2->first_name), array('name'=>'account_name' , 'value'=>'joe pizza')))));
142 $this->assertTrue(isset($result['ids']));
143 $this->assertNotEquals($result['ids'][0],$this->c1->id);
146 /**********************************
147 * HELPER PUBLIC FUNCTIONS
148 **********************************/
151 * Attempt to login to the soap server
153 * @return $set_entry_result - this should contain an id and error. The id corresponds
156 public function _login(){
157 global $current_user;
158 $GLOBALS['db']->commit(); // Making sure we commit any changes before logging in
159 $result = $this->_soapClient->call('login',
161 array('user_name' => $current_user->user_name,
162 'password' => $current_user->user_hash,
164 'application_name' => 'SoapTest')
166 $this->_sessionId = $result['id'];
174 public function _setupTestUser() {
175 $this->_user = SugarTestUserUtilities::createAnonymousUser();
176 $this->_user->status = 'Active';
177 $this->_user->is_admin = 1;
178 $this->_user->save();
179 $GLOBALS['current_user'] = $this->_user;
183 * Remove user created for test
186 public function _tearDownTestUser() {
187 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
188 unset($GLOBALS['current_user']);