]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/NoBlankFieldUpdateOnFirstSyncTest.php
Release 6.4.0
[Github/sugarcrm.git] / tests / service / NoBlankFieldUpdateOnFirstSyncTest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37
38
39 /**
40  * NoBlankFieldUpdateOnFirstSyncTest.php
41  *
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.
48  * 
49  * @author Collin Lee
50  */
51
52 require_once('include/nusoap/nusoap.php');
53 require_once('tests/service/SOAPTestCase.php');
54
55 class NoBlankFieldUpdateOnFirstSyncTest extends SOAPTestCase
56 {
57         public $_soapClient = null;
58     var $_sessionId;
59     var $_resultId;
60     var $_resultId2;
61     var $c = null;
62     var $c2 = null;
63
64         public function setUp()
65     {
66         global $current_user;
67         $this->_soapURL = $GLOBALS['sugar_config']['site_url'].'/soap.php';
68
69         //Clean up any possible contacts not deleted
70         $GLOBALS['db']->query("DELETE FROM contacts WHERE first_name = 'NoBlankFieldUpdate' AND last_name = 'OnFirstSyncTest'");
71
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;
80         $contact->save();
81                 $this->c = $contact;
82
83         $GLOBALS['db']->query("DELETE FROM contacts WHERE first_name = 'Collin' AND last_name = 'Lee'");
84
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 = '';
94         $contact2->save();
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}'");
98         parent::setUp();
99         $this->useOutputBuffering = false;
100     }
101
102     public function tearDown()
103     {
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         unset($this->c);
109         unset($this->c2);
110         parent::tearDown();
111     }
112
113
114     public function testNoBlankFieldUpdateOnFirstSyncTest()
115     {
116         global $current_user;
117         $this->_login();
118         $contacts_list=array(
119                               'session'=>$this->_sessionId, 'module_name' => 'Contacts',
120                                               'name_value_lists' => array(
121                                         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'=>''),
129                                         )
130                               )
131                         );
132
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');
136
137         $existingContact = new Contact();
138         $existingContact->retrieve($this->c->id);
139
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');
142
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');
145
146         //Now sync a second time
147         $this->_login();
148         $contacts_list=array(
149                               'session'=>$this->_sessionId, 'module_name' => 'Contacts',
150                                               'name_value_lists' => array(
151                                         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'=>''),
159                                         )
160                               )
161                         );
162
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');
166         
167         $existingContact = new Contact();
168         $existingContact->retrieve($this->c->id);
169
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');
174     }
175     
176
177     public function testNoEmailsFindsDuplicates()
178     {
179         global $current_user;
180         $this->_login();
181         $contacts_list=array(
182                               'session'=>$this->_sessionId, 'module_name' => 'Contacts',
183                                               'name_value_lists' => array(
184                                         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'=>''),
193                                         )
194                               )
195                         );
196
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');
200
201         $existingContact = new Contact();
202         $existingContact->retrieve($this->c2->id);
203
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');
206
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');
209
210         //Now sync a second time
211         $this->_login();
212         $contacts_list=array(
213                               'session'=>$this->_sessionId, 'module_name' => 'Contacts',
214                                               'name_value_lists' => array(
215                                         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'=>''),
224                                         )
225                               )
226                         );
227
228         $result = $this->_soapClient->call('set_entries',$contacts_list);
229
230         $existingContact = new Contact();
231         $existingContact->retrieve($this->c2->id);
232
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');
237     }
238
239 }
240
241 ?>