]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/NoBlankFieldUpdateOnFirstSyncTest.php
Release 6.5.10
[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-2013 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         $GLOBALS['db']->commit();
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         $GLOBALS['db']->commit();
109         unset($this->c);
110         unset($this->c2);
111         parent::tearDown();
112     }
113
114
115     public function testNoBlankFieldUpdateOnFirstSyncTest()
116     {
117         global $current_user;
118         $this->_login();
119         $contacts_list=array(
120                               'session'=>$this->_sessionId, 'module_name' => 'Contacts',
121                                               'name_value_lists' => array(
122                                         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'),
131                                         )
132                               )
133                         );
134
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');
138
139         $existingContact = new Contact();
140         $existingContact->retrieve($this->c->id);
141
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');
145
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');
149
150         //Now sync a second time
151         $this->_login();
152         $contacts_list=array(
153                               'session'=>$this->_sessionId, 'module_name' => 'Contacts',
154                                               'name_value_lists' => array(
155                                         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'),
164                                         )
165                               )
166                         );
167
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');
171         
172         $existingContact = new Contact();
173         $existingContact->retrieve($this->c->id);
174
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');
178
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');
182     }
183     
184
185     public function testNoEmailsFindsDuplicates()
186     {
187         global $current_user;
188         $this->_login();
189         $contacts_list=array(
190                               'session'=>$this->_sessionId, 'module_name' => 'Contacts',
191                                               'name_value_lists' => array(
192                                         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'=>''),
201                                         )
202                               )
203                         );
204
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');
208
209         $existingContact = new Contact();
210         $existingContact->retrieve($this->c2->id);
211
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');
214
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');
218
219         //Now sync a second time
220         $this->_login();
221         $contacts_list=array(
222                               'session'=>$this->_sessionId, 'module_name' => 'Contacts',
223                                               'name_value_lists' => array(
224                                         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'=>''),
233                                         )
234                               )
235                         );
236
237         $result = $this->_soapClient->call('set_entries',$contacts_list);
238
239         $existingContact = new Contact();
240         $existingContact->retrieve($this->c2->id);
241
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');
247     }
248
249 }
250
251 ?>