3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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->waitForElementPresent("xpath=//table[@class='dataTable no-footer']/tbody/tr");
185 $this->verifyText("xpath=//table[@class='dataTable no-footer']/tbody/tr/td[5]/a", preg_quote("$lastName, $firstName"));
187 // Verify group merged
188 $this->click("css=li#tab_group a");
189 $this->waitForElementPresent("GroupContact");
190 $this->waitForElementPresent("xpath=//form[@id='GroupContact']//div[@class='view-content view-contact-groups']//div/table/tbody/tr/td/a");
191 $this->verifyText("xpath=//form[@id='GroupContact']//div[@class='view-content view-contact-groups']//div/table/tbody/tr/td/a",
196 $this->click("css=li#tab_tag a");
197 $this->waitForElementPresent('check_5');
198 $this->assertChecked("check_3");
201 public function testMergeContactSubType() {
202 $this->webtestLogin();
203 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
204 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
206 $firstName = "Anderson" . substr(sha1(rand()), 0, 4);
207 $this->type('first_name', $firstName);
210 $lastName = substr(sha1(rand()), 0, 4);
211 $this->type('last_name', $lastName);
214 $this->waitForElementPresent('email_1_email');
215 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
216 $this->waitForElementPresent('contact_sub_type');
217 $this->select('contact_sub_type', "Parent");
220 $this->click("_qf_Contact_upload_view");
221 $this->waitForPageToLoad($this->getTimeoutMsec());
222 $this->waitForText('crm-notification-container', "Contact Saved");
224 // contact2: contact with same email id as contact 1.
225 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
226 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
228 $fName = "John" . substr(sha1(rand()), 0, 4);
229 $this->type('first_name', $fName);
230 $lName = substr(sha1(rand()), 0, 4);
231 $this->type('last_name', $lName);
232 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
233 $this->waitForElementPresent('contact_sub_type');
234 $this->multiselect2('contact_sub_type', array("Student", "Staff"));
235 $this->click("_qf_Contact_upload_view");
236 $this->waitForText('crm-notification-container', "Contact Saved");
237 $this->openCiviPage("contact/deduperules", "reset=1");
238 $this->click("xpath=//*[@id='option12']/tbody/tr[3]/td[3]/span/a[1][contains(text(),'Use Rule')]");
239 $this->waitForElementPresent('_qf_DedupeFind_submit-bottom');
240 $this->click("_qf_DedupeFind_next-bottom");
242 $this->waitForElementPresent("xpath=//table[@id='dupePairs']/tbody//tr/td[5]/a[text()='$firstName $lastName']/../../td[8]/a[text()='merge']");
243 $this->waitForElementPresent("xpath=//form[@id='DedupeFind']//a/span[contains(text(),'Done')]");
244 $this->isElementPresent("xpath=//table[@id='dupePairs']/tbody//tr//td/a[text()='$firstName $lastName']/../../td[5]/a[text()='{$fName} {$lName}']/../../td[8]/a[text()='merge']");
245 $this->click("xpath=//table[@id='dupePairs']/tbody//tr//td/a[text()='{$firstName} {$lastName}']/../../td[8]/a[text()='merge']");
246 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
247 $this->click('toggleSelect');
248 $this->click('_qf_Merge_next-bottom');
249 $this->waitForPageToLoad($this->getTimeoutMsec());
250 $this->assertTrue($this->isTextPresent("Staff, Student"));
254 * @param string $firstName
255 * @param string $lastName
258 public function addActivity($firstName, $lastName, $subject) {
259 $withContact = substr(sha1(rand()), 0, 7);
260 $this->webtestAddContact($withContact, "Anderson", $withContact . "@anderson.name");
262 $this->click("css=li#tab_activity a");
264 // waiting for the activity dropdown to show up
265 $this->waitForElementPresent("other_activity");
267 // Select the activity type from the activity dropdown
268 $this->select("other_activity", "label=Meeting");
270 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
271 // button at the end of this page to show up, to make sure it's fully loaded.
272 $this->waitForElementPresent("_qf_Activity_upload");
274 // ...and verifying if the page contains properly formatted display name for chosen contact.
275 $this->assertTrue($this->isTextPresent("Anderson, " . $withContact), "Contact not found in line " . __LINE__
);
277 // Now we're filling the "Assigned To" field.
278 // Typing contact's name into the field (using typeKeys(), not type()!)...
279 $this->select2("assignee_contact_id", $firstName, TRUE, FALSE);
281 // ...and verifying if the page contains properly formatted display name for chosen contact.
282 $this->assertTrue($this->isTextPresent("$lastName, " . $firstName), "Contact not found in line " . __LINE__
);
284 // Since we're here, let's check if screen help is being displayed properly
285 $this->assertTrue($this->isTextPresent("A copy of this activity will be emailed to each Assignee."));
287 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
288 // For simple input fields we can use field id as selector
289 $this->type("subject", $subject);
290 $this->type("location", "Some location needs to be put in this field.");
292 // Choosing the Date.
293 // Please note that we don't want to put in fixed date, since
294 // we want this test to work in the future and not fail because
295 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
296 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
299 $this->type("duration", "30");
301 // Putting in details.
302 $this->type("details", "Really brief details information.");
304 // Making sure that status is set to Scheduled (using value, not label).
305 $this->select("status_id", "value=1");
308 $this->select("priority_id", "value=1");
311 $this->click("_qf_Activity_upload");
312 $this->waitForElementPresent("crm-notification-container");
314 // Is status message correct?
315 $this->waitForText('crm-notification-container', "Activity '$subject' has been saved.", "Status message didn't show up after saving!");
318 public function testMergeTest() {
319 $this->webtestLogin();
321 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
325 $firstName = substr(sha1(rand()), 0, 7);
326 $this->type('first_name', $firstName);
329 $lastName = substr(sha1(rand()), 0, 7);
330 $this->type('last_name', $lastName);
333 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
335 //fill in billing email id
336 $this->click('addEmail');
337 $this->waitForElementPresent('email_2_email');
338 $this->type('email_2_email', "$firstName.$lastName@billing.com");
339 $this->select('email_2_location_type_id', 'value=5');
341 //fill in home phone no
342 $this->type('phone_1_phone', "9876543210");
344 //fill in billing phone id
345 $this->click('addPhone');
346 $this->waitForElementPresent('phone_2_phone');
347 $this->type('phone_2_phone', "9876543120");
348 $this->select('phone_2_location_type_id', 'value=5');
351 $this->click("_qf_Contact_upload_view");
352 $this->waitForPageToLoad($this->getTimeoutMsec());
353 $this->waitForText('crm-notification-container', "Contact Saved");
355 // contact2: duplicate of contact1.
356 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
359 $this->type("first_name", $firstName);
362 $this->type("last_name", $lastName);
365 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
367 //fill in home phone no
368 $this->type('phone_1_phone', "9876543211");
371 $this->click("_qf_Contact_refresh_dedupe");
372 $this->waitForPageToLoad($this->getTimeoutMsec());
374 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
375 $this->click("_qf_Contact_upload_duplicate");
376 $this->waitForPageToLoad($this->getTimeoutMsec());
377 $this->waitForText('crm-notification-container', "Contact Saved");
379 // Find and Merge Contacts with Supervised Rule
380 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
382 // Select the contacts to be merged
383 $this->waitForElementPresent('dupePairs_length');
384 $this->select("name=dupePairs_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->waitForElementPresent('dupePairs_length');
474 $this->select("name=dupePairs_length", "value=100");
475 $this->waitForElementPresent("xpath=//table[@class='pagerDisplay dataTable no-footer']/tbody//tr/td[1]/a[text()='$firstName1 $lastName1']/../../td[2]/a[text()='$firstName1 $lastName1']");
476 $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']");
477 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
478 $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)']");
479 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']");
480 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']");
481 $this->select('location_email_1_locTypeId', 'value=3');
482 $this->select('location_phone_1_locTypeId', 'value=1');
483 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']"));
484 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']"));
485 $this->assertTrue($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']"));
486 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
488 $this->check("move_location_email_1");
489 $this->check("move_location_phone_1");
490 $this->click("_qf_Merge_next-bottom");
491 $this->waitForPageToLoad($this->getTimeoutMsec());
493 $this->assertTrue($this->isTextPresent('Contacts Merged'));
494 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
495 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[contains(text(), '{$firstName1}.{$lastName1}@example.com')]"));
496 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Main')]"));
497 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[contains(text(), '{$firstName1}.{$lastName1}@example.com')]"));
498 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Billing')]"));
499 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543120')]"));
500 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
501 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
504 public function testBatchMerge() {
505 $this->webtestLogin();
507 // add contact1 and its duplicate
509 $firstName = "Kerry" . substr(sha1(rand()), 0, 7);
511 $lastName = "King" . substr(sha1(rand()), 0, 7);
512 $this->_createContacts($firstName, $lastName);
514 //add contact2 and its duplicate
515 //These are the contacts with conflicts in communication preference.these contacts will be skipped during merge.
516 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
519 $firstName1 = "Kurt" . substr(sha1(rand()), 0, 7);
520 $this->type('first_name', $firstName1);
523 $lastName1 = "Cobain" . substr(sha1(rand()), 0, 7);
524 $this->type('last_name', $lastName1);
527 $this->type('email_1_email', "{$firstName1}.{$lastName1}@example.com");
529 //fill in billing email id
530 $this->click('addEmail');
531 $this->waitForElementPresent('email_2_email');
532 $this->type('email_2_email', "$firstName1.$lastName1@billing.com");
533 $this->select('email_2_location_type_id', 'value=5');
535 //fill in home phone no
536 $this->type('phone_1_phone', "9876543210");
538 //fill in billing phone id
539 $this->click('addPhone');
540 $this->waitForElementPresent('phone_2_phone');
541 $this->type('phone_2_phone', "9876543120");
542 $this->select('phone_2_location_type_id', 'value=5');
544 //select communication preference
545 $this->check("privacy[do_not_phone]");
548 $this->click("_qf_Contact_upload_view");
549 $this->waitForPageToLoad($this->getTimeoutMsec());
550 $this->waitForText('crm-notification-container', "Contact Saved");
552 //duplicate of contact2.
553 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
556 $this->type("first_name", $firstName1);
559 $this->type("last_name", $lastName1);
562 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
564 //fill in home phone no
565 $this->type('phone_1_phone', "9876543211");
567 //select communication preference
568 $this->check("preferred_communication_method[1]");
571 $this->click("_qf_Contact_refresh_dedupe");
572 $this->waitForPageToLoad($this->getTimeoutMsec());
574 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
575 $this->click("_qf_Contact_upload_duplicate");
576 $this->waitForPageToLoad($this->getTimeoutMsec());
577 $this->waitForText('crm-notification-container', "Contact Saved");
579 // add contact3 and its duplicate
581 $firstName2 = "David" . substr(sha1(rand()), 0, 7);
583 $lastName2 = "Gilmour" . substr(sha1(rand()), 0, 7);
584 $this->_createContacts($firstName2, $lastName2);
586 // add contact4 and its duplicate
588 $firstName3 = "Dave" . substr(sha1(rand()), 0, 7);
590 $lastName3 = "Mustaine" . substr(sha1(rand()), 0, 7);
591 $this->_createContacts($firstName3, $lastName3);
593 // Find and Merge Contacts with Supervised Rule
594 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew", "css=#DedupeFind table.pagerDisplay tbody tr");
596 $this->waitForElementPresent('dupePairs_length');
597 $this->select("name=dupePairs_length", "value=100");
598 $totalContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
599 $this->click("//form[@id='DedupeFind']//a/span[contains(text(),'Batch Merge Duplicates')]");
601 // Check confirmation alert.
603 (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./",
604 $this->getConfirmation()
607 $this->chooseOkOnNextConfirmation();
608 $this->waitForPageToLoad($this->getTimeoutMsec());
609 $this->waitForElementPresent('civicrm-footer');
610 $this->waitForText('crm-notification-container', "safe mode");
612 // If we are still on the dedupe table page, count unmerged contacts
613 if ($this->isElementPresent("//table[@class='pagerDisplay']")) {
614 // Wait for datatable to load
615 $this->waitForElementPresent("//table[@class='pagerDisplay']/tbody/tr");
616 $unMergedContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
619 $unMergedContacts = 0;
622 $mergedContacts = $totalContacts - $unMergedContacts;
624 //check the existence of merged contacts
625 $contactEmails = array(
626 1 => "{$firstName}.{$lastName}@example.com",
627 2 => "{$firstName2}.{$lastName2}@example.com",
628 3 => "{$firstName3}.{$lastName3}@example.com",
631 foreach ($contactEmails as $key => $value) {
632 $this->click('sort_name_navigation');
633 $this->type('css=input#sort_name_navigation', $value);
634 $this->typeKeys('css=input#sort_name_navigation', $value);
635 // Wait for result list.
636 $this->waitForElementPresent("css=ul.ui-autocomplete li.ui-menu-item");
638 // Visit contact summary page.
639 $this->clickLink("css=ul.ui-autocomplete li.ui-menu-item", 'civicrm-footer');
645 * @param null $firstName
646 * @param null $lastName
647 * @param null $organizationName
648 * @param string $contactType
651 public function _createContacts($firstName = NULL, $lastName = NULL, $organizationName = NULL, $contactType = 'Individual') {
652 if ($contactType == 'Individual') {
654 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
656 $this->type('first_name', $firstName);
659 $this->type('last_name', $lastName);
662 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
664 //fill in billing email id
665 $this->click('addEmail');
666 $this->waitForElementPresent('email_2_email');
667 $this->type('email_2_email', "$firstName.$lastName@billing.com");
668 $this->select('email_2_location_type_id', 'value=5');
671 $this->click("_qf_Contact_upload_view");
672 $this->waitForPageToLoad($this->getTimeoutMsec());
673 $this->waitForText('crm-notification-container', "Contact Saved");
675 //duplicate of above contact.
676 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
679 $this->type("first_name", $firstName);
682 $this->type("last_name", $lastName);
685 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
688 $this->click("_qf_Contact_refresh_dedupe");
689 $this->waitForPageToLoad($this->getTimeoutMsec());
691 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
692 $this->click("_qf_Contact_upload_duplicate");
693 $this->waitForPageToLoad($this->getTimeoutMsec());
694 $this->waitForText('crm-notification-container', "Contact Saved");
696 elseif ($contactType == 'Organization') {
698 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
699 //fill in Organization name
700 $this->type('organization_name', $organizationName);
703 $this->type('email_1_email', "{$organizationName}@org.com");
705 $this->click("_qf_Contact_upload_view-bottom");
706 $this->waitForPageToLoad($this->getTimeoutMsec());
707 $this->waitForText('crm-notification-container', "Contact Saved");
708 $mainId = explode("Contact ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
709 $mainId = trim($mainId[1]);
711 //Duplicate of above contact.
712 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
714 //fill in Organization name
715 $this->type('organization_name', $organizationName);
718 $this->type('email_1_email', "{$organizationName}@org.com");
721 $this->click("_qf_Contact_upload_view-bottom");
722 $this->waitForPageToLoad($this->getTimeoutMsec());
724 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
725 $this->click("_qf_Contact_upload_duplicate");
726 $this->waitForPageToLoad($this->getTimeoutMsec());
727 $this->waitForText('crm-notification-container', "Contact Saved");
728 $duplicateId = explode("Contact ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
729 $duplicateId = trim($duplicateId[1]);
733 'duplicateId' => $duplicateId,
740 * to create new membership type
741 * @param $membershipOrganization
743 public function addMembershipType($membershipOrganization) {
744 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
745 $this->click("link=Add Membership Type");
746 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
748 $this->type('name', "Membership Type $membershipOrganization");
749 $this->select2('member_of_contact_id', $membershipOrganization);
751 $this->type('minimum_fee', '1');
752 $this->select('financial_type_id', 'value=2');
753 $this->type('duration_interval', 1);
754 $this->select('duration_unit', "label=year");
756 $this->select('period_type', "label=Fixed");
757 $this->waitForElementPresent('fixed_period_rollover_day[d]');
759 // fixed period start set to April 1
760 $this->select('fixed_period_start_day[M]', 'value=4');
761 // rollover date set to Jan 31
762 $this->select('fixed_period_rollover_day[M]', 'value=1');
764 // Employer of relationship
765 $this->select('relationship_type_id', 'value=5_b_a');
766 $this->click('_qf_MembershipType_upload-bottom');
767 $this->waitForElementPresent('link=Add Membership Type');
768 $this->waitForText("crm-notification-container", "The membership type 'Membership Type $membershipOrganization' has been saved.");
772 * Test for CRM-12695 fix
774 public function testMergeOrganizations() {
775 $this->webtestLogin();
777 // build organisation name
778 $orgnaizationName = 'org_' . substr(sha1(rand()), 0, 7);
780 $contactIds = array();
781 // create organization and its duplicate
782 $contactIds = $this->_createContacts(NULL, NULL, $orgnaizationName, 'Organization');
784 /*** Add Membership Type - start ***/
785 $this->addMembershipType($orgnaizationName);
786 /*** Add Membership Type - end ***/
788 //create a New Individual to be related to main organization
789 $firstName = substr(sha1(rand()), 0, 7);
790 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
791 $sortName = "Anderson, $firstName";
793 // go to main organization contact to add membership
794 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['mainId']}");
795 // click through to the membership view screen
796 $this->click("css=li#tab_member a");
798 $this->waitForElementPresent("link=Add Membership");
799 $this->click("link=Add Membership");
801 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
803 // fill in Membership Organization and Type
804 $this->select("membership_type_id[0]", "label={$orgnaizationName}");
805 $this->waitForElementPresent("membership_type_id[1]");
806 // Wait for membership type select to reload
807 $this->waitForTextPresent("Membership Type $orgnaizationName");
808 $this->select("membership_type_id[1]", "label=Membership Type $orgnaizationName");
810 $sourceText = "Membership-Organization Duplicate Merge Webtest";
812 $this->type("source", $sourceText);
814 // Let Join Date stay default
816 // fill in Start Date
817 $this->webtestFillDate('start_date');
820 $this->click("_qf_Membership_upload");
821 $this->waitForElementPresent('crm-notification-container');
823 $this->waitForTextPresent($sourceText);
824 // Is status message correct?
825 $this->waitForText('crm-notification-container', "membership for $orgnaizationName has been added.");
827 // add relationship "Employer of"
828 // click through to the relationship view screen
829 $this->click("css=li#tab_rel a");
831 // wait for add Relationship link
832 $this->waitForElementPresent('link=Add Relationship');
833 $this->click('link=Add Relationship');
835 //choose the created relationship type
836 $this->waitForElementPresent("relationship_type_id");
837 $this->select('relationship_type_id', "value=5_b_a");
839 //fill in the individual
840 $this->select2('related_contact_id', $sortName, TRUE, FALSE);
842 $this->waitForElementPresent("_qf_Relationship_upload");
844 //fill in the relationship start date
845 //$this->webtestFillDate('start_date', '-2 year');
846 //$this->webtestFillDate('end_date', '+1 year');
848 $description = "Well here is some description !!!!";
849 $this->type("description", $description);
851 //save the relationship
852 $this->click("_qf_Relationship_upload");
853 $this->isTextPresent("Current Relationships");
855 //check the status message
856 $this->waitForText('crm-notification-container', "Relationship created.");
858 $this->waitForElementPresent("xpath=//table[@class='crm-contact-relationship-selector-current dataTable no-footer']/tbody//tr/td[9]/span/a[text()='View']");
859 $this->waitForElementPresent("xpath=//a[text()='$sortName']");
860 $this->click("xpath=//a[text()='$sortName']");
861 $this->waitForPageToLoad($this->getTimeoutMsec());
863 // Check if Membership for the individual is created
864 $this->waitForElementPresent("xpath=//li[@id='tab_member']/a/em");
865 $this->verifyText("xpath=//li[@id='tab_member']/a/em", 1);
867 //create a New Individual to be related to duplicate organization
868 $firstNameOther = substr(sha1(rand()), 0, 7);
869 $this->webtestAddContact($firstNameOther, "Harmison", "$firstNameOther@harmison.name");
870 $sortNameOther = "Harmison, $firstNameOther";
872 // go to main organization contact to add membership
873 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['duplicateId']}");
875 // add relationship "Employer of"
876 // click through to the relationship view screen
877 $this->click("css=li#tab_rel a");
879 // wait for add Relationship link
880 $this->waitForElementPresent('link=Add Relationship');
881 $this->click('link=Add Relationship');
883 //choose the created relationship type
884 $this->waitForElementPresent("relationship_type_id");
885 $this->select('relationship_type_id', "value=5_b_a");
887 //fill in the individual
888 $this->select2('related_contact_id', $sortNameOther, TRUE, FALSE);
890 $this->waitForElementPresent("_qf_Relationship_upload");
892 //fill in the relationship start date
893 $this->webtestFillDate('start_date', '-2 year');
894 $this->webtestFillDate('end_date', '+1 year');
896 $description = "Well here is some description !!!!";
897 $this->type("description", $description);
899 //save the relationship
900 //$this->click("_qf_Relationship_upload");
901 $this->click("_qf_Relationship_upload");
902 $this->isTextPresent("Current Relationships");
904 //check the status message
905 $this->isTextPresent("Relationship created.");
907 $this->waitForElementPresent("xpath=//table[@class='crm-contact-relationship-selector-current dataTable no-footer']/tbody//tr/td[9]/span/a[text()='View']");
909 // go directly to contact merge page.
910 $this->openCiviPage("contact/merge", "reset=1&cid={$contactIds['mainId']}&oid={$contactIds['duplicateId']}&action=update&rgid=2");
912 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
913 $this->click('_qf_Merge_next-bottom');
914 $this->waitForPageToLoad($this->getTimeoutMsec());
916 // click through to the relationship view screen
917 $this->click("css=li#tab_rel a");
919 // wait for add Relationship link
920 $this->waitForElementPresent("xpath=//a[text()='$sortName']");
921 // go to duplicate organization's related contact
922 // to check if membership is added to that contact
923 $this->click("xpath=//a[text()='$sortName']");
924 $this->waitForPageToLoad($this->getTimeoutMsec());
926 // Check if Membership for the individual is created
927 $this->waitForElementPresent("xpath=//li[@id='tab_member']/a/em");
928 $this->verifyText("xpath=//li[@id='tab_member']/a/em", 0);
932 * Test for CRM-15658 fix
934 public function testMergeEmailAndAddress() {
935 $this->webtestLogin();
936 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
937 $firstName = substr(sha1(rand()), 0, 7);
938 $this->type('first_name', $firstName);
941 $lastName = substr(sha1(rand()), 0, 7);
942 $this->type('last_name', $lastName);
945 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
948 $this->click("addressBlock");
949 $this->waitForElementPresent("address_1_street_address");
950 $this->type("address_1_street_address", "902C El Camino Way SW");
951 $this->type("address_1_city", "Dumfries");
952 $this->type("address_1_postal_code", "1234");
955 $this->click("_qf_Contact_upload_view");
956 $this->waitForPageToLoad($this->getTimeoutMsec());
957 $this->waitForText('crm-notification-container', "Contact Saved");
959 //duplicate contact with same email id
960 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
961 $firstName2 = substr(sha1(rand()), 0, 7);
962 $this->type('first_name', $firstName2);
965 $lastName2 = substr(sha1(rand()), 0, 7);
966 $this->type('last_name', $lastName2);
969 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
972 $this->click("addressBlock");
973 $this->waitForElementPresent("address_1_street_address");
974 $this->type("address_1_street_address", "2782Y Dowlen Path W");
975 $this->type("address_1_city", "Birmingham");
976 $this->type("address_1_postal_code", "3456");
979 $this->click("_qf_Contact_upload_view");
980 $this->waitForPageToLoad($this->getTimeoutMsec());
981 $this->waitForText('crm-notification-container', "Contact Saved");
983 $this->openCiviPage("contact/dedupefind", "reset=1&action=update&rgid=4");
984 $this->click("//a/span[contains(text(),'Refresh Duplicates')]");
985 $this->assertTrue((bool) preg_match("/This will refresh the duplicates list. Click OK to proceed./", $this->getConfirmation()));
986 $this->chooseOkOnNextConfirmation();
987 $this->waitForPageToLoad($this->getTimeoutMsec());
988 $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
989 $this->clickLink("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
991 //merge without specifying any criteria
992 $this->click("_qf_Merge_next-bottom");
993 $this->waitForPageToLoad($this->getTimeoutMsec());
995 $this->assertTrue($this->isTextPresent('Contacts Merged'));
996 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
997 $this->verifyElementNotPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Home')]");
998 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]"));
999 $this->verifyElementNotPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]");
1001 $this->assertElementContainsText('address-block-1', "902C El Camino Way SW");
1002 $this->assertElementContainsText('address-block-1', "Dumfries");
1003 $this->assertElementContainsText('address-block-1', "1234");
1005 $this->assertElementNotContainsText("address-block-2", "2782Y Dowlen Path W");
1006 $this->assertElementNotContainsText("address-block-2", "Birmingham");
1007 $this->assertElementNotContainsText("address-block-2", "3456");