Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-06-25-23-42-42
[civicrm-core.git] / tests / phpunit / WebTest / Contact / MergeContactsTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
25 */
26
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Contact_MergeContactsTest
31 */
32 class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testIndividualAdd() {
39 $this->webtestLogin();
40
41 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
42
43 // add contact1
44 //select prefix
45 $prefix = 'Mr.';
46 $this->click("prefix_id");
47 $this->select("prefix_id", "label=$prefix");
48
49 //fill in first name
50 $firstName = substr(sha1(rand()), 0, 7);
51 $this->type('first_name', $firstName);
52
53 //fill in last name
54 $lastName = substr(sha1(rand()), 0, 7);
55 $this->type('last_name', $lastName);
56
57 //fill in email id
58 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
59
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');
65
66 // Clicking save.
67 $this->click("_qf_Contact_upload_view");
68 $this->waitForPageToLoad($this->getTimeoutMsec());
69 $this->waitForText('crm-notification-container', "Contact Saved");
70
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");
79
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);
87
88 // Add an activity
89 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
90 $this->addActivity($firstName, $lastName, $subject);
91
92 // contact2: duplicate of contact1.
93 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
94
95 //fill in first name
96 $this->type("first_name", $firstName);
97
98 //fill in last name
99 $this->type("last_name", $lastName);
100
101 //fill in email
102 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
103
104 // Clicking save.
105 $this->click("_qf_Contact_refresh_dedupe");
106 $this->waitForPageToLoad($this->getTimeoutMsec());
107
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");
112
113 // Add second pair of dupes so we can test Merge and Goto Next Pair
114 $fname2 = 'Janet';
115 $lname2 = 'Rogers' . substr(sha1(rand()), 0, 7);
116 $email2 = "{$fname2}.{$lname2}@example.org";
117 $this->webtestAddContact($fname2, $lname2, $email2);
118
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");
130
131 // Find and Merge Contacts with Supervised Rule
132 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
133
134 // reload the page
135 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=update");
136
137 // Select the contacts to be merged
138 $this->select("name=option51_length", "value=100");
139
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');
143
144 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", '_qf_Merge_cancel-bottom');
145
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.");
154
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.");
157
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.");
165
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");
171
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());
174
175 // Verify prefix merged
176 // $this->verifyText( "xpath=//div[@class='left-corner']/h2", preg_quote( "$prefix $firstName $lastName" ) );
177
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']");
180
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")
186 );
187
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",
193 preg_quote("$group")
194 );
195
196 // Verify tag merged
197 $this->click("css=li#tab_tag a");
198 $this->waitForElementPresent('check_5');
199 $this->assertChecked("check_3");
200 }
201
202 /**
203 * @param $firstName
204 * @param $lastName
205 * @param $subject
206 */
207 function addActivity($firstName, $lastName, $subject) {
208 $withContact = substr(sha1(rand()), 0, 7);
209 $this->webtestAddContact($withContact, "Anderson", $withContact . "@anderson.name");
210
211 $this->click("css=li#tab_activity a");
212
213 // waiting for the activity dropdown to show up
214 $this->waitForElementPresent("other_activity");
215
216 // Select the activity type from the activity dropdown
217 $this->select("other_activity", "label=Meeting");
218
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");
222
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__);
225
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);
229
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__);
232
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."));
235
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.");
240
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');
246
247 // Setting duration.
248 $this->type("duration", "30");
249
250 // Putting in details.
251 $this->type("details", "Really brief details information.");
252
253 // Making sure that status is set to Scheduled (using value, not label).
254 $this->select("status_id", "value=1");
255
256 // Setting priority.
257 $this->select("priority_id", "value=1");
258
259 // Clicking save.
260 $this->click("_qf_Activity_upload");
261 $this->waitForElementPresent("crm-notification-container");
262
263 // Is status message correct?
264 $this->waitForText('crm-notification-container', "Activity '$subject' has been saved.", "Status message didn't show up after saving!");
265 }
266
267 function testMergeTest() {
268 $this->webtestLogin();
269
270 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
271
272 // add contact1
273 //fill in first name
274 $firstName = substr(sha1(rand()), 0, 7);
275 $this->type('first_name', $firstName);
276
277 //fill in last name
278 $lastName = substr(sha1(rand()), 0, 7);
279 $this->type('last_name', $lastName);
280
281 //fill in email id
282 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
283
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');
289
290 //fill in home phone no
291 $this->type('phone_1_phone', "9876543210");
292
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');
298
299 // Clicking save.
300 $this->click("_qf_Contact_upload_view");
301 $this->waitForPageToLoad($this->getTimeoutMsec());
302 $this->waitForText('crm-notification-container', "Contact Saved");
303
304 // contact2: duplicate of contact1.
305 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
306
307 //fill in first name
308 $this->type("first_name", $firstName);
309
310 //fill in last name
311 $this->type("last_name", $lastName);
312
313 //fill in email
314 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
315
316 //fill in home phone no
317 $this->type('phone_1_phone', "9876543211");
318
319 // Clicking save.
320 $this->click("_qf_Contact_refresh_dedupe");
321 $this->waitForPageToLoad($this->getTimeoutMsec());
322
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");
327
328 // Find and Merge Contacts with Supervised Rule
329 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
330
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');
339
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());
348
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')]"));
362
363 //Merge with the feature of (add)
364 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
365
366 // add contact1
367 //fill in first name
368 $firstName1 = substr(sha1(rand()), 0, 7);
369 $this->type('first_name', $firstName1);
370
371 //fill in last name
372 $lastName1 = substr(sha1(rand()), 0, 7);
373 $this->type('last_name', $lastName1);
374
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');
379
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');
384
385 //fill in home phone no
386 $this->type('phone_1_phone', "9876543210");
387
388 // Clicking save.
389 $this->click("_qf_Contact_upload_view");
390 $this->waitForPageToLoad($this->getTimeoutMsec());
391 $this->waitForText('crm-notification-container', "Contact Saved");
392
393 // contact2: duplicate of contact1.
394 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
395
396 //fill in first name
397 $this->type("first_name", $firstName1);
398
399 //fill in last name
400 $this->type("last_name", $lastName1);
401
402 //fill in email
403 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
404
405 //fill in billing phone no
406 $this->type('phone_1_phone', "9876543120");
407 $this->select('phone_1_location_type_id', 'value=5');
408
409 // Clicking save.
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");
416
417 // Find and Merge Contacts with Supervised Rule
418 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
419
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');
434
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());
439
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')]"));
449 }
450
451 function testBatchMerge(){
452 $this->webtestLogin();
453
454 // add contact1 and its duplicate
455 //first name
456 $firstName = "Kerry".substr(sha1(rand()), 0, 7);
457 //last name
458 $lastName = "King".substr(sha1(rand()), 0, 7);
459 $this->_createContacts($firstName,$lastName);
460
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");
464
465 //fill in first name
466 $firstName1 = "Kurt".substr(sha1(rand()), 0, 7);
467 $this->type('first_name', $firstName1);
468
469 //fill in last name
470 $lastName1 = "Cobain".substr(sha1(rand()), 0, 7);
471 $this->type('last_name', $lastName1);
472
473 //fill in email id
474 $this->type('email_1_email', "{$firstName1}.{$lastName1}@example.com");
475
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');
481
482 //fill in home phone no
483 $this->type('phone_1_phone', "9876543210");
484
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');
490
491 //select communication preference
492 $this->check("privacy[do_not_phone]");
493
494 //Clicking save.
495 $this->click("_qf_Contact_upload_view");
496 $this->waitForPageToLoad($this->getTimeoutMsec());
497 $this->waitForText('crm-notification-container', "Contact Saved");
498
499 //duplicate of contact2.
500 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
501
502 //fill in first name
503 $this->type("first_name", $firstName1);
504
505 //fill in last name
506 $this->type("last_name", $lastName1);
507
508 //fill in email
509 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
510
511 //fill in home phone no
512 $this->type('phone_1_phone', "9876543211");
513
514 //select communication preference
515 $this->check("preferred_communication_method[1]");
516
517 // Clicking save.
518 $this->click("_qf_Contact_refresh_dedupe");
519 $this->waitForPageToLoad($this->getTimeoutMsec());
520
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");
525
526 // add contact3 and its duplicate
527 //fill in first name
528 $firstName2 = "David".substr(sha1(rand()), 0, 7);
529 //fill in last name
530 $lastName2 = "Gilmour".substr(sha1(rand()), 0, 7);
531 $this->_createContacts($firstName2,$lastName2);
532
533 // add contact4 and its duplicate
534 //fill in first name
535 $firstName3 = "Dave".substr(sha1(rand()), 0, 7);
536 //fill in last name
537 $lastName3 = "Mustaine".substr(sha1(rand()), 0, 7);
538 $this->_createContacts($firstName3,$lastName3);
539
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");
542
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']");
546
547 // Check confirmation alert.
548 $this->assertTrue(
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()
551 ));
552 $this->chooseOkOnNextConfirmation();
553 $this->waitForPageToLoad($this->getTimeoutMsec());
554 $this->waitForElementPresent('civicrm-footer');
555 $this->waitForText('crm-notification-container', "safe mode");
556
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");
562 }
563 else {
564 $unMergedContacts = 0;
565 }
566
567 $mergedContacts = $totalContacts - $unMergedContacts;
568
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"
574 );
575
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");
582
583 // Visit contact summary page.
584 $this->clickLink("css=ul.ui-autocomplete li.ui-menu-item", 'civicrm-footer');
585 }
586 }
587
588 /**
589 * Helper FN
590 */
591 function _createContacts($firstName = NULL, $lastName = NULL, $organizationName = NULL, $contactType = 'Individual') {
592 if ($contactType == 'Individual') {
593 // add contact
594 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
595 //fill in first name
596 $this->type('first_name', $firstName);
597
598 //fill in last name
599 $this->type('last_name', $lastName);
600
601 //fill in email id
602 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
603
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');
609
610 // Clicking save.
611 $this->click("_qf_Contact_upload_view");
612 $this->waitForPageToLoad($this->getTimeoutMsec());
613 $this->waitForText('crm-notification-container', "Contact Saved");
614
615 //duplicate of above contact.
616 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
617
618 //fill in first name
619 $this->type("first_name", $firstName);
620
621 //fill in last name
622 $this->type("last_name", $lastName);
623
624 //fill in email
625 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
626
627 // Clicking save.
628 $this->click("_qf_Contact_refresh_dedupe");
629 $this->waitForPageToLoad($this->getTimeoutMsec());
630
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");
635 }
636 elseif ($contactType == 'Organization') {
637 // add contact
638 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
639 //fill in Organization name
640 $this->type('organization_name', $organizationName);
641
642 //fill in email id
643 $this->type('email_1_email', "{$organizationName}@org.com");
644 // Clicking save.
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]);
650
651 //Duplicate of above contact.
652 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
653
654 //fill in Organization name
655 $this->type('organization_name', $organizationName);
656
657 //fill in email id
658 $this->type('email_1_email', "{$organizationName}@org.com");
659
660 // Clicking save.
661 $this->click("_qf_Contact_upload_view-bottom");
662 $this->waitForPageToLoad($this->getTimeoutMsec());
663
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]);
670
671 return array(
672 'mainId' => $mainId,
673 'duplicateId' => $duplicateId
674 );
675 }
676 }
677
678 /**
679 * Helper FN
680 * to create new membership type
681 */
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');
686
687 $this->type('name', "Membership Type $membershipOrganization");
688 $this->select2('member_of_contact_id', $membershipOrganization);
689
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");
694
695 $this->select('period_type', "label=Fixed");
696 $this->waitForElementPresent('fixed_period_rollover_day[d]');
697
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');
702
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.");
708 }
709
710 /**
711 * Test for CRM-12695 fix
712 */
713 function testMergeOrganizations() {
714 $this->webtestLogin();
715
716 // build organisation name
717 $orgnaizationName = 'org_'.substr(sha1(rand()), 0, 7);
718
719 $contactIds = array();
720 // create organization and its duplicate
721 $contactIds = $this->_createContacts(NULL, NULL, $orgnaizationName, 'Organization');
722
723 /*** Add Membership Type - start ***/
724 $this->addMembershipType($orgnaizationName);
725 /*** Add Membership Type - end ***/
726
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";
731
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");
736
737 $this->waitForElementPresent("link=Add Membership");
738 $this->click("link=Add Membership");
739
740 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
741
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");
748
749 $sourceText = "Membership-Organization Duplicate Merge Webtest";
750 // fill in Source
751 $this->type("source", $sourceText);
752
753 // Let Join Date stay default
754
755 // fill in Start Date
756 $this->webtestFillDate('start_date');
757
758 // Clicking save.
759 $this->click("_qf_Membership_upload");
760 $this->waitForElementPresent('crm-notification-container');
761 // page was loaded
762 $this->waitForTextPresent($sourceText);
763 // Is status message correct?
764 $this->waitForText('crm-notification-container', "membership for $orgnaizationName has been added.");
765
766 // add relationship "Employer of"
767 // click through to the relationship view screen
768 $this->click("css=li#tab_rel a");
769
770 // wait for add Relationship link
771 $this->waitForElementPresent('link=Add Relationship');
772 $this->click('link=Add Relationship');
773
774 //choose the created relationship type
775 $this->waitForElementPresent("relationship_type_id");
776 $this->select('relationship_type_id', "value=5_b_a");
777
778 //fill in the individual
779 $this->select2('related_contact_id', $sortName, TRUE, FALSE);
780
781 $this->waitForElementPresent("_qf_Relationship_upload");
782
783 //fill in the relationship start date
784 //$this->webtestFillDate('start_date', '-2 year');
785 //$this->webtestFillDate('end_date', '+1 year');
786
787 $description = "Well here is some description !!!!";
788 $this->type("description", $description);
789
790 //save the relationship
791 $this->click("_qf_Relationship_upload");
792 $this->isTextPresent("Current Relationships");
793
794 //check the status message
795 $this->waitForText('crm-notification-container', "Relationship created.");
796
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());
801
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);
805
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";
810
811 // go to main organization contact to add membership
812 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['duplicateId']}");
813
814 // add relationship "Employer of"
815 // click through to the relationship view screen
816 $this->click("css=li#tab_rel a");
817
818 // wait for add Relationship link
819 $this->waitForElementPresent('link=Add Relationship');
820 $this->click('link=Add Relationship');
821
822 //choose the created relationship type
823 $this->waitForElementPresent("relationship_type_id");
824 $this->select('relationship_type_id', "value=5_b_a");
825
826 //fill in the individual
827 $this->select2('related_contact_id', $sortNameOther, TRUE, FALSE);
828
829 $this->waitForElementPresent("_qf_Relationship_upload");
830
831 //fill in the relationship start date
832 $this->webtestFillDate('start_date', '-2 year');
833 $this->webtestFillDate('end_date', '+1 year');
834
835 $description = "Well here is some description !!!!";
836 $this->type("description", $description);
837
838 //save the relationship
839 //$this->click("_qf_Relationship_upload");
840 $this->click("_qf_Relationship_upload");
841 $this->isTextPresent("Current Relationships");
842
843 //check the status message
844 $this->isTextPresent("Relationship created.");
845
846 $this->waitForElementPresent("xpath=//table[@id='crm-contact-relationship-selector-current']/tbody//tr/td[9]/span/a[text()='View']");
847
848 // go directly to contact merge page.
849 $this->openCiviPage("contact/merge", "reset=1&cid={$contactIds['mainId']}&oid={$contactIds['duplicateId']}&action=update&rgid=2");
850
851 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
852 $this->click('_qf_Merge_next-bottom');
853 $this->waitForPageToLoad($this->getTimeoutMsec());
854
855 // click through to the relationship view screen
856 $this->click("css=li#tab_rel a");
857
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());
864
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);
868 }
869 }
870