whitespace cleanup
[civicrm-core.git] / tests / phpunit / WebTest / Contact / MergeContactsTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testIndividualAdd() {
35 $this->webtestLogin();
36
37 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
38
39 // add contact1
40 //select prefix
41 $prefix = 'Mr.';
42 $this->click("prefix_id");
43 $this->select("prefix_id", "label=$prefix");
44
45 //fill in first name
46 $firstName = substr(sha1(rand()), 0, 7);
47 $this->type('first_name', $firstName);
48
49 //fill in last name
50 $lastName = substr(sha1(rand()), 0, 7);
51 $this->type('last_name', $lastName);
52
53 //fill in email id
54 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
55
56 //fill in billing email id
57 $this->click('addEmail');
58 $this->waitForElementPresent('email_2_email');
59 $this->type('email_2_email', "$firstName.$lastName@billing.com");
60 $this->select('email_2_location_type_id', 'value=5');
61
62 // Clicking save.
63 $this->click("_qf_Contact_upload_view");
64 $this->waitForPageToLoad($this->getTimeoutMsec());
65 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
66
67 // Add Contact to a group
68 $group = 'Newsletter Subscribers';
69 $this->click('css=li#tab_group a');
70 $this->waitForElementPresent('_qf_GroupContact_next');
71 $this->select('group_id', "label=$group");
72 $this->click('_qf_GroupContact_next');
73 $this->waitForPageToLoad($this->getTimeoutMsec());
74 $this->assertElementContainsText('crm-notification-container', "Added to Group");
75
76 // Add Tags to the contact
77 $tag = 'Government Entity';
78 $this->click("css=li#tab_tag a");
79 $this->waitForElementPresent('tagtree');
80 $this->click("xpath=//div[@id='tagtree']/ul//li/input/../label[text()='$tag']");
81 $this->click("css=#tab_summary a");
82 $this->assertElementContainsText('css=.crm-summary-block #tags', $tag);
83
84 // Add an activity
85 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
86 $this->addActivity($firstName, $lastName, $subject);
87
88 // contact2: duplicate of contact1.
89 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
90
91 //fill in first name
92 $this->type("first_name", $firstName);
93
94 //fill in last name
95 $this->type("last_name", $lastName);
96
97 //fill in email
98 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
99
100 // Clicking save.
101 $this->click("_qf_Contact_refresh_dedupe");
102 $this->waitForPageToLoad($this->getTimeoutMsec());
103
104 $this->assertTrue($this->isTextPresent("One matching contact was found. You can View or Edit the existing contact."));
105 $this->click("_qf_Contact_upload_duplicate");
106 $this->waitForPageToLoad($this->getTimeoutMsec());
107 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
108
109 // Add second pair of dupes so we can test Merge and Goto Next Pair
110 $fname2 = 'Janet';
111 $lname2 = 'Rogers' . substr(sha1(rand()), 0, 7);
112 $email2 = "{$fname2}.{$lname2}@example.org";
113 $this->webtestAddContact($fname2, $lname2, $email2);
114
115 // Can not use helper for 2nd contact since it is a dupe
116 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
117 $this->type("first_name", $fname2);
118 $this->type("last_name", $lname2);
119 $this->type("email_1_email", $email2);
120 $this->click("_qf_Contact_refresh_dedupe");
121 $this->waitForPageToLoad($this->getTimeoutMsec());
122 $this->assertTrue($this->isTextPresent("One matching contact was found. You can View or Edit the existing contact."));
123 $this->click("_qf_Contact_upload_duplicate");
124 $this->waitForPageToLoad($this->getTimeoutMsec());
125 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
126
127 // Find and Merge Contacts with Supervised Rule
128 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
129
130 // reload the page
131 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=update");
132
133 // Select the contacts to be merged
134 $this->select("name=option51_length", "value=100");
135
136 $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
137 $this->click("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
138 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
139
140 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", '_qf_Merge_cancel-bottom');
141
142 // Move the activities, groups, etc to the main contact and merge using Merge and Goto Next Pair
143 $this->check('move_prefix_id');
144 $this->check('move_location_email_2');
145 $this->check('move_rel_table_activities');
146 $this->check('move_rel_table_groups');
147 $this->check('move_rel_table_tags');
148 $this->clickLink('_qf_Merge_next-bottom', '_qf_Merge_cancel-bottom');
149 $this->assertTrue($this->isTextPresent('Contacts Merged'), "Contacts Merged text was not found after merge.");
150
151 // Check that we are viewing the next Merge Pair (our 2nd contact, since the merge list is ordered by contact_id)
152 $this->assertTrue($this->isTextPresent("{$fname2} {$lname2}"), "Redirect for Goto Next Pair after merge did not work.");
153
154 // Ensure that the duplicate contact has been deleted
155 $this->openCiviPage("contact/search/advanced", "reset=1", '_qf_Advanced_refresh');
156 $this->type('sort_name', $firstName);
157 $this->check('deleted_contacts');
158 $this->click('_qf_Advanced_refresh');
159 $this->waitForPageToLoad($this->getTimeoutMsec());
160 $this->assertTrue($this->isTextPresent('1 Contact'), "Deletion of duplicate contact during merge was not successful. Dupe contact not found when searching trash.");
161
162 // Search for the main contact
163 $this->openCiviPage("contact/search/advanced", "reset=1", '_qf_Advanced_refresh');
164 $this->type('sort_name', $firstName);
165 $this->click('_qf_Advanced_refresh');
166 $this->waitForElementPresent("xpath=//form[@id='Advanced']/div[3]/div/div[2]/table/tbody/tr");
167
168 $this->click("//form[@id='Advanced']/div[3]/div/div[2]/table/tbody/tr/td[11]/span[1]/a[text()='View']");
169 $this->waitForPageToLoad($this->getTimeoutMsec());
170
171 // Verify prefix merged
172 // $this->verifyText( "xpath=//div[@class='left-corner']/h2", preg_quote( "$prefix $firstName $lastName" ) );
173
174 // Verify billing email merged
175 $this->isElementPresent("xpath=//div[@class='contact_details']/div[1][@class='contact_panel']/div[1][@class='contactCardLeft']/table/tbody/tr[4]/td[2]/span/a[text()='$firstName.$lastName@billing.com']");
176
177 // Verify activity merged
178 $this->click("css=li#tab_activity a");
179 $this->waitForElementPresent("xpath=//table[@id='contact-activity-selector-activity']/tbody/tr");
180 $this->verifyText("xpath=//table[@id='contact-activity-selector-activity']/tbody/tr/td[5]/a",
181 preg_quote("$lastName, $firstName")
182 );
183
184 // Verify group merged
185 $this->click("css=li#tab_group a");
186 $this->waitForElementPresent("xpath=//form[@id='GroupContact']//div[@class='view-content']//div[@class='dataTables_wrapper']/table/tbody/tr");
187 $this->verifyText("xpath=//form[@id='GroupContact']//div[@class='view-content']//div[@class='dataTables_wrapper']/table/tbody/tr/td/a",
188 preg_quote("$group")
189 );
190
191 // Verify tag merged
192 $this->click("css=li#tab_tag a");
193 $this->waitForElementPresent('check_5');
194 $this->assertChecked("check_3");
195 }
196
197 function addActivity($firstName, $lastName, $subject) {
198 $withContact = substr(sha1(rand()), 0, 7);
199 $this->webtestAddContact($withContact, "Anderson", $withContact . "@anderson.name");
200
201 $this->click("css=li#tab_activity a");
202
203 // waiting for the activity dropdown to show up
204 $this->waitForElementPresent("other_activity");
205
206 // Select the activity type from the activity dropdown
207 $this->select("other_activity", "label=Meeting");
208
209 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
210 // button at the end of this page to show up, to make sure it's fully loaded.
211 $this->waitForElementPresent("_qf_Activity_upload");
212
213 // ...and verifying if the page contains properly formatted display name for chosen contact.
214 $this->assertTrue($this->isTextPresent("Anderson, " . $withContact), "Contact not found in line " . __LINE__);
215
216 // Now we're filling the "Assigned To" field.
217 // Typing contact's name into the field (using typeKeys(), not type()!)...
218 $this->click("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id");
219 $this->type("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName);
220 $this->typeKeys("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName);
221
222 // ...waiting for drop down with results to show up...
223 $this->waitForElementPresent("css=div.token-input-dropdown-facebook");
224 $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook");
225
226 //..need to use mouseDownAt on first result (which is a li element), click does not work
227 $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook");
228
229 // ...again, waiting for the box with contact name to show up...
230 $this->waitForElementPresent("css=tr.crm-activity-form-block-assignee_contact_id td ul li span.token-input-delete-token-facebook");
231
232 // ...and verifying if the page contains properly formatted display name for chosen contact.
233 $this->assertTrue($this->isTextPresent("$lastName, " . $firstName), "Contact not found in line " . __LINE__);
234
235 // Since we're here, let's check if screen help is being displayed properly
236 $this->assertTrue($this->isTextPresent("Assigned activities will appear in their Activities listing at CiviCRM Home"));
237
238 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
239 // For simple input fields we can use field id as selector
240 $this->type("subject", $subject);
241 $this->type("location", "Some location needs to be put in this field.");
242
243 // Choosing the Date.
244 // Please note that we don't want to put in fixed date, since
245 // we want this test to work in the future and not fail because
246 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
247 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
248
249 // Setting duration.
250 $this->type("duration", "30");
251
252 // Putting in details.
253 $this->type("details", "Really brief details information.");
254
255 // Making sure that status is set to Scheduled (using value, not label).
256 $this->select("status_id", "value=1");
257
258 // Setting priority.
259 $this->select("priority_id", "value=1");
260
261 // Clicking save.
262 $this->click("_qf_Activity_upload");
263 $this->waitForPageToLoad($this->getTimeoutMsec());
264
265 // Is status message correct?
266 $this->assertTrue($this->isTextPresent("Activity '$subject' has been saved."), "Status message didn't show up after saving!");
267 }
268
269 function testMergeTest() {
270 $this->webtestLogin();
271
272 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
273
274 // add contact1
275 //fill in first name
276 $firstName = substr(sha1(rand()), 0, 7);
277 $this->type('first_name', $firstName);
278
279 //fill in last name
280 $lastName = substr(sha1(rand()), 0, 7);
281 $this->type('last_name', $lastName);
282
283 //fill in email id
284 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
285
286 //fill in billing email id
287 $this->click('addEmail');
288 $this->waitForElementPresent('email_2_email');
289 $this->type('email_2_email', "$firstName.$lastName@billing.com");
290 $this->select('email_2_location_type_id', 'value=5');
291
292 //fill in home phone no
293 $this->type('phone_1_phone', "9876543210");
294
295 //fill in billing phone id
296 $this->click('addPhone');
297 $this->waitForElementPresent('phone_2_phone');
298 $this->type('phone_2_phone', "9876543120");
299 $this->select('phone_2_location_type_id', 'value=5');
300
301 // Clicking save.
302 $this->click("_qf_Contact_upload_view");
303 $this->waitForPageToLoad($this->getTimeoutMsec());
304 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
305
306 // contact2: duplicate of contact1.
307 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
308
309 //fill in first name
310 $this->type("first_name", $firstName);
311
312 //fill in last name
313 $this->type("last_name", $lastName);
314
315 //fill in email
316 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
317
318 //fill in home phone no
319 $this->type('phone_1_phone', "9876543211");
320
321 // Clicking save.
322 $this->click("_qf_Contact_refresh_dedupe");
323 $this->waitForPageToLoad($this->getTimeoutMsec());
324
325 $this->assertTrue($this->isTextPresent("One matching contact was found. You can View or Edit the existing contact."));
326 $this->click("_qf_Contact_upload_duplicate");
327 $this->waitForPageToLoad($this->getTimeoutMsec());
328 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
329
330 // Find and Merge Contacts with Supervised Rule
331 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
332
333 // Select the contacts to be merged
334 $this->select("name=option51_length", "value=100");
335 $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']");
336 $this->click("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
337 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
338 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", "xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']");
339 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']");
340 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
341
342 $this->check("move_location_email_1");
343 $this->check("location[email][1][operation]");
344 $this->check("move_location_email_2");
345 $this->check("move_location_phone_1");
346 $this->check("location[phone][1][operation]");
347 $this->check("move_location_phone_2");
348 $this->click("_qf_Merge_next-bottom");
349 $this->waitForPageToLoad($this->getTimeoutMsec());
350
351 $this->assertTrue($this->isTextPresent('Contacts Merged'));
352 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
353 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[text() = '{$firstName}.{$lastName}@example.com']"));
354 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
355 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[text() ='{$firstName}.{$lastName}@example.com']"));
356 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
357 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[2]/a[text() ='$firstName.$lastName@billing.com']"));
358 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
359 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543211')]"));
360 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
361 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
362 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
363 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[2][contains(text(), '9876543120')]"));
364
365 //Merge with the feature of (add)
366 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
367
368 // add contact1
369 //fill in first name
370 $firstName1 = substr(sha1(rand()), 0, 7);
371 $this->type('first_name', $firstName1);
372
373 //fill in last name
374 $lastName1 = substr(sha1(rand()), 0, 7);
375 $this->type('last_name', $lastName1);
376
377 //fill in billing email id
378 $this->waitForElementPresent('email_1_email');
379 $this->type('email_1_email', "$firstName1.$lastName1@example.com");
380 $this->select('email_1_location_type_id', 'value=5');
381
382 $this->click('addEmail');
383 $this->waitForElementPresent('email_2_email');
384 $this->type('email_2_email', "$firstName.$lastName@home.com");
385 $this->select('email_2_location_type_id', 'value=1');
386
387 //fill in home phone no
388 $this->type('phone_1_phone', "9876543210");
389
390 // Clicking save.
391 $this->click("_qf_Contact_upload_view");
392 $this->waitForPageToLoad($this->getTimeoutMsec());
393 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
394
395 // contact2: duplicate of contact1.
396 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
397
398 //fill in first name
399 $this->type("first_name", $firstName1);
400
401 //fill in last name
402 $this->type("last_name", $lastName1);
403
404 //fill in email
405 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
406
407 //fill in billing phone no
408 $this->type('phone_1_phone', "9876543120");
409 $this->select('phone_1_location_type_id', 'value=5');
410
411 // Clicking save.
412 $this->click("_qf_Contact_refresh_dedupe");
413 $this->waitForPageToLoad($this->getTimeoutMsec());
414 $this->assertTrue($this->isTextPresent("One matching contact was found. You can View or Edit the existing contact."));
415 $this->click("_qf_Contact_upload_duplicate");
416 $this->waitForPageToLoad($this->getTimeoutMsec());
417 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
418
419 // Find and Merge Contacts with Supervised Rule
420 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
421
422 // Select the contacts to be merged
423 $this->select("name=option51_length", "value=100");
424 $this->waitForElementPresent("xpath=//table[@class='pagerDisplay']/tbody//tr/td[1]/a[text()='$firstName1 $lastName1']/../../td[2]/a[text()='$firstName1 $lastName1']");
425 $this->click("xpath=//table[@class='pagerDisplay']/tbody//tr/td[1]/a[text()='$firstName1 $lastName1']/../../td[2]/a[text()='$firstName1 $lastName1']/../../td[4]/a[text()='merge']");
426 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
427 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", "xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']");
428 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']");
429 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']");
430 $this->select('location_email_1_locTypeId', 'value=3');
431 $this->select('location_phone_1_locTypeId', 'value=1');
432 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']"));
433 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']"));
434 $this->assertTrue($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']"));
435 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
436
437 $this->check("move_location_email_1");
438 $this->check("move_location_phone_1");
439 $this->click("_qf_Merge_next-bottom");
440 $this->waitForPageToLoad($this->getTimeoutMsec());
441
442 $this->assertTrue($this->isTextPresent('Contacts Merged'));
443 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
444 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[text() ='{$firstName1}.{$lastName1}@example.com']"));
445 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Main')]"));
446 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[text() ='{$firstName1}.{$lastName1}@example.com']"));
447 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Billing')]"));
448 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543120')]"));
449 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
450 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
451 }
452
453 function testBatchMerge(){
454 $this->webtestLogin();
455
456 // add contact1 and its duplicate
457 //first name
458 $firstName = "Kerry".substr(sha1(rand()), 0, 7);
459 //last name
460 $lastName = "King".substr(sha1(rand()), 0, 7);
461 $this->_createContacts($firstName,$lastName);
462
463 //add contact2 and its duplicate
464 //These are the contacts with conflicts in communication preference.these contacts will be skipped during merge.
465 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
466
467 //fill in first name
468 $firstName1 = "Kurt".substr(sha1(rand()), 0, 7);
469 $this->type('first_name', $firstName1);
470
471 //fill in last name
472 $lastName1 = "Cobain".substr(sha1(rand()), 0, 7);
473 $this->type('last_name', $lastName1);
474
475 //fill in email id
476 $this->type('email_1_email', "{$firstName1}.{$lastName1}@example.com");
477
478 //fill in billing email id
479 $this->click('addEmail');
480 $this->waitForElementPresent('email_2_email');
481 $this->type('email_2_email', "$firstName1.$lastName1@billing.com");
482 $this->select('email_2_location_type_id', 'value=5');
483
484 //fill in home phone no
485 $this->type('phone_1_phone', "9876543210");
486
487 //fill in billing phone id
488 $this->click('addPhone');
489 $this->waitForElementPresent('phone_2_phone');
490 $this->type('phone_2_phone', "9876543120");
491 $this->select('phone_2_location_type_id', 'value=5');
492
493 //select communication preference
494 $this->check("privacy[do_not_phone]");
495
496 //Clicking save.
497 $this->click("_qf_Contact_upload_view");
498 $this->waitForPageToLoad($this->getTimeoutMsec());
499 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
500
501 //duplicate of contact2.
502 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
503
504 //fill in first name
505 $this->type("first_name", $firstName1);
506
507 //fill in last name
508 $this->type("last_name", $lastName1);
509
510 //fill in email
511 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
512
513 //fill in home phone no
514 $this->type('phone_1_phone', "9876543211");
515
516 //select communication preference
517 $this->check("preferred_communication_method[1]");
518
519 // Clicking save.
520 $this->click("_qf_Contact_refresh_dedupe");
521 $this->waitForPageToLoad($this->getTimeoutMsec());
522
523 $this->assertTrue($this->isTextPresent("One matching contact was found. You can View or Edit the existing contact."));
524 $this->click("_qf_Contact_upload_duplicate");
525 $this->waitForPageToLoad($this->getTimeoutMsec());
526 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
527
528 // add contact3 and its duplicate
529 //fill in first name
530 $firstName2 = "David".substr(sha1(rand()), 0, 7);
531 //fill in last name
532 $lastName2 = "Gilmour".substr(sha1(rand()), 0, 7);
533 $this->_createContacts($firstName2,$lastName2);
534
535 // add contact4 and its duplicate
536 //fill in first name
537 $firstName3 = "Dave".substr(sha1(rand()), 0, 7);
538 //fill in last name
539 $lastName3 = "Mustaine".substr(sha1(rand()), 0, 7);
540 $this->_createContacts($firstName3,$lastName3);
541
542 // Find and Merge Contacts with Supervised Rule
543 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew", "css=#DedupeFind table.pagerDisplay tbody tr");
544
545 $this->select("name=option51_length", "value=100");
546 $totalContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
547 $this->click("xpath=//form[@id='DedupeFind']//a/span[text()='Batch Merge Duplicates']");
548
549 // Check confirmation alert.
550 $this->assertTrue(
551 (bool)preg_match("/^This will run the batch merge process on the listed duplicates. The operation will run in safe mode - only records with no direct data conflicts will be merged. Click OK to proceed if you are sure you wish to run this operation./",
552 $this->getConfirmation()
553 ));
554 $this->chooseOkOnNextConfirmation();
555 $this->waitForPageToLoad($this->getTimeoutMsec());
556 $this->waitForElementPresent('civicrm-footer');
557 $this->assertElementContainsText('crm-notification-container', "safe mode");
558
559 // If we are still on the dedupe table page, count unmerged contacts
560 if ($this->isElementPresent("//table[@class='pagerDisplay']")) {
561 // Wait for datatable to load
562 $this->waitForElementPresent("//table[@class='pagerDisplay']/tbody/tr");
563 $unMergedContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
564 }
565 else {
566 $unMergedContacts = 0;
567 }
568
569 $mergedContacts = $totalContacts - $unMergedContacts;
570
571 //check the existence of merged contacts
572 $contactEmails = array(
573 1 => "{$firstName}.{$lastName}@example.com",
574 2 => "{$firstName2}.{$lastName2}@example.com",
575 3 => "{$firstName3}.{$lastName3}@example.com"
576 );
577
578 foreach($contactEmails as $key => $value) {
579 $this->click('sort_name_navigation');
580 $this->type('css=input#sort_name_navigation', $value);
581 $this->typeKeys('css=input#sort_name_navigation', $value);
582 // Wait for result list.
583 $this->waitForElementPresent("css=div.ac_results-inner li");
584
585 // Visit contact summary page.
586 $this->clickLink("css=div.ac_results-inner li", 'civicrm-footer');
587 }
588 }
589
590 /**
591 * Helper FN
592 */
593 function _createContacts($firstName,$lastName){
594 // add contact
595 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
596 //fill in first name
597 $this->type('first_name', $firstName);
598
599 //fill in last name
600 $this->type('last_name', $lastName);
601
602 //fill in email id
603 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
604
605 //fill in billing email id
606 $this->click('addEmail');
607 $this->waitForElementPresent('email_2_email');
608 $this->type('email_2_email', "$firstName.$lastName@billing.com");
609 $this->select('email_2_location_type_id', 'value=5');
610
611 // Clicking save.
612 $this->click("_qf_Contact_upload_view");
613 $this->waitForPageToLoad($this->getTimeoutMsec());
614 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
615
616 //duplicate of above contact.
617 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
618
619 //fill in first name
620 $this->type("first_name", $firstName);
621
622 //fill in last name
623 $this->type("last_name", $lastName);
624
625 //fill in email
626 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
627
628 // Clicking save.
629 $this->click("_qf_Contact_refresh_dedupe");
630 $this->waitForPageToLoad($this->getTimeoutMsec());
631
632 $this->assertTrue($this->isTextPresent("One matching contact was found. You can View or Edit the existing contact."));
633 $this->click("_qf_Contact_upload_duplicate");
634 $this->waitForPageToLoad($this->getTimeoutMsec());
635 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
636 }
637 }
638