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'=>''),
130 array('name'=>'do_not_call', 'value'=>'1'),
135 $result = $this->_soapClient->call('set_entries',$contacts_list);
136 $this->_resultId = $result['ids'][0];
137 $this->assertEquals($this->c->id, $result['ids'][0], 'Found duplicate');
139 $existingContact = new Contact();
140 $existingContact->retrieve($this->c->id);
142 $this->assertEquals('867-5309', $existingContact->phone_mobile, 'Assert that we have not changed the phone_mobile field from first sync');
143 $this->assertEquals('Jenny - I Got Your Number', $existingContact->title, 'Assert that we have not changed the title field from first sync');
144 $this->assertEquals(1, $existingContact->do_not_call, 'Assert the field "do_not_call" checkbox was checked and has value of 1');
146 $result = $GLOBALS['db']->query("SELECT count(id) AS total FROM contacts WHERE first_name = '{$existingContact->first_name}' AND last_name = '{$existingContact->last_name}'");
147 $row = $GLOBALS['db']->fetchByAssoc($result);
148 $this->assertEquals(1, $row['total'], 'Assert we only have one Contact with the first and last name');
150 //Now sync a second time
152 $contacts_list=array(
153 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
154 'name_value_lists' => array(
156 array('name'=>'assigned_user_id' , 'value'=>"{$current_user->id}"),
157 array('name'=>'first_name' , 'value'=>"{$this->c->first_name}"),
158 array('name'=>'last_name' , 'value'=>"{$this->c->last_name}"),
159 array('name'=>'email1' , 'value'=>'noblankfieldupdateonfirstsync@example.com'),
160 array('name'=>'phone_mobile', 'value'=>'1-800-SUGARCRM'),
161 array('name'=>'contacts_users_id', 'value'=>"{$current_user->id}"),
162 array('name'=>'title', 'value'=>''),
163 array('name'=>'do_not_call', 'value'=>'0'),
168 $result = $this->_soapClient->call('set_entries',$contacts_list);
169 $this->_resultId = $result['ids'][0];
170 $this->assertEquals($this->c->id, $result['ids'][0], 'Found duplicate');
172 $existingContact = new Contact();
173 $existingContact->retrieve($this->c->id);
175 $this->assertEquals('1-800-SUGARCRM', $existingContact->phone_mobile, 'Assert that we have changed the phone_mobile field from second sync');
176 $this->assertEquals('', $existingContact->title, 'Assert that we have changed the title field to be (blank) from second sync');
177 $this->assertEquals(0, $existingContact->do_not_call, 'Assert the field "do_not_call" checkbox was UN-checked and has value of 0');
179 $result = $GLOBALS['db']->query("SELECT count(id) AS total FROM contacts WHERE first_name = '{$existingContact->first_name}' AND last_name = '{$existingContact->last_name}'");
180 $row = $GLOBALS['db']->fetchByAssoc($result);
181 $this->assertEquals(1, $row['total'], 'Assert we only have one Contact with the first and last name');
185 public function testNoEmailsFindsDuplicates()
187 global $current_user;
189 $contacts_list=array(
190 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
191 'name_value_lists' => array(
193 array('name'=>'assigned_user_id' , 'value'=>"{$current_user->id}"),
194 array('name'=>'first_name' , 'value'=>"{$this->c2->first_name}"),
195 array('name'=>'last_name' , 'value'=>"{$this->c2->last_name}"),
196 array('name'=>'email1' , 'value'=>''),
197 array('name'=>'email2', 'value'=>''),
198 array('name'=>'phone_mobile', 'value'=>''),
199 array('name'=>'contacts_users_id', 'value'=>"{$current_user->id}"),
200 array('name'=>'title', 'value'=>''),
205 $result = $this->_soapClient->call('set_entries',$contacts_list);
206 $this->_resultId2 = $result['ids'][0];
207 $this->assertEquals($this->c2->id, $result['ids'][0], 'Found duplicate when both records have no email');
209 $existingContact = new Contact();
210 $existingContact->retrieve($this->c2->id);
212 $this->assertEquals('867-5309', $existingContact->phone_mobile, 'Assert that we have not changed the phone_mobile field from first sync');
213 $this->assertEquals('Jenny - I Got Your Number', $existingContact->title, 'Assert that we have not changed the title field from first sync');
215 $result = $GLOBALS['db']->query("SELECT count(id) AS total FROM contacts WHERE first_name = '{$existingContact->first_name}' AND last_name = '{$existingContact->last_name}'");
216 $row = $GLOBALS['db']->fetchByAssoc($result);
217 $this->assertEquals(1, $row['total'], 'Assert we only have one Contact with the first and last name');
219 //Now sync a second time
221 $contacts_list=array(
222 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
223 'name_value_lists' => array(
225 array('name'=>'assigned_user_id' , 'value'=>"{$current_user->id}"),
226 array('name'=>'first_name' , 'value'=>"{$this->c2->first_name}"),
227 array('name'=>'last_name' , 'value'=>"{$this->c2->last_name}"),
228 array('name'=>'email1' , 'value'=>''),
229 array('name'=>'email2', 'value'=>''),
230 array('name'=>'phone_mobile', 'value'=>'1-800-SUGARCRM'),
231 array('name'=>'contacts_users_id', 'value'=>"{$current_user->id}"),
232 array('name'=>'title', 'value'=>''),
237 $result = $this->_soapClient->call('set_entries',$contacts_list);
239 $existingContact = new Contact();
240 $existingContact->retrieve($this->c2->id);
242 $this->assertEquals('1-800-SUGARCRM', $existingContact->phone_mobile, 'Assert that we have changed the phone_mobile field from second sync');
243 $this->assertEquals('', $existingContact->title, 'Assert that we have changed the title field to be (blank) from second sync');
244 $result = $GLOBALS['db']->query("SELECT count(id) AS total FROM contacts WHERE first_name = '{$existingContact->first_name}' AND last_name = '{$existingContact->last_name}'");
245 $row = $GLOBALS['db']->fetchByAssoc($result);
246 $this->assertEquals(1, $row['total'], 'Assert we only have one Contact with the first and last name');