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