3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Contact_MergeContactsTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testIndividualAdd() {
35 $this->webtestLogin();
37 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
42 $this->click("prefix_id");
43 $this->select("prefix_id", "label=$prefix");
46 $firstName = substr(sha1(rand()), 0, 7);
47 $this->type('first_name', $firstName);
50 $lastName = substr(sha1(rand()), 0, 7);
51 $this->type('last_name', $lastName);
54 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
56 //fill in billing email id
57 $this->click('addEmail');
58 $this->waitForElementPresent('email_2_email');
59 $this->type('email_2_email', "$firstName.$lastName@billing.com");
60 $this->select('email_2_location_type_id', 'value=5');
63 $this->click("_qf_Contact_upload_view");
64 $this->waitForPageToLoad($this->getTimeoutMsec());
65 $this->waitForText('crm-notification-container', "Contact Saved");
67 // Add Contact to a group
68 $group = 'Newsletter Subscribers';
69 $this->click('css=li#tab_group a');
70 $this->waitForElementPresent('_qf_GroupContact_next');
71 $this->select('group_id', "label=$group");
72 $this->click('_qf_GroupContact_next');
73 $this->waitForPageToLoad($this->getTimeoutMsec());
74 $this->waitForText('crm-notification-container', "Added to Group");
76 // Add Tags to the contact
77 $tag = 'Government Entity';
78 $this->click("css=li#tab_tag a");
79 $this->waitForElementPresent('tagtree');
80 $this->click("xpath=//div[@id='tagtree']/ul//li/input/../label[text()='$tag']");
81 $this->click("css=#tab_summary a");
82 $this->assertElementContainsText('css=.crm-summary-block #tags', $tag);
85 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
86 $this->addActivity($firstName, $lastName, $subject);
88 // contact2: duplicate of contact1.
89 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
92 $this->type("first_name", $firstName);
95 $this->type("last_name", $lastName);
98 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
101 $this->click("_qf_Contact_refresh_dedupe");
102 $this->waitForPageToLoad($this->getTimeoutMsec());
104 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
105 $this->click("_qf_Contact_upload_duplicate");
106 $this->waitForPageToLoad($this->getTimeoutMsec());
107 $this->waitForText('crm-notification-container', "Contact Saved");
109 // Add second pair of dupes so we can test Merge and Goto Next Pair
111 $lname2 = 'Rogers' . substr(sha1(rand()), 0, 7);
112 $email2 = "{$fname2}.{$lname2}@example.org";
113 $this->webtestAddContact($fname2, $lname2, $email2);
115 // Can not use helper for 2nd contact since it is a dupe
116 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
117 $this->type("first_name", $fname2);
118 $this->type("last_name", $lname2);
119 $this->type("email_1_email", $email2);
120 $this->click("_qf_Contact_refresh_dedupe");
121 $this->waitForPageToLoad($this->getTimeoutMsec());
122 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
123 $this->click("_qf_Contact_upload_duplicate");
124 $this->waitForPageToLoad($this->getTimeoutMsec());
125 $this->waitForText('crm-notification-container', "Contact Saved");
127 // Find and Merge Contacts with Supervised Rule
128 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
131 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=update");
133 // Select the contacts to be merged
134 $this->select("name=option51_length", "value=100");
136 $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
137 $this->click("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
138 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
140 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", '_qf_Merge_cancel-bottom');
142 // Move the activities, groups, etc to the main contact and merge using Merge and Goto Next Pair
143 $this->check('move_prefix_id');
144 $this->check('move_location_email_2');
145 $this->check('move_rel_table_activities');
146 $this->check('move_rel_table_groups');
147 $this->check('move_rel_table_tags');
148 $this->clickLink('_qf_Merge_next-bottom', '_qf_Merge_cancel-bottom');
149 $this->assertTrue($this->isTextPresent('Contacts Merged'), "Contacts Merged text was not found after merge.");
151 // Check that we are viewing the next Merge Pair (our 2nd contact, since the merge list is ordered by contact_id)
152 $this->assertTrue($this->isTextPresent("{$fname2} {$lname2}"), "Redirect for Goto Next Pair after merge did not work.");
154 // Ensure that the duplicate contact has been deleted
155 $this->openCiviPage("contact/search/advanced", "reset=1", '_qf_Advanced_refresh');
156 $this->type('sort_name', $firstName);
157 $this->check('deleted_contacts');
158 $this->click('_qf_Advanced_refresh');
159 $this->waitForPageToLoad($this->getTimeoutMsec());
160 $this->assertTrue($this->isTextPresent('1 Contact'), "Deletion of duplicate contact during merge was not successful. Dupe contact not found when searching trash.");
162 // Search for the main contact
163 $this->openCiviPage("contact/search/advanced", "reset=1", '_qf_Advanced_refresh');
164 $this->type('sort_name', $firstName);
165 $this->click('_qf_Advanced_refresh');
166 $this->waitForElementPresent("xpath=//form[@id='Advanced']/div[3]/div/div[2]/table/tbody/tr");
168 $this->click("//form[@id='Advanced']/div[3]/div/div[2]/table/tbody/tr/td[11]/span[1]/a[text()='View']");
169 $this->waitForPageToLoad($this->getTimeoutMsec());
171 // Verify prefix merged
172 // $this->verifyText( "xpath=//div[@class='left-corner']/h2", preg_quote( "$prefix $firstName $lastName" ) );
174 // Verify billing email merged
175 $this->isElementPresent("xpath=//div[@class='contact_details']/div[1][@class='contact_panel']/div[1][@class='contactCardLeft']/table/tbody/tr[4]/td[2]/span/a[text()='$firstName.$lastName@billing.com']");
177 // Verify activity merged
178 $this->click("css=li#tab_activity a");
179 $this->waitForElementPresent("xpath=//table[@id='contact-activity-selector-activity']/tbody/tr");
180 $this->verifyText("xpath=//table[@id='contact-activity-selector-activity']/tbody/tr/td[5]/a",
181 preg_quote("$lastName, $firstName")
184 // Verify group merged
185 $this->click("css=li#tab_group a");
186 $this->waitForElementPresent("xpath=//form[@id='GroupContact']//div[@class='view-content']//div[@class='dataTables_wrapper']/table/tbody/tr");
187 $this->verifyText("xpath=//form[@id='GroupContact']//div[@class='view-content']//div[@class='dataTables_wrapper']/table/tbody/tr/td/a",
192 $this->click("css=li#tab_tag a");
193 $this->waitForElementPresent('check_5');
194 $this->assertChecked("check_3");
197 function addActivity($firstName, $lastName, $subject) {
198 $withContact = substr(sha1(rand()), 0, 7);
199 $this->webtestAddContact($withContact, "Anderson", $withContact . "@anderson.name");
201 $this->click("css=li#tab_activity a");
203 // waiting for the activity dropdown to show up
204 $this->waitForElementPresent("other_activity");
206 // Select the activity type from the activity dropdown
207 $this->select("other_activity", "label=Meeting");
209 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
210 // button at the end of this page to show up, to make sure it's fully loaded.
211 $this->waitForElementPresent("_qf_Activity_upload");
213 // ...and verifying if the page contains properly formatted display name for chosen contact.
214 $this->assertTrue($this->isTextPresent("Anderson, " . $withContact), "Contact not found in line " . __LINE__
);
216 // Now we're filling the "Assigned To" field.
217 // Typing contact's name into the field (using typeKeys(), not type()!)...
218 $this->click("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id");
219 $this->type("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName);
220 $this->typeKeys("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName);
222 // ...waiting for drop down with results to show up...
223 $this->waitForElementPresent("css=div.token-input-dropdown-facebook");
224 $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook");
226 //..need to use mouseDownAt on first result (which is a li element), click does not work
227 $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook");
229 // ...again, waiting for the box with contact name to show up...
230 $this->waitForElementPresent("css=tr.crm-activity-form-block-assignee_contact_id td ul li span.token-input-delete-token-facebook");
232 // ...and verifying if the page contains properly formatted display name for chosen contact.
233 $this->assertTrue($this->isTextPresent("$lastName, " . $firstName), "Contact not found in line " . __LINE__
);
235 // Since we're here, let's check if screen help is being displayed properly
236 $this->assertTrue($this->isTextPresent("Assigned activities will appear in their Activities listing at CiviCRM Home"));
238 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
239 // For simple input fields we can use field id as selector
240 $this->type("subject", $subject);
241 $this->type("location", "Some location needs to be put in this field.");
243 // Choosing the Date.
244 // Please note that we don't want to put in fixed date, since
245 // we want this test to work in the future and not fail because
246 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
247 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
250 $this->type("duration", "30");
252 // Putting in details.
253 $this->type("details", "Really brief details information.");
255 // Making sure that status is set to Scheduled (using value, not label).
256 $this->select("status_id", "value=1");
259 $this->select("priority_id", "value=1");
262 $this->click("_qf_Activity_upload");
263 $this->waitForPageToLoad($this->getTimeoutMsec());
265 // Is status message correct?
266 $this->waitForText('crm-notification-container', "Activity '$subject' has been saved.", "Status message didn't show up after saving!");
269 function testMergeTest() {
270 $this->webtestLogin();
272 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
276 $firstName = substr(sha1(rand()), 0, 7);
277 $this->type('first_name', $firstName);
280 $lastName = substr(sha1(rand()), 0, 7);
281 $this->type('last_name', $lastName);
284 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
286 //fill in billing email id
287 $this->click('addEmail');
288 $this->waitForElementPresent('email_2_email');
289 $this->type('email_2_email', "$firstName.$lastName@billing.com");
290 $this->select('email_2_location_type_id', 'value=5');
292 //fill in home phone no
293 $this->type('phone_1_phone', "9876543210");
295 //fill in billing phone id
296 $this->click('addPhone');
297 $this->waitForElementPresent('phone_2_phone');
298 $this->type('phone_2_phone', "9876543120");
299 $this->select('phone_2_location_type_id', 'value=5');
302 $this->click("_qf_Contact_upload_view");
303 $this->waitForPageToLoad($this->getTimeoutMsec());
304 $this->waitForText('crm-notification-container', "Contact Saved");
306 // contact2: duplicate of contact1.
307 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
310 $this->type("first_name", $firstName);
313 $this->type("last_name", $lastName);
316 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
318 //fill in home phone no
319 $this->type('phone_1_phone', "9876543211");
322 $this->click("_qf_Contact_refresh_dedupe");
323 $this->waitForPageToLoad($this->getTimeoutMsec());
325 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
326 $this->click("_qf_Contact_upload_duplicate");
327 $this->waitForPageToLoad($this->getTimeoutMsec());
328 $this->waitForText('crm-notification-container', "Contact Saved");
330 // Find and Merge Contacts with Supervised Rule
331 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
333 // Select the contacts to be merged
334 $this->select("name=option51_length", "value=100");
335 $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']");
336 $this->click("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
337 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
338 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", "xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(overwrite)']");
339 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(add)']");
340 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
342 $this->check("move_location_email_1");
343 $this->check("location[email][1][operation]");
344 $this->check("move_location_email_2");
345 $this->check("move_location_phone_1");
346 $this->check("location[phone][1][operation]");
347 $this->check("move_location_phone_2");
348 $this->click("_qf_Merge_next-bottom");
349 $this->waitForPageToLoad($this->getTimeoutMsec());
351 $this->assertTrue($this->isTextPresent('Contacts Merged'));
352 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
353 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[text() = '{$firstName}.{$lastName}@example.com']"));
354 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
355 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[text() ='{$firstName}.{$lastName}@example.com']"));
356 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
357 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[2]/a[text() ='$firstName.$lastName@billing.com']"));
358 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
359 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543211')]"));
360 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
361 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
362 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
363 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[2][contains(text(), '9876543120')]"));
365 //Merge with the feature of (add)
366 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
370 $firstName1 = substr(sha1(rand()), 0, 7);
371 $this->type('first_name', $firstName1);
374 $lastName1 = substr(sha1(rand()), 0, 7);
375 $this->type('last_name', $lastName1);
377 //fill in billing email id
378 $this->waitForElementPresent('email_1_email');
379 $this->type('email_1_email', "$firstName1.$lastName1@example.com");
380 $this->select('email_1_location_type_id', 'value=5');
382 $this->click('addEmail');
383 $this->waitForElementPresent('email_2_email');
384 $this->type('email_2_email', "$firstName.$lastName@home.com");
385 $this->select('email_2_location_type_id', 'value=1');
387 //fill in home phone no
388 $this->type('phone_1_phone', "9876543210");
391 $this->click("_qf_Contact_upload_view");
392 $this->waitForPageToLoad($this->getTimeoutMsec());
393 $this->waitForText('crm-notification-container', "Contact Saved");
395 // contact2: duplicate of contact1.
396 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
399 $this->type("first_name", $firstName1);
402 $this->type("last_name", $lastName1);
405 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
407 //fill in billing phone no
408 $this->type('phone_1_phone', "9876543120");
409 $this->select('phone_1_location_type_id', 'value=5');
412 $this->click("_qf_Contact_refresh_dedupe");
413 $this->waitForPageToLoad($this->getTimeoutMsec());
414 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
415 $this->click("_qf_Contact_upload_duplicate");
416 $this->waitForPageToLoad($this->getTimeoutMsec());
417 $this->waitForText('crm-notification-container', "Contact Saved");
419 // Find and Merge Contacts with Supervised Rule
420 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
422 // Select the contacts to be merged
423 $this->select("name=option51_length", "value=100");
424 $this->waitForElementPresent("xpath=//table[@class='pagerDisplay']/tbody//tr/td[1]/a[text()='$firstName1 $lastName1']/../../td[2]/a[text()='$firstName1 $lastName1']");
425 $this->click("xpath=//table[@class='pagerDisplay']/tbody//tr/td[1]/a[text()='$firstName1 $lastName1']/../../td[2]/a[text()='$firstName1 $lastName1']/../../td[4]/a[text()='merge']");
426 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
427 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", "xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(overwrite)']");
428 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(add)']");
429 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[5]/td[4]/span[text()='(overwrite)']");
430 $this->select('location_email_1_locTypeId', 'value=3');
431 $this->select('location_phone_1_locTypeId', 'value=1');
432 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']"));
433 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']"));
434 $this->assertTrue($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']"));
435 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
437 $this->check("move_location_email_1");
438 $this->check("move_location_phone_1");
439 $this->click("_qf_Merge_next-bottom");
440 $this->waitForPageToLoad($this->getTimeoutMsec());
442 $this->assertTrue($this->isTextPresent('Contacts Merged'));
443 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
444 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[text() ='{$firstName1}.{$lastName1}@example.com']"));
445 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Main')]"));
446 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[text() ='{$firstName1}.{$lastName1}@example.com']"));
447 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Billing')]"));
448 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543120')]"));
449 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
450 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
453 function testBatchMerge(){
454 $this->webtestLogin();
456 // add contact1 and its duplicate
458 $firstName = "Kerry".substr(sha1(rand()), 0, 7);
460 $lastName = "King".substr(sha1(rand()), 0, 7);
461 $this->_createContacts($firstName,$lastName);
463 //add contact2 and its duplicate
464 //These are the contacts with conflicts in communication preference.these contacts will be skipped during merge.
465 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
468 $firstName1 = "Kurt".substr(sha1(rand()), 0, 7);
469 $this->type('first_name', $firstName1);
472 $lastName1 = "Cobain".substr(sha1(rand()), 0, 7);
473 $this->type('last_name', $lastName1);
476 $this->type('email_1_email', "{$firstName1}.{$lastName1}@example.com");
478 //fill in billing email id
479 $this->click('addEmail');
480 $this->waitForElementPresent('email_2_email');
481 $this->type('email_2_email', "$firstName1.$lastName1@billing.com");
482 $this->select('email_2_location_type_id', 'value=5');
484 //fill in home phone no
485 $this->type('phone_1_phone', "9876543210");
487 //fill in billing phone id
488 $this->click('addPhone');
489 $this->waitForElementPresent('phone_2_phone');
490 $this->type('phone_2_phone', "9876543120");
491 $this->select('phone_2_location_type_id', 'value=5');
493 //select communication preference
494 $this->check("privacy[do_not_phone]");
497 $this->click("_qf_Contact_upload_view");
498 $this->waitForPageToLoad($this->getTimeoutMsec());
499 $this->waitForText('crm-notification-container', "Contact Saved");
501 //duplicate of contact2.
502 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
505 $this->type("first_name", $firstName1);
508 $this->type("last_name", $lastName1);
511 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
513 //fill in home phone no
514 $this->type('phone_1_phone', "9876543211");
516 //select communication preference
517 $this->check("preferred_communication_method[1]");
520 $this->click("_qf_Contact_refresh_dedupe");
521 $this->waitForPageToLoad($this->getTimeoutMsec());
523 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
524 $this->click("_qf_Contact_upload_duplicate");
525 $this->waitForPageToLoad($this->getTimeoutMsec());
526 $this->waitForText('crm-notification-container', "Contact Saved");
528 // add contact3 and its duplicate
530 $firstName2 = "David".substr(sha1(rand()), 0, 7);
532 $lastName2 = "Gilmour".substr(sha1(rand()), 0, 7);
533 $this->_createContacts($firstName2,$lastName2);
535 // add contact4 and its duplicate
537 $firstName3 = "Dave".substr(sha1(rand()), 0, 7);
539 $lastName3 = "Mustaine".substr(sha1(rand()), 0, 7);
540 $this->_createContacts($firstName3,$lastName3);
542 // Find and Merge Contacts with Supervised Rule
543 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew", "css=#DedupeFind table.pagerDisplay tbody tr");
545 $this->select("name=option51_length", "value=100");
546 $totalContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
547 $this->click("xpath=//form[@id='DedupeFind']//a/span[text()='Batch Merge Duplicates']");
549 // Check confirmation alert.
551 (bool)preg_match("/^This will run the batch merge process on the listed duplicates. The operation will run in safe mode - only records with no direct data conflicts will be merged. Click OK to proceed if you are sure you wish to run this operation./",
552 $this->getConfirmation()
554 $this->chooseOkOnNextConfirmation();
555 $this->waitForPageToLoad($this->getTimeoutMsec());
556 $this->waitForElementPresent('civicrm-footer');
557 $this->waitForText('crm-notification-container', "safe mode");
559 // If we are still on the dedupe table page, count unmerged contacts
560 if ($this->isElementPresent("//table[@class='pagerDisplay']")) {
561 // Wait for datatable to load
562 $this->waitForElementPresent("//table[@class='pagerDisplay']/tbody/tr");
563 $unMergedContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
566 $unMergedContacts = 0;
569 $mergedContacts = $totalContacts - $unMergedContacts;
571 //check the existence of merged contacts
572 $contactEmails = array(
573 1 => "{$firstName}.{$lastName}@example.com",
574 2 => "{$firstName2}.{$lastName2}@example.com",
575 3 => "{$firstName3}.{$lastName3}@example.com"
578 foreach($contactEmails as $key => $value) {
579 $this->click('sort_name_navigation');
580 $this->type('css=input#sort_name_navigation', $value);
581 $this->typeKeys('css=input#sort_name_navigation', $value);
582 // Wait for result list.
583 $this->waitForElementPresent("css=div.ac_results-inner li");
585 // Visit contact summary page.
586 $this->clickLink("css=div.ac_results-inner li", 'civicrm-footer');
593 function _createContacts($firstName = NULL, $lastName = NULL, $organizationName = NULL, $contactType = 'Individual') {
594 if ($contactType == 'Individual') {
596 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
598 $this->type('first_name', $firstName);
601 $this->type('last_name', $lastName);
604 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
606 //fill in billing email id
607 $this->click('addEmail');
608 $this->waitForElementPresent('email_2_email');
609 $this->type('email_2_email', "$firstName.$lastName@billing.com");
610 $this->select('email_2_location_type_id', 'value=5');
613 $this->click("_qf_Contact_upload_view");
614 $this->waitForPageToLoad($this->getTimeoutMsec());
615 $this->waitForText('crm-notification-container', "Contact Saved");
617 //duplicate of above contact.
618 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
621 $this->type("first_name", $firstName);
624 $this->type("last_name", $lastName);
627 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
630 $this->click("_qf_Contact_refresh_dedupe");
631 $this->waitForPageToLoad($this->getTimeoutMsec());
633 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
634 $this->click("_qf_Contact_upload_duplicate");
635 $this->waitForPageToLoad($this->getTimeoutMsec());
636 $this->waitForText('crm-notification-container', "Contact Saved");
638 elseif ($contactType == 'Organization') {
640 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
641 //fill in Organization name
642 $this->type('organization_name', $organizationName);
645 $this->type('email_1_email', "{$organizationName}@org.com");
647 $this->click("_qf_Contact_upload_view-bottom");
648 $this->waitForPageToLoad($this->getTimeoutMsec());
649 $this->waitForText('crm-notification-container', "Contact Saved");
650 $mainId = explode("CiviCRM ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
651 $mainId = trim($mainId[1]);
653 //Duplicate of above contact.
654 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
656 //fill in Organization name
657 $this->type('organization_name', $organizationName);
660 $this->type('email_1_email', "{$organizationName}@org.com");
663 $this->click("_qf_Contact_upload_view-bottom");
664 $this->waitForPageToLoad($this->getTimeoutMsec());
666 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
667 $this->click("_qf_Contact_upload_duplicate");
668 $this->waitForPageToLoad($this->getTimeoutMsec());
669 $this->waitForText('crm-notification-container', "Contact Saved");
670 $duplicateId = explode("CiviCRM ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
671 $duplicateId = trim($duplicateId[1]);
675 'duplicateId' => $duplicateId
682 * to create new membershiptype
684 function addMembershipType($membershipOrganization) {
685 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
686 $this->click("link=Add Membership Type");
687 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
689 $this->type('name', "Membership Type $membershipOrganization");
690 $this->type('member_of_contact', $membershipOrganization);
691 $this->click('member_of_contact');
692 $this->waitForElementPresent("css=div.ac_results-inner li");
693 $this->click("css=div.ac_results-inner li.ac_even");
695 $this->type('minimum_fee', '1');
696 $this->select( 'financial_type_id', 'value=2' );
697 $this->type('duration_interval', 1);
698 $this->select('duration_unit', "label=year");
700 $this->select('period_type', "label=fixed");
701 $this->waitForElementPresent('fixed_period_rollover_day[d]');
703 // fixed period start set to April 1
704 $this->select('fixed_period_start_day[M]', 'value=4');
705 // rollover date set to Jan 31
706 $this->select('fixed_period_rollover_day[M]', 'value=1');
708 // Employer of relationship
709 $this->select('relationship_type_id', 'value=5_b_a');
710 $this->click('_qf_MembershipType_upload-bottom');
711 $this->waitForElementPresent('link=Add Membership Type');
712 $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $membershipOrganization' has been saved."));
716 * Test for CRM-12695 fix
718 function testMergeOrganizations() {
719 $this->webtestLogin();
721 // build organisation name
722 $orgnaizationName = 'org_'.substr(sha1(rand()), 0, 7);
724 $contactIds = array();
725 // create organization and its duplicate
726 $contactIds = $this->_createContacts(NULL, NULL, $orgnaizationName, 'Organization');
728 /*** Add Membership Type - start ***/
729 $this->addMembershipType($orgnaizationName);
730 /*** Add Membership Type - end ***/
732 //create a New Individual to be related to main organization
733 $firstName = substr(sha1(rand()), 0, 7);
734 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
735 $sortName = "Anderson, $firstName";
737 // go to main organization contact to add membership
738 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['mainId']}");
739 // click through to the membership view screen
740 $this->click("css=li#tab_member a");
742 $this->waitForElementPresent("link=Add Membership");
743 $this->click("link=Add Membership");
745 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
747 // fill in Membership Organization and Type
748 $this->select("membership_type_id[0]", "label={$orgnaizationName}");
749 $this->waitForElementPresent("membership_type_id[1]");
750 // Wait for membership type select to reload
751 $this->waitForTextPresent("Membership Type $orgnaizationName");
752 $this->select("membership_type_id[1]", "label=Membership Type $orgnaizationName");
754 $sourceText = "Membership-Organization Duplicate Merge Webtest";
756 $this->type("source", $sourceText);
758 // Let Join Date stay default
760 // fill in Start Date
761 $this->webtestFillDate('start_date');
764 $this->click("_qf_Membership_upload");
765 $this->waitForPageToLoad($this->getTimeoutMsec());
767 $this->waitForTextPresent($sourceText);
768 // Is status message correct?
769 $this->waitForText('crm-notification-container', "membership for $orgnaizationName has been added.");
771 // add relationship "Employer of"
772 // click through to the relationship view screen
773 $this->click("css=li#tab_rel a");
775 // wait for add Relationship link
776 $this->waitForElementPresent('link=Add Relationship');
777 $this->click('link=Add Relationship');
779 //choose the created relationship type
780 $this->waitForElementPresent("relationship_type_id");
781 $this->select('relationship_type_id', "value=5_b_a");
783 //fill in the individual
784 $this->webtestFillAutocomplete($sortName);
786 $this->waitForElementPresent("quick-save");
788 //fill in the relationship start date
789 //$this->webtestFillDate('start_date', '-2 year');
790 //$this->webtestFillDate('end_date', '+1 year');
792 $description = "Well here is some description !!!!";
793 $this->type("description", $description);
795 //save the relationship
796 $this->click("quick-save");
797 $this->waitForElementPresent("current-relationships");
799 //check the status message
800 $this->assertTrue($this->isTextPresent("New relationship created."));
802 $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
803 $this->waitForElementPresent("xpath=//a[text()='$sortName']");
804 $this->click("xpath=//a[text()='$sortName']");
805 $this->waitForPageToLoad($this->getTimeoutMsec());
807 // Check if Membership for the individual is created
808 $this->waitForElementPresent("xpath=//li[@id='tab_member']/a/em");
809 $this->verifyText("xpath=//li[@id='tab_member']/a/em", 1);
811 //create a New Individual to be related to duplicate organization
812 $firstNameOther = substr(sha1(rand()), 0, 7);
813 $this->webtestAddContact($firstNameOther, "Harmison", "$firstNameOther@harmison.name");
814 $sortNameOther = "Harmison, $firstNameOther";
816 // go to main organization contact to add membership
817 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['duplicateId']}");
819 // add relationship "Employer of"
820 // click through to the relationship view screen
821 $this->click("css=li#tab_rel a");
823 // wait for add Relationship link
824 $this->waitForElementPresent('link=Add Relationship');
825 $this->click('link=Add Relationship');
827 //choose the created relationship type
828 $this->waitForElementPresent("relationship_type_id");
829 $this->select('relationship_type_id', "value=5_b_a");
831 //fill in the individual
832 $this->webtestFillAutocomplete($sortNameOther);
834 $this->waitForElementPresent("quick-save");
836 //fill in the relationship start date
837 $this->webtestFillDate('start_date', '-2 year');
838 $this->webtestFillDate('end_date', '+1 year');
840 $description = "Well here is some description !!!!";
841 $this->type("description", $description);
843 //save the relationship
844 //$this->click("_qf_Relationship_upload");
845 $this->click("quick-save");
846 $this->waitForElementPresent("current-relationships");
848 //check the status message
849 $this->assertTrue($this->isTextPresent("New relationship created."));
851 $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
853 // go directly to contact merge page.
854 $this->openCiviPage("contact/merge", "reset=1&cid={$contactIds['mainId']}&oid={$contactIds['duplicateId']}&action=update&rgid=2");
856 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
857 $this->click('_qf_Merge_next-bottom');
858 $this->waitForPageToLoad($this->getTimeoutMsec());
860 // click through to the relationship view screen
861 $this->click("css=li#tab_rel a");
863 // wait for add Relationship link
864 $this->waitForElementPresent("xpath=//a[text()='$sortNameOther']");
865 // go to duplicate organization's related contact
866 // to check if membership is added to that contact
867 $this->click("xpath=//a[text()='$sortNameOther']");
868 $this->waitForPageToLoad($this->getTimeoutMsec());
870 // Check if Membership for the individual is created
871 $this->waitForElementPresent("xpath=//li[@id='tab_member']/a/em");
872 $this->verifyText("xpath=//li[@id='tab_member']/a/em", 1);