3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 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/../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->click("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->check('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[@id='contact-activity-selector-activity']/tbody/tr");
184 $this->verifyText("xpath=//table[@id='contact-activity-selector-activity']/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");
207 function addActivity($firstName, $lastName, $subject) {
208 $withContact = substr(sha1(rand()), 0, 7);
209 $this->webtestAddContact($withContact, "Anderson", $withContact . "@anderson.name");
211 $this->click("css=li#tab_activity a");
213 // waiting for the activity dropdown to show up
214 $this->waitForElementPresent("other_activity");
216 // Select the activity type from the activity dropdown
217 $this->select("other_activity", "label=Meeting");
219 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
220 // button at the end of this page to show up, to make sure it's fully loaded.
221 $this->waitForElementPresent("_qf_Activity_upload");
223 // ...and verifying if the page contains properly formatted display name for chosen contact.
224 $this->assertTrue($this->isTextPresent("Anderson, " . $withContact), "Contact not found in line " . __LINE__
);
226 // Now we're filling the "Assigned To" field.
227 // Typing contact's name into the field (using typeKeys(), not type()!)...
228 $this->select2("assignee_contact_id", $firstName,TRUE,FALSE);
230 // ...and verifying if the page contains properly formatted display name for chosen contact.
231 $this->assertTrue($this->isTextPresent("$lastName, " . $firstName), "Contact not found in line " . __LINE__
);
233 // Since we're here, let's check if screen help is being displayed properly
234 $this->assertTrue($this->isTextPresent("A copy of this activity will be emailed to each Assignee."));
236 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
237 // For simple input fields we can use field id as selector
238 $this->type("subject", $subject);
239 $this->type("location", "Some location needs to be put in this field.");
241 // Choosing the Date.
242 // Please note that we don't want to put in fixed date, since
243 // we want this test to work in the future and not fail because
244 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
245 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
248 $this->type("duration", "30");
250 // Putting in details.
251 $this->type("details", "Really brief details information.");
253 // Making sure that status is set to Scheduled (using value, not label).
254 $this->select("status_id", "value=1");
257 $this->select("priority_id", "value=1");
260 $this->click("_qf_Activity_upload");
261 $this->waitForElementPresent("crm-notification-container");
263 // Is status message correct?
264 $this->waitForText('crm-notification-container', "Activity '$subject' has been saved.", "Status message didn't show up after saving!");
267 function testMergeTest() {
268 $this->webtestLogin();
270 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
274 $firstName = substr(sha1(rand()), 0, 7);
275 $this->type('first_name', $firstName);
278 $lastName = substr(sha1(rand()), 0, 7);
279 $this->type('last_name', $lastName);
282 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
284 //fill in billing email id
285 $this->click('addEmail');
286 $this->waitForElementPresent('email_2_email');
287 $this->type('email_2_email', "$firstName.$lastName@billing.com");
288 $this->select('email_2_location_type_id', 'value=5');
290 //fill in home phone no
291 $this->type('phone_1_phone', "9876543210");
293 //fill in billing phone id
294 $this->click('addPhone');
295 $this->waitForElementPresent('phone_2_phone');
296 $this->type('phone_2_phone', "9876543120");
297 $this->select('phone_2_location_type_id', 'value=5');
300 $this->click("_qf_Contact_upload_view");
301 $this->waitForPageToLoad($this->getTimeoutMsec());
302 $this->waitForText('crm-notification-container', "Contact Saved");
304 // contact2: duplicate of contact1.
305 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
308 $this->type("first_name", $firstName);
311 $this->type("last_name", $lastName);
314 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
316 //fill in home phone no
317 $this->type('phone_1_phone', "9876543211");
320 $this->click("_qf_Contact_refresh_dedupe");
321 $this->waitForPageToLoad($this->getTimeoutMsec());
323 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
324 $this->click("_qf_Contact_upload_duplicate");
325 $this->waitForPageToLoad($this->getTimeoutMsec());
326 $this->waitForText('crm-notification-container', "Contact Saved");
328 // Find and Merge Contacts with Supervised Rule
329 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
331 // Select the contacts to be merged
332 $this->select("name=option51_length", "value=100");
333 $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']");
334 $this->click("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
335 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
336 $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);
337 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[5]/td[4]/span[text()='(add)']");
338 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
340 $this->check("move_location_email_1");
341 $this->check("location[email][1][operation]");
342 $this->check("move_location_email_2");
343 $this->check("move_location_phone_1");
344 $this->check("location[phone][1][operation]");
345 $this->check("move_location_phone_2");
346 $this->click("_qf_Merge_next-bottom");
347 $this->waitForPageToLoad($this->getTimeoutMsec());
349 $this->assertTrue($this->isTextPresent('Contacts Merged'));
350 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
351 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[text() = '{$firstName}.{$lastName}@example.com']"));
352 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
353 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[text() ='{$firstName}.{$lastName}@example.com']"));
354 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
355 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[2]/a[text() ='$firstName.$lastName@billing.com']"));
356 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
357 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543211')]"));
358 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
359 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
360 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
361 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[2][contains(text(), '9876543120')]"));
363 //Merge with the feature of (add)
364 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
368 $firstName1 = substr(sha1(rand()), 0, 7);
369 $this->type('first_name', $firstName1);
372 $lastName1 = substr(sha1(rand()), 0, 7);
373 $this->type('last_name', $lastName1);
375 //fill in billing email id
376 $this->waitForElementPresent('email_1_email');
377 $this->type('email_1_email', "$firstName1.$lastName1@example.com");
378 $this->select('email_1_location_type_id', 'value=5');
380 $this->click('addEmail');
381 $this->waitForElementPresent('email_2_email');
382 $this->type('email_2_email', "$firstName.$lastName@home.com");
383 $this->select('email_2_location_type_id', 'value=1');
385 //fill in home phone no
386 $this->type('phone_1_phone', "9876543210");
389 $this->click("_qf_Contact_upload_view");
390 $this->waitForPageToLoad($this->getTimeoutMsec());
391 $this->waitForText('crm-notification-container', "Contact Saved");
393 // contact2: duplicate of contact1.
394 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
397 $this->type("first_name", $firstName1);
400 $this->type("last_name", $lastName1);
403 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
405 //fill in billing phone no
406 $this->type('phone_1_phone', "9876543120");
407 $this->select('phone_1_location_type_id', 'value=5');
410 $this->click("_qf_Contact_refresh_dedupe");
411 $this->waitForPageToLoad($this->getTimeoutMsec());
412 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
413 $this->click("_qf_Contact_upload_duplicate");
414 $this->waitForPageToLoad($this->getTimeoutMsec());
415 $this->waitForText('crm-notification-container', "Contact Saved");
417 // Find and Merge Contacts with Supervised Rule
418 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
420 // Select the contacts to be merged
421 $this->select("name=option51_length", "value=100");
422 $this->waitForElementPresent("xpath=//*[@id='DedupeFind']//table[@class='pagerDisplay dataTable no-footer']/tbody//tr/td[1]/a[text()='57e10a6 9a3de85']/../../td[2]/a[text()='57e10a6 9a3de85']");
423 $this->click("xpath=//*[@id='DedupeFind']//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']");
424 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
425 $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)']");
426 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']");
427 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']");
428 $this->select('location_email_1_locTypeId', 'value=3');
429 $this->select('location_phone_1_locTypeId', 'value=1');
430 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']"));
431 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']"));
432 $this->assertTrue($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']"));
433 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
435 $this->check("move_location_email_1");
436 $this->check("move_location_phone_1");
437 $this->click("_qf_Merge_next-bottom");
438 $this->waitForPageToLoad($this->getTimeoutMsec());
440 $this->assertTrue($this->isTextPresent('Contacts Merged'));
441 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
442 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[text() ='{$firstName1}.{$lastName1}@example.com']"));
443 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Main')]"));
444 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[text() ='{$firstName1}.{$lastName1}@example.com']"));
445 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Billing')]"));
446 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543120')]"));
447 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
448 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
451 function testBatchMerge(){
452 $this->webtestLogin();
454 // add contact1 and its duplicate
456 $firstName = "Kerry".substr(sha1(rand()), 0, 7);
458 $lastName = "King".substr(sha1(rand()), 0, 7);
459 $this->_createContacts($firstName,$lastName);
461 //add contact2 and its duplicate
462 //These are the contacts with conflicts in communication preference.these contacts will be skipped during merge.
463 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
466 $firstName1 = "Kurt".substr(sha1(rand()), 0, 7);
467 $this->type('first_name', $firstName1);
470 $lastName1 = "Cobain".substr(sha1(rand()), 0, 7);
471 $this->type('last_name', $lastName1);
474 $this->type('email_1_email', "{$firstName1}.{$lastName1}@example.com");
476 //fill in billing email id
477 $this->click('addEmail');
478 $this->waitForElementPresent('email_2_email');
479 $this->type('email_2_email', "$firstName1.$lastName1@billing.com");
480 $this->select('email_2_location_type_id', 'value=5');
482 //fill in home phone no
483 $this->type('phone_1_phone', "9876543210");
485 //fill in billing phone id
486 $this->click('addPhone');
487 $this->waitForElementPresent('phone_2_phone');
488 $this->type('phone_2_phone', "9876543120");
489 $this->select('phone_2_location_type_id', 'value=5');
491 //select communication preference
492 $this->check("privacy[do_not_phone]");
495 $this->click("_qf_Contact_upload_view");
496 $this->waitForPageToLoad($this->getTimeoutMsec());
497 $this->waitForText('crm-notification-container', "Contact Saved");
499 //duplicate of contact2.
500 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
503 $this->type("first_name", $firstName1);
506 $this->type("last_name", $lastName1);
509 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
511 //fill in home phone no
512 $this->type('phone_1_phone', "9876543211");
514 //select communication preference
515 $this->check("preferred_communication_method[1]");
518 $this->click("_qf_Contact_refresh_dedupe");
519 $this->waitForPageToLoad($this->getTimeoutMsec());
521 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
522 $this->click("_qf_Contact_upload_duplicate");
523 $this->waitForPageToLoad($this->getTimeoutMsec());
524 $this->waitForText('crm-notification-container', "Contact Saved");
526 // add contact3 and its duplicate
528 $firstName2 = "David".substr(sha1(rand()), 0, 7);
530 $lastName2 = "Gilmour".substr(sha1(rand()), 0, 7);
531 $this->_createContacts($firstName2,$lastName2);
533 // add contact4 and its duplicate
535 $firstName3 = "Dave".substr(sha1(rand()), 0, 7);
537 $lastName3 = "Mustaine".substr(sha1(rand()), 0, 7);
538 $this->_createContacts($firstName3,$lastName3);
540 // Find and Merge Contacts with Supervised Rule
541 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew", "css=#DedupeFind table.pagerDisplay tbody tr");
543 $this->select("name=option51_length", "value=100");
544 $totalContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
545 $this->click("xpath=//form[@id='DedupeFind']//a/span[text()='Batch Merge Duplicates']");
547 // Check confirmation alert.
549 (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./",
550 $this->getConfirmation()
552 $this->chooseOkOnNextConfirmation();
553 $this->waitForPageToLoad($this->getTimeoutMsec());
554 $this->waitForElementPresent('civicrm-footer');
555 $this->waitForText('crm-notification-container', "safe mode");
557 // If we are still on the dedupe table page, count unmerged contacts
558 if ($this->isElementPresent("//table[@class='pagerDisplay']")) {
559 // Wait for datatable to load
560 $this->waitForElementPresent("//table[@class='pagerDisplay']/tbody/tr");
561 $unMergedContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
564 $unMergedContacts = 0;
567 $mergedContacts = $totalContacts - $unMergedContacts;
569 //check the existence of merged contacts
570 $contactEmails = array(
571 1 => "{$firstName}.{$lastName}@example.com",
572 2 => "{$firstName2}.{$lastName2}@example.com",
573 3 => "{$firstName3}.{$lastName3}@example.com"
576 foreach($contactEmails as $key => $value) {
577 $this->click('sort_name_navigation');
578 $this->type('css=input#sort_name_navigation', $value);
579 $this->typeKeys('css=input#sort_name_navigation', $value);
580 // Wait for result list.
581 $this->waitForElementPresent("css=ul.ui-autocomplete li.ui-menu-item");
583 // Visit contact summary page.
584 $this->clickLink("css=ul.ui-autocomplete li.ui-menu-item", 'civicrm-footer');
591 function _createContacts($firstName = NULL, $lastName = NULL, $organizationName = NULL, $contactType = 'Individual') {
592 if ($contactType == 'Individual') {
594 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
596 $this->type('first_name', $firstName);
599 $this->type('last_name', $lastName);
602 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
604 //fill in billing email id
605 $this->click('addEmail');
606 $this->waitForElementPresent('email_2_email');
607 $this->type('email_2_email', "$firstName.$lastName@billing.com");
608 $this->select('email_2_location_type_id', 'value=5');
611 $this->click("_qf_Contact_upload_view");
612 $this->waitForPageToLoad($this->getTimeoutMsec());
613 $this->waitForText('crm-notification-container', "Contact Saved");
615 //duplicate of above contact.
616 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
619 $this->type("first_name", $firstName);
622 $this->type("last_name", $lastName);
625 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
628 $this->click("_qf_Contact_refresh_dedupe");
629 $this->waitForPageToLoad($this->getTimeoutMsec());
631 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
632 $this->click("_qf_Contact_upload_duplicate");
633 $this->waitForPageToLoad($this->getTimeoutMsec());
634 $this->waitForText('crm-notification-container', "Contact Saved");
636 elseif ($contactType == 'Organization') {
638 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
639 //fill in Organization name
640 $this->type('organization_name', $organizationName);
643 $this->type('email_1_email', "{$organizationName}@org.com");
645 $this->click("_qf_Contact_upload_view-bottom");
646 $this->waitForPageToLoad($this->getTimeoutMsec());
647 $this->waitForText('crm-notification-container', "Contact Saved");
648 $mainId = explode("CiviCRM ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
649 $mainId = trim($mainId[1]);
651 //Duplicate of above contact.
652 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
654 //fill in Organization name
655 $this->type('organization_name', $organizationName);
658 $this->type('email_1_email', "{$organizationName}@org.com");
661 $this->click("_qf_Contact_upload_view-bottom");
662 $this->waitForPageToLoad($this->getTimeoutMsec());
664 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
665 $this->click("_qf_Contact_upload_duplicate");
666 $this->waitForPageToLoad($this->getTimeoutMsec());
667 $this->waitForText('crm-notification-container', "Contact Saved");
668 $duplicateId = explode("CiviCRM ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
669 $duplicateId = trim($duplicateId[1]);
673 'duplicateId' => $duplicateId
680 * to create new membership type
682 function addMembershipType($membershipOrganization) {
683 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
684 $this->click("link=Add Membership Type");
685 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
687 $this->type('name', "Membership Type $membershipOrganization");
688 $this->select2('member_of_contact_id', $membershipOrganization);
690 $this->type('minimum_fee', '1');
691 $this->select( 'financial_type_id', 'value=2' );
692 $this->type('duration_interval', 1);
693 $this->select('duration_unit', "label=year");
695 $this->select('period_type', "label=Fixed");
696 $this->waitForElementPresent('fixed_period_rollover_day[d]');
698 // fixed period start set to April 1
699 $this->select('fixed_period_start_day[M]', 'value=4');
700 // rollover date set to Jan 31
701 $this->select('fixed_period_rollover_day[M]', 'value=1');
703 // Employer of relationship
704 $this->select('relationship_type_id', 'value=5_b_a');
705 $this->click('_qf_MembershipType_upload-bottom');
706 $this->waitForElementPresent('link=Add Membership Type');
707 $this->waitForText("crm-notification-container", "The membership type 'Membership Type $membershipOrganization' has been saved.");
711 * Test for CRM-12695 fix
713 function testMergeOrganizations() {
714 $this->webtestLogin();
716 // build organisation name
717 $orgnaizationName = 'org_'.substr(sha1(rand()), 0, 7);
719 $contactIds = array();
720 // create organization and its duplicate
721 $contactIds = $this->_createContacts(NULL, NULL, $orgnaizationName, 'Organization');
723 /*** Add Membership Type - start ***/
724 $this->addMembershipType($orgnaizationName);
725 /*** Add Membership Type - end ***/
727 //create a New Individual to be related to main organization
728 $firstName = substr(sha1(rand()), 0, 7);
729 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
730 $sortName = "Anderson, $firstName";
732 // go to main organization contact to add membership
733 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['mainId']}");
734 // click through to the membership view screen
735 $this->click("css=li#tab_member a");
737 $this->waitForElementPresent("link=Add Membership");
738 $this->click("link=Add Membership");
740 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
742 // fill in Membership Organization and Type
743 $this->select("membership_type_id[0]", "label={$orgnaizationName}");
744 $this->waitForElementPresent("membership_type_id[1]");
745 // Wait for membership type select to reload
746 $this->waitForTextPresent("Membership Type $orgnaizationName");
747 $this->select("membership_type_id[1]", "label=Membership Type $orgnaizationName");
749 $sourceText = "Membership-Organization Duplicate Merge Webtest";
751 $this->type("source", $sourceText);
753 // Let Join Date stay default
755 // fill in Start Date
756 $this->webtestFillDate('start_date');
759 $this->click("_qf_Membership_upload");
760 $this->waitForElementPresent('crm-notification-container');
762 $this->waitForTextPresent($sourceText);
763 // Is status message correct?
764 $this->waitForText('crm-notification-container', "membership for $orgnaizationName has been added.");
766 // add relationship "Employer of"
767 // click through to the relationship view screen
768 $this->click("css=li#tab_rel a");
770 // wait for add Relationship link
771 $this->waitForElementPresent('link=Add Relationship');
772 $this->click('link=Add Relationship');
774 //choose the created relationship type
775 $this->waitForElementPresent("relationship_type_id");
776 $this->select('relationship_type_id', "value=5_b_a");
778 //fill in the individual
779 $this->select2('related_contact_id', $sortName, TRUE, FALSE);
781 $this->waitForElementPresent("_qf_Relationship_upload");
783 //fill in the relationship start date
784 //$this->webtestFillDate('start_date', '-2 year');
785 //$this->webtestFillDate('end_date', '+1 year');
787 $description = "Well here is some description !!!!";
788 $this->type("description", $description);
790 //save the relationship
791 $this->click("_qf_Relationship_upload");
792 $this->isTextPresent("Current Relationships");
794 //check the status message
795 $this->waitForText('crm-notification-container', "Relationship created.");
797 $this->waitForElementPresent("xpath=//table[@id='crm-contact-relationship-selector-current']/tbody//tr/td[9]/span/a[text()='View']");
798 $this->waitForElementPresent("xpath=//a[text()='$sortName']");
799 $this->click("xpath=//a[text()='$sortName']");
800 $this->waitForPageToLoad($this->getTimeoutMsec());
802 // Check if Membership for the individual is created
803 $this->waitForElementPresent("xpath=//li[@id='tab_member']/a/em");
804 $this->verifyText("xpath=//li[@id='tab_member']/a/em", 1);
806 //create a New Individual to be related to duplicate organization
807 $firstNameOther = substr(sha1(rand()), 0, 7);
808 $this->webtestAddContact($firstNameOther, "Harmison", "$firstNameOther@harmison.name");
809 $sortNameOther = "Harmison, $firstNameOther";
811 // go to main organization contact to add membership
812 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['duplicateId']}");
814 // add relationship "Employer of"
815 // click through to the relationship view screen
816 $this->click("css=li#tab_rel a");
818 // wait for add Relationship link
819 $this->waitForElementPresent('link=Add Relationship');
820 $this->click('link=Add Relationship');
822 //choose the created relationship type
823 $this->waitForElementPresent("relationship_type_id");
824 $this->select('relationship_type_id', "value=5_b_a");
826 //fill in the individual
827 $this->select2('related_contact_id', $sortNameOther, TRUE, FALSE);
829 $this->waitForElementPresent("_qf_Relationship_upload");
831 //fill in the relationship start date
832 $this->webtestFillDate('start_date', '-2 year');
833 $this->webtestFillDate('end_date', '+1 year');
835 $description = "Well here is some description !!!!";
836 $this->type("description", $description);
838 //save the relationship
839 //$this->click("_qf_Relationship_upload");
840 $this->click("_qf_Relationship_upload");
841 $this->isTextPresent("Current Relationships");
843 //check the status message
844 $this->isTextPresent("Relationship created.");
846 $this->waitForElementPresent("xpath=//table[@id='crm-contact-relationship-selector-current']/tbody//tr/td[9]/span/a[text()='View']");
848 // go directly to contact merge page.
849 $this->openCiviPage("contact/merge", "reset=1&cid={$contactIds['mainId']}&oid={$contactIds['duplicateId']}&action=update&rgid=2");
851 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
852 $this->click('_qf_Merge_next-bottom');
853 $this->waitForPageToLoad($this->getTimeoutMsec());
855 // click through to the relationship view screen
856 $this->click("css=li#tab_rel a");
858 // wait for add Relationship link
859 $this->waitForElementPresent("xpath=//a[text()='$sortName']");
860 // go to duplicate organization's related contact
861 // to check if membership is added to that contact
862 $this->click("xpath=//a[text()='$sortName']");
863 $this->waitForPageToLoad($this->getTimeoutMsec());
865 // Check if Membership for the individual is created
866 $this->waitForElementPresent("xpath=//li[@id='tab_member']/a/em");
867 $this->verifyText("xpath=//li[@id='tab_member']/a/em", 1);