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 ********************************************************************************/
40 * NoBlankFieldUpdateOnFirstSyncTest.php
42 * This unit test was written to test an Outlook Plugin Hotfix. It is attempting to mimic
43 * what would happen if a new Contact record was created in Sugar. Then a record with the same
44 * first and last name and a matching email was created in Outlook. With the Outlook settings
45 * set so that the Sugar server wins on conflicts, what was happening was that the new (blank) values
46 * from the Outlook plugin were overriding the SugarCRM record values. Under the new test what should
47 * happen is that blank values from the Outlook side do NOT wipe out the SugarCRM values on first sync.
52 require_once('include/nusoap/nusoap.php');
53 require_once('tests/service/SOAPTestCase.php');
55 class NoBlankFieldUpdateOnFirstSyncTest extends SOAPTestCase
57 public $_soapClient = null;
64 public function setUp()
67 $this->_soapURL = $GLOBALS['sugar_config']['site_url'].'/soap.php';
69 //Clean up any possible contacts not deleted
70 $GLOBALS['db']->query("DELETE FROM contacts WHERE first_name = 'NoBlankFieldUpdate' AND last_name = 'OnFirstSyncTest'");
72 $current_user = SugarTestUserUtilities::createAnonymousUser();
73 $contact = SugarTestContactUtilities::createContact();
74 $contact->first_name = 'NoBlankFieldUpdate';
75 $contact->last_name = 'OnFirstSyncTest';
76 $contact->phone_mobile = '867-5309';
77 $contact->email1 = 'noblankfieldupdateonfirstsync@example.com';
78 $contact->title = 'Jenny - I Got Your Number';
79 $contact->disable_custom_fields = true;
83 $GLOBALS['db']->query("DELETE FROM contacts WHERE first_name = 'Collin' AND last_name = 'Lee'");
85 //Manually create a contact entry
86 $contact2 = new Contact();
87 $contact2->title = 'Jenny - I Got Your Number';
88 $contact2->first_name = 'Collin';
89 $contact2->last_name = 'Lee';
90 $contact2->phone_mobile = '867-5309';
91 $contact2->disable_custom_fields = true;
92 $contact2->email1 = '';
93 $contact2->email2 = '';
95 $this->c2 = $contact2;
96 //DELETE contact_users entries that may have remained
97 $GLOBALS['db']->query("DELETE FROM contacts_users WHERE user_id = '{$current_user->id}'");
99 $GLOBALS['db']->commit();
102 public function tearDown()
104 global $current_user;
105 SugarTestContactUtilities::removeAllCreatedContacts();
106 $GLOBALS['db']->query("DELETE FROM contacts WHERE id in ('{$this->_resultId}', '{$this->_resultId2}')");
107 $GLOBALS['db']->query("DELETE FROM contacts_users WHERE user_id = '{$current_user->id}'");
108 $GLOBALS['db']->commit();
115 public function testNoBlankFieldUpdateOnFirstSyncTest()
117 global $current_user;
119 $contacts_list=array(
120 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
121 'name_value_lists' => array(
123 array('name'=>'assigned_user_id' , 'value'=>"{$current_user->id}"),
124 array('name'=>'first_name' , 'value'=>"{$this->c->first_name}"),
125 array('name'=>'last_name' , 'value'=>"{$this->c->last_name}"),
126 array('name'=>'email1' , 'value'=>'noblankfieldupdateonfirstsync@example.com'),
127 array('name'=>'phone_mobile', 'value'=>''),
128 array('name'=>'contacts_users_id', 'value'=>"{$current_user->id}"),
129 array('name'=>'title', 'value'=>''),
134 $result = $this->_soapClient->call('set_entries',$contacts_list);
135 $this->_resultId = $result['ids'][0];
136 $this->assertEquals($this->c->id, $result['ids'][0], 'Found duplicate');
138 $existingContact = new Contact();
139 $existingContact->retrieve($this->c->id);
141 $this->assertEquals('867-5309', $existingContact->phone_mobile, 'Assert that we have not changed the phone_mobile field from first sync');
142 $this->assertEquals('Jenny - I Got Your Number', $existingContact->title, 'Assert that we have not changed the title field from first sync');
144 $result = $GLOBALS['db']->query("SELECT count(id) AS total FROM contacts WHERE first_name = '{$existingContact->first_name}' AND last_name = '{$existingContact->last_name}'");
145 $row = $GLOBALS['db']->fetchByAssoc($result);
146 $this->assertEquals(1, $row['total'], 'Assert we only have one Contact with the first and last name');
148 //Now sync a second time
150 $contacts_list=array(
151 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
152 'name_value_lists' => array(
154 array('name'=>'assigned_user_id' , 'value'=>"{$current_user->id}"),
155 array('name'=>'first_name' , 'value'=>"{$this->c->first_name}"),
156 array('name'=>'last_name' , 'value'=>"{$this->c->last_name}"),
157 array('name'=>'email1' , 'value'=>'noblankfieldupdateonfirstsync@example.com'),
158 array('name'=>'phone_mobile', 'value'=>'1-800-SUGARCRM'),
159 array('name'=>'contacts_users_id', 'value'=>"{$current_user->id}"),
160 array('name'=>'title', 'value'=>''),
165 $result = $this->_soapClient->call('set_entries',$contacts_list);
166 $this->_resultId = $result['ids'][0];
167 $this->assertEquals($this->c->id, $result['ids'][0], 'Found duplicate');
169 $existingContact = new Contact();
170 $existingContact->retrieve($this->c->id);
172 $this->assertEquals('1-800-SUGARCRM', $existingContact->phone_mobile, 'Assert that we have changed the phone_mobile field from second sync');
173 $this->assertEquals('', $existingContact->title, 'Assert that we have changed the title field to be (blank) from second sync');
174 $result = $GLOBALS['db']->query("SELECT count(id) AS total FROM contacts WHERE first_name = '{$existingContact->first_name}' AND last_name = '{$existingContact->last_name}'");
175 $row = $GLOBALS['db']->fetchByAssoc($result);
176 $this->assertEquals(1, $row['total'], 'Assert we only have one Contact with the first and last name');
180 public function testNoEmailsFindsDuplicates()
182 global $current_user;
184 $contacts_list=array(
185 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
186 'name_value_lists' => array(
188 array('name'=>'assigned_user_id' , 'value'=>"{$current_user->id}"),
189 array('name'=>'first_name' , 'value'=>"{$this->c2->first_name}"),
190 array('name'=>'last_name' , 'value'=>"{$this->c2->last_name}"),
191 array('name'=>'email1' , 'value'=>''),
192 array('name'=>'email2', 'value'=>''),
193 array('name'=>'phone_mobile', 'value'=>''),
194 array('name'=>'contacts_users_id', 'value'=>"{$current_user->id}"),
195 array('name'=>'title', 'value'=>''),
200 $result = $this->_soapClient->call('set_entries',$contacts_list);
201 $this->_resultId2 = $result['ids'][0];
202 $this->assertEquals($this->c2->id, $result['ids'][0], 'Found duplicate when both records have no email');
204 $existingContact = new Contact();
205 $existingContact->retrieve($this->c2->id);
207 $this->assertEquals('867-5309', $existingContact->phone_mobile, 'Assert that we have not changed the phone_mobile field from first sync');
208 $this->assertEquals('Jenny - I Got Your Number', $existingContact->title, 'Assert that we have not changed the title field from first sync');
210 $result = $GLOBALS['db']->query("SELECT count(id) AS total FROM contacts WHERE first_name = '{$existingContact->first_name}' AND last_name = '{$existingContact->last_name}'");
211 $row = $GLOBALS['db']->fetchByAssoc($result);
212 $this->assertEquals(1, $row['total'], 'Assert we only have one Contact with the first and last name');
214 //Now sync a second time
216 $contacts_list=array(
217 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
218 'name_value_lists' => array(
220 array('name'=>'assigned_user_id' , 'value'=>"{$current_user->id}"),
221 array('name'=>'first_name' , 'value'=>"{$this->c2->first_name}"),
222 array('name'=>'last_name' , 'value'=>"{$this->c2->last_name}"),
223 array('name'=>'email1' , 'value'=>''),
224 array('name'=>'email2', 'value'=>''),
225 array('name'=>'phone_mobile', 'value'=>'1-800-SUGARCRM'),
226 array('name'=>'contacts_users_id', 'value'=>"{$current_user->id}"),
227 array('name'=>'title', 'value'=>''),
232 $result = $this->_soapClient->call('set_entries',$contacts_list);
234 $existingContact = new Contact();
235 $existingContact->retrieve($this->c2->id);
237 $this->assertEquals('1-800-SUGARCRM', $existingContact->phone_mobile, 'Assert that we have changed the phone_mobile field from second sync');
238 $this->assertEquals('', $existingContact->title, 'Assert that we have changed the title field to be (blank) from second sync');
239 $result = $GLOBALS['db']->query("SELECT count(id) AS total FROM contacts WHERE first_name = '{$existingContact->first_name}' AND last_name = '{$existingContact->last_name}'");
240 $row = $GLOBALS['db']->fetchByAssoc($result);
241 $this->assertEquals(1, $row['total'], 'Assert we only have one Contact with the first and last name');