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 ********************************************************************************/
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 $this->useOutputBuffering = false;
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}'");
114 public function testNoBlankFieldUpdateOnFirstSyncTest()
116 global $current_user;
118 $contacts_list=array(
119 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
120 'name_value_lists' => array(
122 array('name'=>'assigned_user_id' , 'value'=>"{$current_user->id}"),
123 array('name'=>'first_name' , 'value'=>"{$this->c->first_name}"),
124 array('name'=>'last_name' , 'value'=>"{$this->c->last_name}"),
125 array('name'=>'email1' , 'value'=>'noblankfieldupdateonfirstsync@example.com'),
126 array('name'=>'phone_mobile', 'value'=>''),
127 array('name'=>'contacts_users_id', 'value'=>"{$current_user->id}"),
128 array('name'=>'title', 'value'=>''),
133 $result = $this->_soapClient->call('set_entries',$contacts_list);
134 $this->_resultId = $result['ids'][0];
135 $this->assertEquals($this->c->id, $result['ids'][0], 'Found duplicate');
137 $existingContact = new Contact();
138 $existingContact->retrieve($this->c->id);
140 $this->assertEquals('867-5309', $existingContact->phone_mobile, 'Assert that we have not changed the phone_mobile field from first sync');
141 $this->assertEquals('Jenny - I Got Your Number', $existingContact->title, 'Assert that we have not changed the title field from first sync');
143 $result = $GLOBALS['db']->getOne("SELECT count(id) AS total FROM contacts WHERE first_name = '{$existingContact->first_name}' AND last_name = '{$existingContact->last_name}'");
144 $this->assertEquals(1, $result['total'], 'Assert we only have one Contact with the first and last name');
146 //Now sync a second time
148 $contacts_list=array(
149 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
150 'name_value_lists' => array(
152 array('name'=>'assigned_user_id' , 'value'=>"{$current_user->id}"),
153 array('name'=>'first_name' , 'value'=>"{$this->c->first_name}"),
154 array('name'=>'last_name' , 'value'=>"{$this->c->last_name}"),
155 array('name'=>'email1' , 'value'=>'noblankfieldupdateonfirstsync@example.com'),
156 array('name'=>'phone_mobile', 'value'=>'1-800-SUGARCRM'),
157 array('name'=>'contacts_users_id', 'value'=>"{$current_user->id}"),
158 array('name'=>'title', 'value'=>''),
163 $result = $this->_soapClient->call('set_entries',$contacts_list);
164 $this->_resultId = $result['ids'][0];
165 $this->assertEquals($this->c->id, $result['ids'][0], 'Found duplicate');
167 $existingContact = new Contact();
168 $existingContact->retrieve($this->c->id);
170 $this->assertEquals('1-800-SUGARCRM', $existingContact->phone_mobile, 'Assert that we have changed the phone_mobile field from second sync');
171 $this->assertEquals('', $existingContact->title, 'Assert that we have changed the title field to be (blank) from second sync');
172 $result = $GLOBALS['db']->getOne("SELECT count(id) AS total FROM contacts WHERE first_name = '{$existingContact->first_name}' AND last_name = '{$existingContact->last_name}'");
173 $this->assertEquals(1, $result['total'], 'Assert we only have one Contact with the first and last name');
177 public function testNoEmailsFindsDuplicates()
179 global $current_user;
181 $contacts_list=array(
182 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
183 'name_value_lists' => array(
185 array('name'=>'assigned_user_id' , 'value'=>"{$current_user->id}"),
186 array('name'=>'first_name' , 'value'=>"{$this->c2->first_name}"),
187 array('name'=>'last_name' , 'value'=>"{$this->c2->last_name}"),
188 array('name'=>'email1' , 'value'=>''),
189 array('name'=>'email2', 'value'=>''),
190 array('name'=>'phone_mobile', 'value'=>''),
191 array('name'=>'contacts_users_id', 'value'=>"{$current_user->id}"),
192 array('name'=>'title', 'value'=>''),
197 $result = $this->_soapClient->call('set_entries',$contacts_list);
198 $this->_resultId2 = $result['ids'][0];
199 $this->assertEquals($this->c2->id, $result['ids'][0], 'Found duplicate when both records have no email');
201 $existingContact = new Contact();
202 $existingContact->retrieve($this->c2->id);
204 $this->assertEquals('867-5309', $existingContact->phone_mobile, 'Assert that we have not changed the phone_mobile field from first sync');
205 $this->assertEquals('Jenny - I Got Your Number', $existingContact->title, 'Assert that we have not changed the title field from first sync');
207 $result = $GLOBALS['db']->getOne("SELECT count(id) AS total FROM contacts WHERE first_name = '{$existingContact->first_name}' AND last_name = '{$existingContact->last_name}'");
208 $this->assertEquals(1, $result['total'], 'Assert we only have one Contact with the first and last name');
210 //Now sync a second time
212 $contacts_list=array(
213 'session'=>$this->_sessionId, 'module_name' => 'Contacts',
214 'name_value_lists' => array(
216 array('name'=>'assigned_user_id' , 'value'=>"{$current_user->id}"),
217 array('name'=>'first_name' , 'value'=>"{$this->c2->first_name}"),
218 array('name'=>'last_name' , 'value'=>"{$this->c2->last_name}"),
219 array('name'=>'email1' , 'value'=>''),
220 array('name'=>'email2', 'value'=>''),
221 array('name'=>'phone_mobile', 'value'=>'1-800-SUGARCRM'),
222 array('name'=>'contacts_users_id', 'value'=>"{$current_user->id}"),
223 array('name'=>'title', 'value'=>''),
228 $result = $this->_soapClient->call('set_entries',$contacts_list);
230 $existingContact = new Contact();
231 $existingContact->retrieve($this->c2->id);
233 $this->assertEquals('1-800-SUGARCRM', $existingContact->phone_mobile, 'Assert that we have changed the phone_mobile field from second sync');
234 $this->assertEquals('', $existingContact->title, 'Assert that we have changed the title field to be (blank) from second sync');
235 $result = $GLOBALS['db']->getOne("SELECT count(id) AS total FROM contacts WHERE first_name = '{$existingContact->first_name}' AND last_name = '{$existingContact->last_name}'");
236 $this->assertEquals(1, $result['total'], 'Assert we only have one Contact with the first and last name');