3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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->markTestSkipped('Skipping for now as it works fine locally.');
40 $this->webtestLogin();
42 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
47 $this->click("prefix_id");
48 $this->select("prefix_id", "label=$prefix");
51 $firstName = substr(sha1(rand()), 0, 7);
52 $this->type('first_name', $firstName);
55 $lastName = substr(sha1(rand()), 0, 7);
56 $this->type('last_name', $lastName);
59 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
61 //fill in billing email id
62 $this->click('addEmail');
63 $this->waitForElementPresent('email_2_email');
64 $this->type('email_2_email', "$firstName.$lastName@billing.com");
65 $this->select('email_2_location_type_id', 'value=5');
68 $this->click("_qf_Contact_upload_view");
69 $this->waitForPageToLoad($this->getTimeoutMsec());
70 $this->waitForText('crm-notification-container', "Contact Saved");
72 // Add Contact to a group
73 $group = 'Newsletter Subscribers';
74 $this->click('css=li#tab_group a');
75 $this->waitForElementPresent('_qf_GroupContact_next');
76 $this->select('group_id', "label=$group");
77 $this->click('_qf_GroupContact_next');
78 $this->waitForElementPresent('link=Delete');
79 $this->waitForText('crm-notification-container', "Added to Group");
81 // Add Tags to the contact
82 $tag = 'Government Entity';
83 $this->click("css=li#tab_tag a");
84 $this->waitForElementPresent('tagtree');
85 $this->click("xpath=//div[@id='tagtree']/ul//li/input/../span/label[text()='$tag']");
86 $this->click("css=#tab_summary a");
87 $this->assertElementContainsText('css=.crm-summary-block #tags', $tag);
90 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
91 $this->addActivity($firstName, $lastName, $subject);
93 // contact2: duplicate of contact1.
94 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
97 $this->type("first_name", $firstName);
100 $this->type("last_name", $lastName);
103 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
106 $this->click("_qf_Contact_refresh_dedupe");
107 $this->waitForPageToLoad($this->getTimeoutMsec());
109 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
110 $this->click("_qf_Contact_upload_duplicate");
111 $this->waitForPageToLoad($this->getTimeoutMsec());
112 $this->waitForText('crm-notification-container', "Contact Saved");
114 // Add second pair of dupes so we can test Merge and Goto Next Pair
116 $lname2 = 'Rogers' . substr(sha1(rand()), 0, 7);
117 $email2 = "{$fname2}.{$lname2}@example.org";
118 $this->webtestAddContact($fname2, $lname2, $email2);
120 // Can not use helper for 2nd contact since it is a dupe
121 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
122 $this->type("first_name", $fname2);
123 $this->type("last_name", $lname2);
124 $this->type("email_1_email", $email2);
125 $this->click("_qf_Contact_refresh_dedupe");
126 $this->waitForPageToLoad($this->getTimeoutMsec());
127 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
128 $this->click("_qf_Contact_upload_duplicate");
129 $this->waitForPageToLoad($this->getTimeoutMsec());
130 $this->waitForText('crm-notification-container', "Contact Saved");
132 // Find and Merge Contacts with Supervised Rule
133 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
136 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=update");
138 // Select the contacts to be merged
139 $this->waitForElementPresent('dupePairs_length');
140 $this->select("name=dupePairs_length", "value=100");
141 $this->waitForElementPresent("xpath=//table[@id='dupePairs']/tbody//tr/td[5]/a[text()='$firstName $lastName']/../../td[8]/a[text()='merge']");
142 $this->click("xpath=//table[@id='dupePairs']/tbody//tr/td[5]/a[text()='$firstName $lastName']/../../td[8]/a[text()='merge']");
143 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
145 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", '_qf_Merge_cancel-bottom');
147 // Move the activities, groups, etc to the main contact and merge using Merge and Goto Next Pair
148 $this->check('move_prefix_id');
149 $this->check('move_location_email_2');
150 $this->check('move_rel_table_activities');
151 $this->check('move_rel_table_groups');
152 $this->check('move_rel_table_tags');
153 $this->clickLink('_qf_Merge_next-bottom', '_qf_Merge_cancel-bottom');
154 $this->assertTrue($this->isTextPresent('Contacts Merged'), "Contacts Merged text was not found after merge.");
156 // Check that we are viewing the next Merge Pair (our 2nd contact, since the merge list is ordered by contact_id)
157 $this->assertTrue($this->isTextPresent("{$fname2} {$lname2}"), "Redirect for Goto Next Pair after merge did not work.");
159 // Ensure that the duplicate contact has been deleted
160 $this->openCiviPage("contact/search/advanced", "reset=1", '_qf_Advanced_refresh');
161 $this->type('sort_name', $firstName);
162 $this->click('deleted_contacts');
163 $this->click('_qf_Advanced_refresh');
164 $this->waitForPageToLoad($this->getTimeoutMsec());
165 $this->assertTrue($this->isTextPresent('1 Contact'), "Deletion of duplicate contact during merge was not successful. Dupe contact not found when searching trash.");
167 // Search for the main contact
168 $this->openCiviPage("contact/search/advanced", "reset=1", '_qf_Advanced_refresh');
169 $this->type('sort_name', $firstName);
170 $this->click('_qf_Advanced_refresh');
171 $this->waitForElementPresent("xpath=//form[@id='Advanced']/div[3]/div/div[2]/table/tbody/tr");
173 $this->click("//form[@id='Advanced']/div[3]/div/div[2]/table/tbody/tr/td[11]/span[1]/a[text()='View']");
174 $this->waitForPageToLoad($this->getTimeoutMsec());
176 // Verify prefix merged
177 // $this->verifyText( "xpath=//div[@class='left-corner']/h2", preg_quote( "$prefix $firstName $lastName" ) );
179 // Verify billing email merged
180 $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']");
182 // Verify activity merged
183 $this->click("css=li#tab_activity a");
184 $this->waitForAjaxContent();
185 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr");
186 $this->verifyText("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[5]/a", 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=//table[@id='dupePairs']/tbody//tr/td[3]/a[text()='{$firstName} {$lastName}']/../../td[8]/a[2][text()='merge']");
244 $this->waitForElementPresent("xpath=//form[@id='DedupeFind']//a/span[contains(text(),'Done')]");
245 $this->isElementPresent("xpath=//table[@id='dupePairs']/tbody//tr//td/a[text()='$firstName $lastName']/../../td[5]/a[text()='{$fName} {$lName}']/../../td[8]/a[text()='merge']");
246 $this->click("xpath=//table[@id='dupePairs']/tbody//tr/td[3]/a[text()='{$firstName} {$lastName}']/../../td[8]/a[2][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->waitForElementPresent('dupePairs_length');
385 $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']");
386 $this->click("xpath=//a[text()='$firstName $lastName']/../../td[8]/a[text()='merge']");
387 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
388 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a");
390 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(overwrite)']");
391 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[5]/td[4]/span[text()='(add)']");
392 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
394 $this->check("move_location_email_1");
395 $this->check("location[email][1][operation]");
396 $this->check("move_location_email_2");
397 $this->check("move_location_phone_1");
398 $this->check("location[phone][1][operation]");
399 $this->check("move_location_phone_2");
400 $this->click("_qf_Merge_next-bottom");
401 $this->waitForPageToLoad($this->getTimeoutMsec());
403 $this->assertTrue($this->isTextPresent('Contacts Merged'));
404 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
405 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]"));
406 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
407 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]"));
408 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
409 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[2]/a[contains(text(), '$firstName.$lastName@billing.com')]"));
410 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
411 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543211')]"));
412 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
413 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
414 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
415 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[2][contains(text(), '9876543120')]"));
417 //Merge with the feature of (add)
418 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
422 $firstName1 = substr(sha1(rand()), 0, 7);
423 $this->type('first_name', $firstName1);
426 $lastName1 = substr(sha1(rand()), 0, 7);
427 $this->type('last_name', $lastName1);
429 //fill in billing email id
430 $this->waitForElementPresent('email_1_email');
431 $this->type('email_1_email', "$firstName1.$lastName1@example.com");
432 $this->select('email_1_location_type_id', 'value=5');
434 $this->click('addEmail');
435 $this->waitForElementPresent('email_2_email');
436 $this->type('email_2_email', "$firstName.$lastName@home.com");
437 $this->select('email_2_location_type_id', 'value=1');
439 //fill in home phone no
440 $this->type('phone_1_phone', "9876543210");
443 $this->click("_qf_Contact_upload_view");
444 $this->waitForPageToLoad($this->getTimeoutMsec());
445 $this->waitForText('crm-notification-container', "Contact Saved");
447 // contact2: duplicate of contact1.
448 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
451 $this->type("first_name", $firstName1);
454 $this->type("last_name", $lastName1);
457 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
459 //fill in billing phone no
460 $this->type('phone_1_phone', "9876543120");
461 $this->select('phone_1_location_type_id', 'value=5');
464 $this->click("_qf_Contact_refresh_dedupe");
465 $this->waitForPageToLoad($this->getTimeoutMsec());
466 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
467 $this->click("_qf_Contact_upload_duplicate");
468 $this->waitForPageToLoad($this->getTimeoutMsec());
469 $this->waitForText('crm-notification-container', "Contact Saved");
471 // Find and Merge Contacts with Supervised Rule
472 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
474 // Select the contacts to be merged
475 $this->waitForElementPresent('dupePairs_length');
476 $this->waitForElementPresent("xpath=//a[text()='$firstName1 $lastName1']");
477 $this->click("xpath=//a[text()='$firstName1 $lastName1']/../../td[8]/a[text()='merge']");
478 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
479 $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)']");
480 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']");
481 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']");
482 $this->select('location_email_1_locTypeId', 'value=3');
483 $this->select('location_phone_1_locTypeId', 'value=1');
484 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']"));
485 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']"));
486 $this->assertTrue($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']"));
487 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
489 $this->check("move_location_email_1");
490 $this->check("move_location_phone_1");
491 $this->click("_qf_Merge_next-bottom");
492 $this->waitForPageToLoad($this->getTimeoutMsec());
494 $this->assertTrue($this->isTextPresent('Contacts Merged'));
495 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
496 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[contains(text(), '{$firstName1}.{$lastName1}@example.com')]"));
497 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Main')]"));
498 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[contains(text(), '{$firstName1}.{$lastName1}@example.com')]"));
499 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Billing')]"));
500 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543120')]"));
501 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
502 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
505 public function testBatchMerge() {
506 $this->webtestLogin();
508 // add contact1 and its duplicate
510 $firstName = "Kerry" . substr(sha1(rand()), 0, 7);
512 $lastName = "King" . substr(sha1(rand()), 0, 7);
513 $this->_createContacts($firstName, $lastName);
515 //add contact2 and its duplicate
516 //These are the contacts with conflicts in communication preference.these contacts will be skipped during merge.
517 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
520 $firstName1 = "Kurt" . substr(sha1(rand()), 0, 7);
521 $this->type('first_name', $firstName1);
524 $lastName1 = "Cobain" . substr(sha1(rand()), 0, 7);
525 $this->type('last_name', $lastName1);
528 $this->type('email_1_email', "{$firstName1}.{$lastName1}@example.com");
530 //fill in billing email id
531 $this->click('addEmail');
532 $this->waitForElementPresent('email_2_email');
533 $this->type('email_2_email', "$firstName1.$lastName1@billing.com");
534 $this->select('email_2_location_type_id', 'value=5');
536 //fill in home phone no
537 $this->type('phone_1_phone', "9876543210");
539 //fill in billing phone id
540 $this->click('addPhone');
541 $this->waitForElementPresent('phone_2_phone');
542 $this->type('phone_2_phone', "9876543120");
543 $this->select('phone_2_location_type_id', 'value=5');
545 //select communication preference
546 $this->check("privacy[do_not_phone]");
549 $this->click("_qf_Contact_upload_view");
550 $this->waitForPageToLoad($this->getTimeoutMsec());
551 $this->waitForText('crm-notification-container', "Contact Saved");
553 //duplicate of contact2.
554 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
557 $this->type("first_name", $firstName1);
560 $this->type("last_name", $lastName1);
563 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
565 //fill in home phone no
566 $this->type('phone_1_phone', "9876543211");
568 //select communication preference
569 $this->check("preferred_communication_method[1]");
572 $this->click("_qf_Contact_refresh_dedupe");
573 $this->waitForPageToLoad($this->getTimeoutMsec());
575 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
576 $this->click("_qf_Contact_upload_duplicate");
577 $this->waitForPageToLoad($this->getTimeoutMsec());
578 $this->waitForText('crm-notification-container', "Contact Saved");
580 // add contact3 and its duplicate
582 $firstName2 = "David" . substr(sha1(rand()), 0, 7);
584 $lastName2 = "Gilmour" . substr(sha1(rand()), 0, 7);
585 $this->_createContacts($firstName2, $lastName2);
587 // add contact4 and its duplicate
589 $firstName3 = "Dave" . substr(sha1(rand()), 0, 7);
591 $lastName3 = "Mustaine" . substr(sha1(rand()), 0, 7);
592 $this->_createContacts($firstName3, $lastName3);
594 // Find and Merge Contacts with Supervised Rule
595 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew", "dupePairs");
597 $this->waitForElementPresent('dupePairs_length');
598 $this->select("name=dupePairs_length", "value=100");
599 $totalContacts = $this->getXpathCount("//table[@id='dupePairs']/tbody/tr");
600 $this->click("//form[@id='DedupeFind']//a/span[contains(text(),' Batch Merge All Duplicates')]");
602 // Check confirmation alert.
604 (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./",
605 $this->getConfirmation()
608 $this->chooseOkOnNextConfirmation();
609 $this->waitForPageToLoad($this->getTimeoutMsec());
610 $this->waitForElementPresent('civicrm-footer');
611 $this->waitForElementPresent("crm-main-content-wrapper");
613 // If we are still on the dedupe table page, count unmerged contacts
614 if ($this->isElementPresent("//table[@class='pagerDisplay']")) {
615 // Wait for datatable to load
616 $this->waitForElementPresent("//table[@class='pagerDisplay']/tbody/tr");
617 $unMergedContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
620 $unMergedContacts = 0;
623 $mergedContacts = $totalContacts - $unMergedContacts;
625 //check the existence of merged contacts
626 $contactEmails = array(
627 1 => "{$firstName}.{$lastName}@example.com",
628 2 => "{$firstName2}.{$lastName2}@example.com",
629 3 => "{$firstName3}.{$lastName3}@example.com",
632 foreach ($contactEmails as $key => $value) {
633 $this->click('sort_name_navigation');
634 $this->type('css=input#sort_name_navigation', $value);
635 $this->typeKeys('css=input#sort_name_navigation', $value);
636 // Wait for result list.
637 $this->waitForElementPresent("css=ul.ui-autocomplete li.ui-menu-item");
639 // Visit contact summary page.
640 $this->clickLink("css=ul.ui-autocomplete li.ui-menu-item", 'civicrm-footer');
646 * @param null $firstName
647 * @param null $lastName
648 * @param null $organizationName
649 * @param string $contactType
652 public function _createContacts($firstName = NULL, $lastName = NULL, $organizationName = NULL, $contactType = 'Individual') {
653 if ($contactType == 'Individual') {
655 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
657 $this->type('first_name', $firstName);
660 $this->type('last_name', $lastName);
663 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
665 //fill in billing email id
666 $this->click('addEmail');
667 $this->waitForElementPresent('email_2_email');
668 $this->type('email_2_email', "$firstName.$lastName@billing.com");
669 $this->select('email_2_location_type_id', 'value=5');
672 $this->click("_qf_Contact_upload_view");
673 $this->waitForPageToLoad($this->getTimeoutMsec());
674 $this->waitForText('crm-notification-container', "Contact Saved");
676 //duplicate of above contact.
677 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
680 $this->type("first_name", $firstName);
683 $this->type("last_name", $lastName);
686 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
689 $this->click("_qf_Contact_refresh_dedupe");
690 $this->waitForPageToLoad($this->getTimeoutMsec());
692 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
693 $this->click("_qf_Contact_upload_duplicate");
694 $this->waitForPageToLoad($this->getTimeoutMsec());
695 $this->waitForText('crm-notification-container', "Contact Saved");
697 elseif ($contactType == 'Organization') {
699 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
700 //fill in Organization name
701 $this->type('organization_name', $organizationName);
704 $this->type('email_1_email', "{$organizationName}@org.com");
706 $this->click("_qf_Contact_upload_view-bottom");
707 $this->waitForPageToLoad($this->getTimeoutMsec());
708 $this->waitForText('crm-notification-container', "Contact Saved");
709 $mainId = explode("Contact ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
710 $mainId = trim($mainId[1]);
712 //Duplicate of above contact.
713 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
715 //fill in Organization name
716 $this->type('organization_name', $organizationName);
719 $this->type('email_1_email', "{$organizationName}@org.com");
722 $this->click("_qf_Contact_upload_view-bottom");
723 $this->waitForPageToLoad($this->getTimeoutMsec());
725 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
726 $this->click("_qf_Contact_upload_duplicate");
727 $this->waitForPageToLoad($this->getTimeoutMsec());
728 $this->waitForText('crm-notification-container', "Contact Saved");
729 $duplicateId = explode("Contact ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
730 $duplicateId = trim($duplicateId[1]);
734 'duplicateId' => $duplicateId,
741 * to create new membership type
742 * @param $membershipOrganization
744 public function addMembershipType($membershipOrganization) {
745 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
746 $this->click("link=Add Membership Type");
747 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
749 $this->type('name', "Membership Type $membershipOrganization");
750 $this->select2('member_of_contact_id', $membershipOrganization);
752 $this->type('minimum_fee', '1');
753 $this->select('financial_type_id', 'value=2');
754 $this->type('duration_interval', 1);
755 $this->select('duration_unit', "label=year");
757 $this->select('period_type', "label=Fixed");
758 $this->waitForElementPresent('fixed_period_rollover_day[d]');
760 // fixed period start set to April 1
761 $this->select('fixed_period_start_day[M]', 'value=4');
762 // rollover date set to Jan 31
763 $this->select('fixed_period_rollover_day[M]', 'value=1');
765 // Employer of relationship
766 $this->select('relationship_type_id', 'value=5_b_a');
767 $this->click('_qf_MembershipType_upload-bottom');
768 $this->waitForElementPresent('link=Add Membership Type');
769 $this->waitForText("crm-notification-container", "The membership type 'Membership Type $membershipOrganization' has been saved.");
773 * Test for CRM-12695 fix
775 public function testMergeOrganizations() {
776 $this->webtestLogin();
778 // build organisation name
779 $orgnaizationName = 'org_' . substr(sha1(rand()), 0, 7);
781 $contactIds = array();
782 // create organization and its duplicate
783 $contactIds = $this->_createContacts(NULL, NULL, $orgnaizationName, 'Organization');
785 /*** Add Membership Type - start ***/
786 $this->addMembershipType($orgnaizationName);
787 /*** Add Membership Type - end ***/
789 //create a New Individual to be related to main organization
790 $firstName = substr(sha1(rand()), 0, 7);
791 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
792 $sortName = "Anderson, $firstName";
794 // go to main organization contact to add membership
795 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['mainId']}");
796 // click through to the membership view screen
797 $this->click("css=li#tab_member a");
799 $this->waitForElementPresent("link=Add Membership");
800 $this->click("link=Add Membership");
802 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
804 // fill in Membership Organization and Type
805 $this->select("membership_type_id[0]", "label={$orgnaizationName}");
806 $this->waitForElementPresent("membership_type_id[1]");
807 // Wait for membership type select to reload
808 $this->waitForTextPresent("Membership Type $orgnaizationName");
809 $this->select("membership_type_id[1]", "label=Membership Type $orgnaizationName");
811 $sourceText = "Membership-Organization Duplicate Merge Webtest";
813 $this->type("source", $sourceText);
815 // Let Join Date stay default
817 // fill in Start Date
818 $this->webtestFillDate('start_date');
821 $this->click("_qf_Membership_upload");
822 $this->waitForElementPresent('crm-notification-container');
824 $this->waitForTextPresent($sourceText);
825 // Is status message correct?
826 $this->waitForText('crm-notification-container', "membership for $orgnaizationName has been added.");
828 // add relationship "Employer of"
829 // click through to the relationship view screen
830 $this->click("css=li#tab_rel a");
832 // wait for add Relationship link
833 $this->waitForElementPresent('link=Add Relationship');
834 $this->click('link=Add Relationship');
836 //choose the created relationship type
837 $this->waitForElementPresent("relationship_type_id");
838 $this->select('relationship_type_id', "value=5_b_a");
840 //fill in the individual
841 $this->waitForElementPresent('related_contact_id');
842 $this->select2('related_contact_id', $sortName, TRUE, FALSE);
844 $this->waitForElementPresent("_qf_Relationship_upload");
846 //fill in the relationship start date
847 //$this->webtestFillDate('start_date', '-2 year');
848 //$this->webtestFillDate('end_date', '+1 year');
850 $description = "Well here is some description !!!!";
851 $this->type("description", $description);
853 //save the relationship
854 $this->click("_qf_Relationship_upload");
855 $this->isTextPresent("Current Relationships");
857 //check the status message
858 $this->waitForText('crm-notification-container', "Relationship created.");
859 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]/span/a[text()='View']");
860 $this->waitForAjaxContent();
861 $this->click("xpath=//a[text()='$sortName']");
862 $this->waitForAjaxContent();
864 // Check if Membership for the individual is created
865 $this->waitForElementPresent("xpath=//li[@id='tab_member']/a/em");
866 $this->verifyText("xpath=//li[@id='tab_member']/a/em", 1);
868 //create a New Individual to be related to duplicate organization
869 $firstNameOther = substr(sha1(rand()), 0, 7);
870 $this->webtestAddContact($firstNameOther, "Harmison", "$firstNameOther@harmison.name");
871 $sortNameOther = "Harmison, $firstNameOther";
873 // go to main organization contact to add membership
874 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['duplicateId']}");
876 // add relationship "Employer of"
877 // click through to the relationship view screen
878 $this->click("css=li#tab_rel a");
880 // wait for add Relationship link
881 $this->waitForElementPresent('link=Add Relationship');
882 $this->click('link=Add Relationship');
884 //choose the created relationship type
885 $this->waitForElementPresent("relationship_type_id");
886 $this->select('relationship_type_id', "value=5_b_a");
888 //fill in the individual
889 $this->waitForElementPresent('related_contact_id');
890 $this->select2('related_contact_id', $sortNameOther, TRUE, FALSE);
892 $this->waitForElementPresent("_qf_Relationship_upload");
894 //fill in the relationship start date
895 $this->webtestFillDate('start_date', '-2 year');
896 $this->webtestFillDate('end_date', '+1 year');
898 $description = "Well here is some description !!!!";
899 $this->type("description", $description);
901 //save the relationship
902 //$this->click("_qf_Relationship_upload");
903 $this->click("_qf_Relationship_upload");
904 $this->isTextPresent("Current Relationships");
906 //check the status message
907 $this->isTextPresent("Relationship created.");
909 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]/span/a[text()='View']");
911 // go directly to contact merge page.
912 $this->openCiviPage("contact/merge", "reset=1&cid={$contactIds['mainId']}&oid={$contactIds['duplicateId']}&action=update&rgid=2");
914 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
915 $this->click('_qf_Merge_next-bottom');
916 $this->waitForPageToLoad($this->getTimeoutMsec());
918 // click through to the relationship view screen
919 $this->click("css=li#tab_rel a");
921 // wait for add Relationship link
922 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody//tr//td//a[text()='$sortName']");
923 // go to duplicate organization's related contact
924 // to check if membership is added to that contact
925 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody//tr//td//a[text()='$sortName']");
926 $this->waitForPageToLoad($this->getTimeoutMsec());
928 // Check if Membership for the individual is created
929 $this->waitForElementPresent("xpath=//li[@id='tab_member']/a/em");
930 $this->verifyText("xpath=//li[@id='tab_member']/a/em", 0);
934 * Test for CRM-15658 fix
936 public function testMergeEmailAndAddress() {
937 $this->webtestLogin();
938 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
939 $firstName = substr(sha1(rand()), 0, 7);
940 $this->type('first_name', $firstName);
943 $lastName = substr(sha1(rand()), 0, 7);
944 $this->type('last_name', $lastName);
947 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
950 $this->click("addressBlock");
951 $this->waitForElementPresent("address_1_street_address");
952 $this->type("address_1_street_address", "902C El Camino Way SW");
953 $this->type("address_1_city", "Dumfries");
954 $this->type("address_1_postal_code", "1234");
957 $this->click("_qf_Contact_upload_view");
958 $this->waitForPageToLoad($this->getTimeoutMsec());
959 $this->waitForText('crm-notification-container', "Contact Saved");
961 //duplicate contact with same email id
962 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
963 $firstName2 = substr(sha1(rand()), 0, 7);
964 $this->type('first_name', $firstName2);
967 $lastName2 = substr(sha1(rand()), 0, 7);
968 $this->type('last_name', $lastName2);
971 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
974 $this->click("addressBlock");
975 $this->waitForElementPresent("address_1_street_address");
976 $this->type("address_1_street_address", "2782Y Dowlen Path W");
977 $this->type("address_1_city", "Birmingham");
978 $this->type("address_1_postal_code", "3456");
981 $this->click("_qf_Contact_upload_view");
982 $this->waitForPageToLoad($this->getTimeoutMsec());
983 $this->waitForText('crm-notification-container', "Contact Saved");
985 $this->openCiviPage("contact/dedupefind", "reset=1&action=update&rgid=4");
986 $this->click("//a/span[contains(text(),'Refresh Duplicates')]");
987 $this->assertTrue((bool) preg_match("/This will refresh the duplicates list. Click OK to proceed./", $this->getConfirmation()));
988 $this->chooseOkOnNextConfirmation();
989 $this->waitForPageToLoad($this->getTimeoutMsec());
990 $this->waitForElementPresent("xpath=//table[@id='dupePairs']/tbody//tr/td[3]/a[text()='$firstName $lastName']/../../td[8]//a[text()='merge']");
991 $this->click("xpath=//table[@id='dupePairs']/tbody//tr/td[3]/a[text()='$firstName $lastName']/../../td[8]//a[text()='merge']");
992 $this->waitForPageToLoad($this->getTimeoutMsec());
994 //merge without specifying any criteria
995 $this->click("_qf_Merge_next-bottom");
996 $this->waitForPageToLoad($this->getTimeoutMsec());
998 $this->assertTrue($this->isTextPresent('Contacts Merged'));
999 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
1000 $this->verifyElementNotPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Home')]");
1001 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]"));
1002 $this->verifyElementNotPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]");
1004 $this->assertElementContainsText('address-block-1', "902C El Camino Way SW");
1005 $this->assertElementContainsText('address-block-1', "Dumfries");
1006 $this->assertElementContainsText('address-block-1', "1234");
1008 $this->assertElementNotContainsText("address-block-2", "2782Y Dowlen Path W");
1009 $this->assertElementNotContainsText("address-block-2", "Birmingham");
1010 $this->assertElementNotContainsText("address-block-2", "3456");