3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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';
30 * Class WebTest_Contact_MergeContactsTest
32 class WebTest_Contact_MergeContactsTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testIndividualAdd() {
39 $this->webtestLogin();
41 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
46 $this->click("prefix_id");
47 $this->select("prefix_id", "label=$prefix");
50 $firstName = substr(sha1(rand()), 0, 7);
51 $this->type('first_name', $firstName);
54 $lastName = substr(sha1(rand()), 0, 7);
55 $this->type('last_name', $lastName);
58 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
60 //fill in billing email id
61 $this->click('addEmail');
62 $this->waitForElementPresent('email_2_email');
63 $this->type('email_2_email', "$firstName.$lastName@billing.com");
64 $this->select('email_2_location_type_id', 'value=5');
67 $this->click("_qf_Contact_upload_view");
68 $this->waitForPageToLoad($this->getTimeoutMsec());
69 $this->waitForText('crm-notification-container', "Contact Saved");
71 // Add Contact to a group
72 $group = 'Newsletter Subscribers';
73 $this->click('css=li#tab_group a');
74 $this->waitForElementPresent('_qf_GroupContact_next');
75 $this->select('group_id', "label=$group");
76 $this->click('_qf_GroupContact_next');
77 $this->waitForElementPresent('link=Delete');
78 $this->waitForText('crm-notification-container', "Added to Group");
80 // Add Tags to the contact
81 $tag = 'Government Entity';
82 $this->click("css=li#tab_tag a");
83 $this->waitForElementPresent('tagtree');
84 $this->click("xpath=//div[@id='tagtree']/ul//li/input/../span/label[text()='$tag']");
85 $this->click("css=#tab_summary a");
86 $this->assertElementContainsText('css=.crm-summary-block #tags', $tag);
89 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
90 $this->addActivity($firstName, $lastName, $subject);
92 // contact2: duplicate of contact1.
93 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
96 $this->type("first_name", $firstName);
99 $this->type("last_name", $lastName);
102 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
105 $this->click("_qf_Contact_refresh_dedupe");
106 $this->waitForPageToLoad($this->getTimeoutMsec());
108 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
109 $this->click("_qf_Contact_upload_duplicate");
110 $this->waitForPageToLoad($this->getTimeoutMsec());
111 $this->waitForText('crm-notification-container', "Contact Saved");
113 // Add second pair of dupes so we can test Merge and Goto Next Pair
115 $lname2 = 'Rogers' . substr(sha1(rand()), 0, 7);
116 $email2 = "{$fname2}.{$lname2}@example.org";
117 $this->webtestAddContact($fname2, $lname2, $email2);
119 // Can not use helper for 2nd contact since it is a dupe
120 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
121 $this->type("first_name", $fname2);
122 $this->type("last_name", $lname2);
123 $this->type("email_1_email", $email2);
124 $this->click("_qf_Contact_refresh_dedupe");
125 $this->waitForPageToLoad($this->getTimeoutMsec());
126 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
127 $this->click("_qf_Contact_upload_duplicate");
128 $this->waitForPageToLoad($this->getTimeoutMsec());
129 $this->waitForText('crm-notification-container', "Contact Saved");
131 // Find and Merge Contacts with Supervised Rule
132 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
135 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=update");
137 // Select the contacts to be merged
138 $this->select("name=option51_length", "value=100");
140 $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
141 $this->clickLink("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
142 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
144 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", '_qf_Merge_cancel-bottom');
146 // Move the activities, groups, etc to the main contact and merge using Merge and Goto Next Pair
147 $this->check('move_prefix_id');
148 $this->check('move_location_email_2');
149 $this->check('move_rel_table_activities');
150 $this->check('move_rel_table_groups');
151 $this->check('move_rel_table_tags');
152 $this->clickLink('_qf_Merge_next-bottom', '_qf_Merge_cancel-bottom');
153 $this->assertTrue($this->isTextPresent('Contacts Merged'), "Contacts Merged text was not found after merge.");
155 // Check that we are viewing the next Merge Pair (our 2nd contact, since the merge list is ordered by contact_id)
156 $this->assertTrue($this->isTextPresent("{$fname2} {$lname2}"), "Redirect for Goto Next Pair after merge did not work.");
158 // Ensure that the duplicate contact has been deleted
159 $this->openCiviPage("contact/search/advanced", "reset=1", '_qf_Advanced_refresh');
160 $this->type('sort_name', $firstName);
161 $this->click('deleted_contacts');
162 $this->click('_qf_Advanced_refresh');
163 $this->waitForPageToLoad($this->getTimeoutMsec());
164 $this->assertTrue($this->isTextPresent('1 Contact'), "Deletion of duplicate contact during merge was not successful. Dupe contact not found when searching trash.");
166 // Search for the main contact
167 $this->openCiviPage("contact/search/advanced", "reset=1", '_qf_Advanced_refresh');
168 $this->type('sort_name', $firstName);
169 $this->click('_qf_Advanced_refresh');
170 $this->waitForElementPresent("xpath=//form[@id='Advanced']/div[3]/div/div[2]/table/tbody/tr");
172 $this->click("//form[@id='Advanced']/div[3]/div/div[2]/table/tbody/tr/td[11]/span[1]/a[text()='View']");
173 $this->waitForPageToLoad($this->getTimeoutMsec());
175 // Verify prefix merged
176 // $this->verifyText( "xpath=//div[@class='left-corner']/h2", preg_quote( "$prefix $firstName $lastName" ) );
178 // Verify billing email merged
179 $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']");
181 // Verify activity merged
182 $this->click("css=li#tab_activity a");
183 $this->waitForElementPresent("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody/tr");
184 $this->verifyText("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody/tr/td[5]/a",
185 preg_quote("$lastName, $firstName")
188 // Verify group merged
189 $this->click("css=li#tab_group a");
190 $this->waitForElementPresent("GroupContact");
191 $this->waitForElementPresent("xpath=//form[@id='GroupContact']//div[@class='view-content view-contact-groups']//div/table/tbody/tr/td/a");
192 $this->verifyText("xpath=//form[@id='GroupContact']//div[@class='view-content view-contact-groups']//div/table/tbody/tr/td/a",
197 $this->click("css=li#tab_tag a");
198 $this->waitForElementPresent('check_5');
199 $this->assertChecked("check_3");
202 public function testMergeContactSubType() {
203 $this->webtestLogin();
204 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
205 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
207 $firstName = "Anderson" . substr(sha1(rand()), 0, 4);
208 $this->type('first_name', $firstName);
211 $lastName = substr(sha1(rand()), 0, 4);
212 $this->type('last_name', $lastName);
215 $this->waitForElementPresent('email_1_email');
216 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
217 $this->waitForElementPresent('contact_sub_type');
218 $this->select('contact_sub_type', "Parent");
221 $this->click("_qf_Contact_upload_view");
222 $this->waitForPageToLoad($this->getTimeoutMsec());
223 $this->waitForText('crm-notification-container', "Contact Saved");
225 // contact2: contact with same email id as contact 1.
226 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
227 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
229 $fName = "John" . substr(sha1(rand()), 0, 4);
230 $this->type('first_name', $fName);
231 $lName = substr(sha1(rand()), 0, 4);
232 $this->type('last_name', $lName);
233 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
234 $this->waitForElementPresent('contact_sub_type');
235 $this->multiselect2('contact_sub_type', array("Student", "Staff"));
236 $this->click("_qf_Contact_upload_view");
237 $this->waitForText('crm-notification-container', "Contact Saved");
238 $this->openCiviPage("contact/deduperules", "reset=1");
239 $this->click("xpath=//*[@id='option12']/tbody/tr[3]/td[3]/span/a[1][contains(text(),'Use Rule')]");
240 $this->waitForElementPresent('_qf_DedupeFind_submit-bottom');
241 $this->click("_qf_DedupeFind_next-bottom");
243 $this->waitForElementPresent("xpath=//form[@id='DedupeFind']/div[2]/div/table/tbody/tr[1]/td[4]/a[text()='merge']");
244 $this->waitForElementPresent("xpath=//form[@id='DedupeFind']/a[3]/span[contains(text(),'Done')]");
245 $this->isElementPresent("xpath=//table[@id='option51']/tbody/tr/td[1]/a[text()='{$firstName} {$lastName}']/../td[2]/a[text()='{$fName} {$lName}']");
246 $this->click("xpath=//table[@id='option51']/tbody/tr[1]/td[4]/a[text()='merge']");
247 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
248 $this->click('toggleSelect');
249 $this->click('_qf_Merge_next-bottom');
250 $this->waitForPageToLoad($this->getTimeoutMsec());
251 $this->assertTrue($this->isTextPresent("Staff, Student"));
255 * @param string $firstName
256 * @param string $lastName
259 public function addActivity($firstName, $lastName, $subject) {
260 $withContact = substr(sha1(rand()), 0, 7);
261 $this->webtestAddContact($withContact, "Anderson", $withContact . "@anderson.name");
263 $this->click("css=li#tab_activity a");
265 // waiting for the activity dropdown to show up
266 $this->waitForElementPresent("other_activity");
268 // Select the activity type from the activity dropdown
269 $this->select("other_activity", "label=Meeting");
271 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
272 // button at the end of this page to show up, to make sure it's fully loaded.
273 $this->waitForElementPresent("_qf_Activity_upload");
275 // ...and verifying if the page contains properly formatted display name for chosen contact.
276 $this->assertTrue($this->isTextPresent("Anderson, " . $withContact), "Contact not found in line " . __LINE__
);
278 // Now we're filling the "Assigned To" field.
279 // Typing contact's name into the field (using typeKeys(), not type()!)...
280 $this->select2("assignee_contact_id", $firstName, TRUE, FALSE);
282 // ...and verifying if the page contains properly formatted display name for chosen contact.
283 $this->assertTrue($this->isTextPresent("$lastName, " . $firstName), "Contact not found in line " . __LINE__
);
285 // Since we're here, let's check if screen help is being displayed properly
286 $this->assertTrue($this->isTextPresent("A copy of this activity will be emailed to each Assignee."));
288 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
289 // For simple input fields we can use field id as selector
290 $this->type("subject", $subject);
291 $this->type("location", "Some location needs to be put in this field.");
293 // Choosing the Date.
294 // Please note that we don't want to put in fixed date, since
295 // we want this test to work in the future and not fail because
296 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
297 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
300 $this->type("duration", "30");
302 // Putting in details.
303 $this->type("details", "Really brief details information.");
305 // Making sure that status is set to Scheduled (using value, not label).
306 $this->select("status_id", "value=1");
309 $this->select("priority_id", "value=1");
312 $this->click("_qf_Activity_upload");
313 $this->waitForElementPresent("crm-notification-container");
315 // Is status message correct?
316 $this->waitForText('crm-notification-container', "Activity '$subject' has been saved.", "Status message didn't show up after saving!");
319 public function testMergeTest() {
320 $this->webtestLogin();
322 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
326 $firstName = substr(sha1(rand()), 0, 7);
327 $this->type('first_name', $firstName);
330 $lastName = substr(sha1(rand()), 0, 7);
331 $this->type('last_name', $lastName);
334 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
336 //fill in billing email id
337 $this->click('addEmail');
338 $this->waitForElementPresent('email_2_email');
339 $this->type('email_2_email', "$firstName.$lastName@billing.com");
340 $this->select('email_2_location_type_id', 'value=5');
342 //fill in home phone no
343 $this->type('phone_1_phone', "9876543210");
345 //fill in billing phone id
346 $this->click('addPhone');
347 $this->waitForElementPresent('phone_2_phone');
348 $this->type('phone_2_phone', "9876543120");
349 $this->select('phone_2_location_type_id', 'value=5');
352 $this->click("_qf_Contact_upload_view");
353 $this->waitForPageToLoad($this->getTimeoutMsec());
354 $this->waitForText('crm-notification-container', "Contact Saved");
356 // contact2: duplicate of contact1.
357 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
360 $this->type("first_name", $firstName);
363 $this->type("last_name", $lastName);
366 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
368 //fill in home phone no
369 $this->type('phone_1_phone', "9876543211");
372 $this->click("_qf_Contact_refresh_dedupe");
373 $this->waitForPageToLoad($this->getTimeoutMsec());
375 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
376 $this->click("_qf_Contact_upload_duplicate");
377 $this->waitForPageToLoad($this->getTimeoutMsec());
378 $this->waitForText('crm-notification-container', "Contact Saved");
380 // Find and Merge Contacts with Supervised Rule
381 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
383 // Select the contacts to be merged
384 $this->select("name=option51_length", "value=100");
385 $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']");
386 $this->click("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
387 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
388 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", "xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(overwrite)']", FALSE);
389 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[5]/td[4]/span[text()='(add)']");
390 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
392 $this->check("move_location_email_1");
393 $this->check("location[email][1][operation]");
394 $this->check("move_location_email_2");
395 $this->check("move_location_phone_1");
396 $this->check("location[phone][1][operation]");
397 $this->check("move_location_phone_2");
398 $this->click("_qf_Merge_next-bottom");
399 $this->waitForPageToLoad($this->getTimeoutMsec());
401 $this->assertTrue($this->isTextPresent('Contacts Merged'));
402 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
403 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]"));
404 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
405 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]"));
406 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
407 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[2]/a[contains(text(), '$firstName.$lastName@billing.com')]"));
408 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
409 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543211')]"));
410 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
411 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
412 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
413 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[2][contains(text(), '9876543120')]"));
415 //Merge with the feature of (add)
416 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
420 $firstName1 = substr(sha1(rand()), 0, 7);
421 $this->type('first_name', $firstName1);
424 $lastName1 = substr(sha1(rand()), 0, 7);
425 $this->type('last_name', $lastName1);
427 //fill in billing email id
428 $this->waitForElementPresent('email_1_email');
429 $this->type('email_1_email', "$firstName1.$lastName1@example.com");
430 $this->select('email_1_location_type_id', 'value=5');
432 $this->click('addEmail');
433 $this->waitForElementPresent('email_2_email');
434 $this->type('email_2_email', "$firstName.$lastName@home.com");
435 $this->select('email_2_location_type_id', 'value=1');
437 //fill in home phone no
438 $this->type('phone_1_phone', "9876543210");
441 $this->click("_qf_Contact_upload_view");
442 $this->waitForPageToLoad($this->getTimeoutMsec());
443 $this->waitForText('crm-notification-container', "Contact Saved");
445 // contact2: duplicate of contact1.
446 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
449 $this->type("first_name", $firstName1);
452 $this->type("last_name", $lastName1);
455 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
457 //fill in billing phone no
458 $this->type('phone_1_phone', "9876543120");
459 $this->select('phone_1_location_type_id', 'value=5');
462 $this->click("_qf_Contact_refresh_dedupe");
463 $this->waitForPageToLoad($this->getTimeoutMsec());
464 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
465 $this->click("_qf_Contact_upload_duplicate");
466 $this->waitForPageToLoad($this->getTimeoutMsec());
467 $this->waitForText('crm-notification-container', "Contact Saved");
469 // Find and Merge Contacts with Supervised Rule
470 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
472 // Select the contacts to be merged
473 $this->select("name=option51_length", "value=100");
474 $this->waitForElementPresent("xpath=//table[@class='pagerDisplay dataTable no-footer']/tbody//tr/td[1]/a[text()='$firstName1 $lastName1']/../../td[2]/a[text()='$firstName1 $lastName1']");
475 $this->click("xpath=//table[@class='pagerDisplay dataTable no-footer']/tbody//tr/td[1]/a[text()='$firstName1 $lastName1']/../../td[2]/a[text()='$firstName1 $lastName1']/../../td[4]/a[text()='merge']");
476 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
477 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", "xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']");
478 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']");
479 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']");
480 $this->select('location_email_1_locTypeId', 'value=3');
481 $this->select('location_phone_1_locTypeId', 'value=1');
482 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']"));
483 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']"));
484 $this->assertTrue($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']"));
485 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
487 $this->check("move_location_email_1");
488 $this->check("move_location_phone_1");
489 $this->click("_qf_Merge_next-bottom");
490 $this->waitForPageToLoad($this->getTimeoutMsec());
492 $this->assertTrue($this->isTextPresent('Contacts Merged'));
493 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
494 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[contains(text(), '{$firstName1}.{$lastName1}@example.com')]"));
495 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Main')]"));
496 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[contains(text(), '{$firstName1}.{$lastName1}@example.com')]"));
497 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Billing')]"));
498 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543120')]"));
499 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
500 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
503 public function testBatchMerge() {
504 $this->webtestLogin();
506 // add contact1 and its duplicate
508 $firstName = "Kerry" . substr(sha1(rand()), 0, 7);
510 $lastName = "King" . substr(sha1(rand()), 0, 7);
511 $this->_createContacts($firstName, $lastName);
513 //add contact2 and its duplicate
514 //These are the contacts with conflicts in communication preference.these contacts will be skipped during merge.
515 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
518 $firstName1 = "Kurt" . substr(sha1(rand()), 0, 7);
519 $this->type('first_name', $firstName1);
522 $lastName1 = "Cobain" . substr(sha1(rand()), 0, 7);
523 $this->type('last_name', $lastName1);
526 $this->type('email_1_email', "{$firstName1}.{$lastName1}@example.com");
528 //fill in billing email id
529 $this->click('addEmail');
530 $this->waitForElementPresent('email_2_email');
531 $this->type('email_2_email', "$firstName1.$lastName1@billing.com");
532 $this->select('email_2_location_type_id', 'value=5');
534 //fill in home phone no
535 $this->type('phone_1_phone', "9876543210");
537 //fill in billing phone id
538 $this->click('addPhone');
539 $this->waitForElementPresent('phone_2_phone');
540 $this->type('phone_2_phone', "9876543120");
541 $this->select('phone_2_location_type_id', 'value=5');
543 //select communication preference
544 $this->check("privacy[do_not_phone]");
547 $this->click("_qf_Contact_upload_view");
548 $this->waitForPageToLoad($this->getTimeoutMsec());
549 $this->waitForText('crm-notification-container', "Contact Saved");
551 //duplicate of contact2.
552 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
555 $this->type("first_name", $firstName1);
558 $this->type("last_name", $lastName1);
561 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
563 //fill in home phone no
564 $this->type('phone_1_phone', "9876543211");
566 //select communication preference
567 $this->check("preferred_communication_method[1]");
570 $this->click("_qf_Contact_refresh_dedupe");
571 $this->waitForPageToLoad($this->getTimeoutMsec());
573 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
574 $this->click("_qf_Contact_upload_duplicate");
575 $this->waitForPageToLoad($this->getTimeoutMsec());
576 $this->waitForText('crm-notification-container', "Contact Saved");
578 // add contact3 and its duplicate
580 $firstName2 = "David" . substr(sha1(rand()), 0, 7);
582 $lastName2 = "Gilmour" . substr(sha1(rand()), 0, 7);
583 $this->_createContacts($firstName2, $lastName2);
585 // add contact4 and its duplicate
587 $firstName3 = "Dave" . substr(sha1(rand()), 0, 7);
589 $lastName3 = "Mustaine" . substr(sha1(rand()), 0, 7);
590 $this->_createContacts($firstName3, $lastName3);
592 // Find and Merge Contacts with Supervised Rule
593 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew", "css=#DedupeFind table.pagerDisplay tbody tr");
595 $this->select("name=option51_length", "value=100");
596 $totalContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
597 $this->click("//form[@id='DedupeFind']//a/span[contains(text(),'Batch Merge Duplicates')]");
599 // Check confirmation alert.
601 (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./",
602 $this->getConfirmation()
604 $this->chooseOkOnNextConfirmation();
605 $this->waitForPageToLoad($this->getTimeoutMsec());
606 $this->waitForElementPresent('civicrm-footer');
607 $this->waitForText('crm-notification-container', "safe mode");
609 // If we are still on the dedupe table page, count unmerged contacts
610 if ($this->isElementPresent("//table[@class='pagerDisplay']")) {
611 // Wait for datatable to load
612 $this->waitForElementPresent("//table[@class='pagerDisplay']/tbody/tr");
613 $unMergedContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
616 $unMergedContacts = 0;
619 $mergedContacts = $totalContacts - $unMergedContacts;
621 //check the existence of merged contacts
622 $contactEmails = array(
623 1 => "{$firstName}.{$lastName}@example.com",
624 2 => "{$firstName2}.{$lastName2}@example.com",
625 3 => "{$firstName3}.{$lastName3}@example.com",
628 foreach ($contactEmails as $key => $value) {
629 $this->click('sort_name_navigation');
630 $this->type('css=input#sort_name_navigation', $value);
631 $this->typeKeys('css=input#sort_name_navigation', $value);
632 // Wait for result list.
633 $this->waitForElementPresent("css=ul.ui-autocomplete li.ui-menu-item");
635 // Visit contact summary page.
636 $this->clickLink("css=ul.ui-autocomplete li.ui-menu-item", 'civicrm-footer');
643 public function _createContacts($firstName = NULL, $lastName = NULL, $organizationName = NULL, $contactType = 'Individual') {
644 if ($contactType == 'Individual') {
646 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
648 $this->type('first_name', $firstName);
651 $this->type('last_name', $lastName);
654 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
656 //fill in billing email id
657 $this->click('addEmail');
658 $this->waitForElementPresent('email_2_email');
659 $this->type('email_2_email', "$firstName.$lastName@billing.com");
660 $this->select('email_2_location_type_id', 'value=5');
663 $this->click("_qf_Contact_upload_view");
664 $this->waitForPageToLoad($this->getTimeoutMsec());
665 $this->waitForText('crm-notification-container', "Contact Saved");
667 //duplicate of above contact.
668 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
671 $this->type("first_name", $firstName);
674 $this->type("last_name", $lastName);
677 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
680 $this->click("_qf_Contact_refresh_dedupe");
681 $this->waitForPageToLoad($this->getTimeoutMsec());
683 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
684 $this->click("_qf_Contact_upload_duplicate");
685 $this->waitForPageToLoad($this->getTimeoutMsec());
686 $this->waitForText('crm-notification-container', "Contact Saved");
688 elseif ($contactType == 'Organization') {
690 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
691 //fill in Organization name
692 $this->type('organization_name', $organizationName);
695 $this->type('email_1_email', "{$organizationName}@org.com");
697 $this->click("_qf_Contact_upload_view-bottom");
698 $this->waitForPageToLoad($this->getTimeoutMsec());
699 $this->waitForText('crm-notification-container', "Contact Saved");
700 $mainId = explode("CiviCRM ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
701 $mainId = trim($mainId[1]);
703 //Duplicate of above contact.
704 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
706 //fill in Organization name
707 $this->type('organization_name', $organizationName);
710 $this->type('email_1_email', "{$organizationName}@org.com");
713 $this->click("_qf_Contact_upload_view-bottom");
714 $this->waitForPageToLoad($this->getTimeoutMsec());
716 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
717 $this->click("_qf_Contact_upload_duplicate");
718 $this->waitForPageToLoad($this->getTimeoutMsec());
719 $this->waitForText('crm-notification-container', "Contact Saved");
720 $duplicateId = explode("CiviCRM ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
721 $duplicateId = trim($duplicateId[1]);
725 'duplicateId' => $duplicateId,
732 * to create new membership type
734 public function addMembershipType($membershipOrganization) {
735 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
736 $this->click("link=Add Membership Type");
737 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
739 $this->type('name', "Membership Type $membershipOrganization");
740 $this->select2('member_of_contact_id', $membershipOrganization);
742 $this->type('minimum_fee', '1');
743 $this->select('financial_type_id', 'value=2');
744 $this->type('duration_interval', 1);
745 $this->select('duration_unit', "label=year");
747 $this->select('period_type', "label=Fixed");
748 $this->waitForElementPresent('fixed_period_rollover_day[d]');
750 // fixed period start set to April 1
751 $this->select('fixed_period_start_day[M]', 'value=4');
752 // rollover date set to Jan 31
753 $this->select('fixed_period_rollover_day[M]', 'value=1');
755 // Employer of relationship
756 $this->select('relationship_type_id', 'value=5_b_a');
757 $this->click('_qf_MembershipType_upload-bottom');
758 $this->waitForElementPresent('link=Add Membership Type');
759 $this->waitForText("crm-notification-container", "The membership type 'Membership Type $membershipOrganization' has been saved.");
763 * Test for CRM-12695 fix
765 public function testMergeOrganizations() {
766 $this->webtestLogin();
768 // build organisation name
769 $orgnaizationName = 'org_' . substr(sha1(rand()), 0, 7);
771 $contactIds = array();
772 // create organization and its duplicate
773 $contactIds = $this->_createContacts(NULL, NULL, $orgnaizationName, 'Organization');
775 /*** Add Membership Type - start ***/
776 $this->addMembershipType($orgnaizationName);
777 /*** Add Membership Type - end ***/
779 //create a New Individual to be related to main organization
780 $firstName = substr(sha1(rand()), 0, 7);
781 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
782 $sortName = "Anderson, $firstName";
784 // go to main organization contact to add membership
785 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['mainId']}");
786 // click through to the membership view screen
787 $this->click("css=li#tab_member a");
789 $this->waitForElementPresent("link=Add Membership");
790 $this->click("link=Add Membership");
792 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
794 // fill in Membership Organization and Type
795 $this->select("membership_type_id[0]", "label={$orgnaizationName}");
796 $this->waitForElementPresent("membership_type_id[1]");
797 // Wait for membership type select to reload
798 $this->waitForTextPresent("Membership Type $orgnaizationName");
799 $this->select("membership_type_id[1]", "label=Membership Type $orgnaizationName");
801 $sourceText = "Membership-Organization Duplicate Merge Webtest";
803 $this->type("source", $sourceText);
805 // Let Join Date stay default
807 // fill in Start Date
808 $this->webtestFillDate('start_date');
811 $this->click("_qf_Membership_upload");
812 $this->waitForElementPresent('crm-notification-container');
814 $this->waitForTextPresent($sourceText);
815 // Is status message correct?
816 $this->waitForText('crm-notification-container', "membership for $orgnaizationName has been added.");
818 // add relationship "Employer of"
819 // click through to the relationship view screen
820 $this->click("css=li#tab_rel a");
822 // wait for add Relationship link
823 $this->waitForElementPresent('link=Add Relationship');
824 $this->click('link=Add Relationship');
826 //choose the created relationship type
827 $this->waitForElementPresent("relationship_type_id");
828 $this->select('relationship_type_id', "value=5_b_a");
830 //fill in the individual
831 $this->select2('related_contact_id', $sortName, TRUE, FALSE);
833 $this->waitForElementPresent("_qf_Relationship_upload");
835 //fill in the relationship start date
836 //$this->webtestFillDate('start_date', '-2 year');
837 //$this->webtestFillDate('end_date', '+1 year');
839 $description = "Well here is some description !!!!";
840 $this->type("description", $description);
842 //save the relationship
843 $this->click("_qf_Relationship_upload");
844 $this->isTextPresent("Current Relationships");
846 //check the status message
847 $this->waitForText('crm-notification-container', "Relationship created.");
849 $this->waitForElementPresent("xpath=//table[@class='crm-contact-relationship-selector-current dataTable no-footer']/tbody//tr/td[9]/span/a[text()='View']");
850 $this->waitForElementPresent("xpath=//a[text()='$sortName']");
851 $this->click("xpath=//a[text()='$sortName']");
852 $this->waitForPageToLoad($this->getTimeoutMsec());
854 // Check if Membership for the individual is created
855 $this->waitForElementPresent("xpath=//li[@id='tab_member']/a/em");
856 $this->verifyText("xpath=//li[@id='tab_member']/a/em", 1);
858 //create a New Individual to be related to duplicate organization
859 $firstNameOther = substr(sha1(rand()), 0, 7);
860 $this->webtestAddContact($firstNameOther, "Harmison", "$firstNameOther@harmison.name");
861 $sortNameOther = "Harmison, $firstNameOther";
863 // go to main organization contact to add membership
864 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['duplicateId']}");
866 // add relationship "Employer of"
867 // click through to the relationship view screen
868 $this->click("css=li#tab_rel a");
870 // wait for add Relationship link
871 $this->waitForElementPresent('link=Add Relationship');
872 $this->click('link=Add Relationship');
874 //choose the created relationship type
875 $this->waitForElementPresent("relationship_type_id");
876 $this->select('relationship_type_id', "value=5_b_a");
878 //fill in the individual
879 $this->select2('related_contact_id', $sortNameOther, TRUE, FALSE);
881 $this->waitForElementPresent("_qf_Relationship_upload");
883 //fill in the relationship start date
884 $this->webtestFillDate('start_date', '-2 year');
885 $this->webtestFillDate('end_date', '+1 year');
887 $description = "Well here is some description !!!!";
888 $this->type("description", $description);
890 //save the relationship
891 //$this->click("_qf_Relationship_upload");
892 $this->click("_qf_Relationship_upload");
893 $this->isTextPresent("Current Relationships");
895 //check the status message
896 $this->isTextPresent("Relationship created.");
898 $this->waitForElementPresent("xpath=//table[@class='crm-contact-relationship-selector-current dataTable no-footer']/tbody//tr/td[9]/span/a[text()='View']");
900 // go directly to contact merge page.
901 $this->openCiviPage("contact/merge", "reset=1&cid={$contactIds['mainId']}&oid={$contactIds['duplicateId']}&action=update&rgid=2");
903 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
904 $this->click('_qf_Merge_next-bottom');
905 $this->waitForPageToLoad($this->getTimeoutMsec());
907 // click through to the relationship view screen
908 $this->click("css=li#tab_rel a");
910 // wait for add Relationship link
911 $this->waitForElementPresent("xpath=//a[text()='$sortName']");
912 // go to duplicate organization's related contact
913 // to check if membership is added to that contact
914 $this->click("xpath=//a[text()='$sortName']");
915 $this->waitForPageToLoad($this->getTimeoutMsec());
917 // Check if Membership for the individual is created
918 $this->waitForElementPresent("xpath=//li[@id='tab_member']/a/em");
919 $this->verifyText("xpath=//li[@id='tab_member']/a/em", 0);
923 * Test for CRM-15658 fix
925 public function testMergeEmailAndAddress() {
926 $this->webtestLogin();
927 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
928 $firstName = substr(sha1(rand()), 0, 7);
929 $this->type('first_name', $firstName);
932 $lastName = substr(sha1(rand()), 0, 7);
933 $this->type('last_name', $lastName);
936 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
939 $this->click("addressBlock");
940 $this->waitForElementPresent("address_1_street_address");
941 $this->type("address_1_street_address", "902C El Camino Way SW");
942 $this->type("address_1_city", "Dumfries");
943 $this->type("address_1_postal_code", "1234");
946 $this->click("_qf_Contact_upload_view");
947 $this->waitForPageToLoad($this->getTimeoutMsec());
948 $this->waitForText('crm-notification-container', "Contact Saved");
950 //duplicate contact with same email id
951 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
952 $firstName2 = substr(sha1(rand()), 0, 7);
953 $this->type('first_name', $firstName2);
956 $lastName2 = substr(sha1(rand()), 0, 7);
957 $this->type('last_name', $lastName2);
960 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
963 $this->click("addressBlock");
964 $this->waitForElementPresent("address_1_street_address");
965 $this->type("address_1_street_address", "2782Y Dowlen Path W");
966 $this->type("address_1_city", "Birmingham");
967 $this->type("address_1_postal_code", "3456");
970 $this->click("_qf_Contact_upload_view");
971 $this->waitForPageToLoad($this->getTimeoutMsec());
972 $this->waitForText('crm-notification-container', "Contact Saved");
974 $this->openCiviPage("contact/dedupefind", "reset=1&action=update&rgid=4");
975 $this->click("//a/span[contains(text(),'Refresh Duplicates')]");
976 $this->assertTrue((bool) preg_match("/This will refresh the duplicates list. Click OK to proceed./", $this->getConfirmation()));
977 $this->chooseOkOnNextConfirmation();
978 $this->waitForPageToLoad($this->getTimeoutMsec());
979 $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
980 $this->clickLink("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
982 //merge without specifying any criteria
983 $this->click("_qf_Merge_next-bottom");
984 $this->waitForPageToLoad($this->getTimeoutMsec());
986 $this->assertTrue($this->isTextPresent('Contacts Merged'));
987 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
988 $this->verifyElementNotPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Home')]");
989 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]"));
990 $this->verifyElementNotPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]");
992 $this->assertElementContainsText('address-block-1', "902C El Camino Way SW");
993 $this->assertElementContainsText('address-block-1', "Dumfries");
994 $this->assertElementContainsText('address-block-1', "1234");
996 $this->assertElementNotContainsText("address-block-2", "2782Y Dowlen Path W");
997 $this->assertElementNotContainsText("address-block-2", "Birmingham");
998 $this->assertElementNotContainsText("address-block-2", "3456");