3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Contact_MergeContactsTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testIndividualAdd() {
35 $this->webtestLogin();
37 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
42 $this->click("prefix_id");
43 $this->select("prefix_id", "label=$prefix");
46 $firstName = substr(sha1(rand()), 0, 7);
47 $this->type('first_name', $firstName);
50 $lastName = substr(sha1(rand()), 0, 7);
51 $this->type('last_name', $lastName);
54 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
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');
63 $this->click("_qf_Contact_upload_view");
64 $this->waitForPageToLoad($this->getTimeoutMsec());
65 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
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");
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);
85 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
86 $this->addActivity($firstName, $lastName, $subject);
88 // contact2: duplicate of contact1.
89 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
92 $this->type("first_name", $firstName);
95 $this->type("last_name", $lastName);
98 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
101 $this->click("_qf_Contact_refresh_dedupe");
102 $this->waitForPageToLoad($this->getTimeoutMsec());
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");
109 // Add second pair of dupes so we can test Merge and Goto Next Pair
111 $lname2 = 'Rogers' . substr(sha1(rand()), 0, 7);
112 $email2 = "{$fname2}.{$lname2}@example.org";
113 $this->webtestAddContact($fname2, $lname2, $email2);
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");
127 // Find and Merge Contacts with Supervised Rule
128 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
131 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=update");
133 // Select the contacts to be merged
134 $this->select("name=option51_length", "value=100");
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');
140 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", '_qf_Merge_cancel-bottom');
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.");
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.");
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.");
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");
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());
171 // Verify prefix merged
172 // $this->verifyText( "xpath=//div[@class='left-corner']/h2", preg_quote( "$prefix $firstName $lastName" ) );
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']");
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")
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",
192 $this->click("css=li#tab_tag a");
193 $this->waitForElementPresent('check_5');
194 $this->assertChecked("check_3");
197 function addActivity($firstName, $lastName, $subject) {
198 $withContact = substr(sha1(rand()), 0, 7);
199 $this->webtestAddContact($withContact, "Anderson", $withContact . "@anderson.name");
201 $this->click("css=li#tab_activity a");
203 // waiting for the activity dropdown to show up
204 $this->waitForElementPresent("other_activity");
206 // Select the activity type from the activity dropdown
207 $this->select("other_activity", "label=Meeting");
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");
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__
);
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);
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");
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");
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");
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__
);
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"));
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.");
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');
250 $this->type("duration", "30");
252 // Putting in details.
253 $this->type("details", "Really brief details information.");
255 // Making sure that status is set to Scheduled (using value, not label).
256 $this->select("status_id", "value=1");
259 $this->select("priority_id", "value=1");
262 $this->click("_qf_Activity_upload");
263 $this->waitForPageToLoad($this->getTimeoutMsec());
265 // Is status message correct?
266 $this->assertTrue($this->isTextPresent("Activity '$subject' has been saved."), "Status message didn't show up after saving!");
269 function testMergeTest() {
270 $this->webtestLogin();
272 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
276 $firstName = substr(sha1(rand()), 0, 7);
277 $this->type('first_name', $firstName);
280 $lastName = substr(sha1(rand()), 0, 7);
281 $this->type('last_name', $lastName);
284 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
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');
292 //fill in home phone no
293 $this->type('phone_1_phone', "9876543210");
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');
302 $this->click("_qf_Contact_upload_view");
303 $this->waitForPageToLoad($this->getTimeoutMsec());
304 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
306 // contact2: duplicate of contact1.
307 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
310 $this->type("first_name", $firstName);
313 $this->type("last_name", $lastName);
316 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
318 //fill in home phone no
319 $this->type('phone_1_phone', "9876543211");
322 $this->click("_qf_Contact_refresh_dedupe");
323 $this->waitForPageToLoad($this->getTimeoutMsec());
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");
330 // Find and Merge Contacts with Supervised Rule
331 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
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');
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());
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')]"));
365 //Merge with the feature of (add)
366 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
370 $firstName1 = substr(sha1(rand()), 0, 7);
371 $this->type('first_name', $firstName1);
374 $lastName1 = substr(sha1(rand()), 0, 7);
375 $this->type('last_name', $lastName1);
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');
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');
387 //fill in home phone no
388 $this->type('phone_1_phone', "9876543210");
391 $this->click("_qf_Contact_upload_view");
392 $this->waitForPageToLoad($this->getTimeoutMsec());
393 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
395 // contact2: duplicate of contact1.
396 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
399 $this->type("first_name", $firstName1);
402 $this->type("last_name", $lastName1);
405 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
407 //fill in billing phone no
408 $this->type('phone_1_phone', "9876543120");
409 $this->select('phone_1_location_type_id', 'value=5');
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");
419 // Find and Merge Contacts with Supervised Rule
420 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
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');
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());
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')]"));
453 function testBatchMerge(){
454 $this->webtestLogin();
456 // add contact1 and its duplicate
458 $firstName = "Kerry".substr(sha1(rand()), 0, 7);
460 $lastName = "King".substr(sha1(rand()), 0, 7);
461 $this->_createContacts($firstName,$lastName);
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");
468 $firstName1 = "Kurt".substr(sha1(rand()), 0, 7);
469 $this->type('first_name', $firstName1);
472 $lastName1 = "Cobain".substr(sha1(rand()), 0, 7);
473 $this->type('last_name', $lastName1);
476 $this->type('email_1_email', "{$firstName1}.{$lastName1}@example.com");
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');
484 //fill in home phone no
485 $this->type('phone_1_phone', "9876543210");
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');
493 //select communication preference
494 $this->check("privacy[do_not_phone]");
497 $this->click("_qf_Contact_upload_view");
498 $this->waitForPageToLoad($this->getTimeoutMsec());
499 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
501 //duplicate of contact2.
502 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
505 $this->type("first_name", $firstName1);
508 $this->type("last_name", $lastName1);
511 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
513 //fill in home phone no
514 $this->type('phone_1_phone', "9876543211");
516 //select communication preference
517 $this->check("preferred_communication_method[1]");
520 $this->click("_qf_Contact_refresh_dedupe");
521 $this->waitForPageToLoad($this->getTimeoutMsec());
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");
528 // add contact3 and its duplicate
530 $firstName2 = "David".substr(sha1(rand()), 0, 7);
532 $lastName2 = "Gilmour".substr(sha1(rand()), 0, 7);
533 $this->_createContacts($firstName2,$lastName2);
535 // add contact4 and its duplicate
537 $firstName3 = "Dave".substr(sha1(rand()), 0, 7);
539 $lastName3 = "Mustaine".substr(sha1(rand()), 0, 7);
540 $this->_createContacts($firstName3,$lastName3);
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");
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']");
549 // Check confirmation alert.
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()
554 $this->chooseOkOnNextConfirmation();
555 $this->waitForPageToLoad($this->getTimeoutMsec());
556 $this->waitForElementPresent('civicrm-footer');
557 $this->assertElementContainsText('crm-notification-container', "safe mode");
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");
566 $unMergedContacts = 0;
569 $mergedContacts = $totalContacts - $unMergedContacts;
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"
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");
585 // Visit contact summary page.
586 $this->clickLink("css=div.ac_results-inner li", 'civicrm-footer');
593 function _createContacts($firstName,$lastName){
595 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
597 $this->type('first_name', $firstName);
600 $this->type('last_name', $lastName);
603 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
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');
612 $this->click("_qf_Contact_upload_view");
613 $this->waitForPageToLoad($this->getTimeoutMsec());
614 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
616 //duplicate of above contact.
617 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
620 $this->type("first_name", $firstName);
623 $this->type("last_name", $lastName);
626 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
629 $this->click("_qf_Contact_refresh_dedupe");
630 $this->waitForPageToLoad($this->getTimeoutMsec());
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");