Merge pull request #2876 from mepps/participant-image-event-badge
[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 class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testIndividualAdd() {
35 $this->webtestLogin();
36
37 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
38
39 // add contact1
40 //select prefix
41 $prefix = 'Mr.';
42 $this->click("prefix_id");
43 $this->select("prefix_id", "label=$prefix");
44
45 //fill in first name
46 $firstName = substr(sha1(rand()), 0, 7);
47 $this->type('first_name', $firstName);
48
49 //fill in last name
50 $lastName = substr(sha1(rand()), 0, 7);
51 $this->type('last_name', $lastName);
52
53 //fill in email id
54 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
55
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');
61
62 // Clicking save.
63 $this->click("_qf_Contact_upload_view");
64 $this->waitForPageToLoad($this->getTimeoutMsec());
65 $this->waitForText('crm-notification-container', "Contact Saved");
66
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->waitForElementPresent('link=Delete');
74 $this->waitForText('crm-notification-container', "Added to Group");
75
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);
83
84 // Add an activity
85 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
86 $this->addActivity($firstName, $lastName, $subject);
87
88 // contact2: duplicate of contact1.
89 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
90
91 //fill in first name
92 $this->type("first_name", $firstName);
93
94 //fill in last name
95 $this->type("last_name", $lastName);
96
97 //fill in email
98 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
99
100 // Clicking save.
101 $this->click("_qf_Contact_refresh_dedupe");
102 $this->waitForPageToLoad($this->getTimeoutMsec());
103
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");
108
109 // Add second pair of dupes so we can test Merge and Goto Next Pair
110 $fname2 = 'Janet';
111 $lname2 = 'Rogers' . substr(sha1(rand()), 0, 7);
112 $email2 = "{$fname2}.{$lname2}@example.org";
113 $this->webtestAddContact($fname2, $lname2, $email2);
114
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");
126
127 // Find and Merge Contacts with Supervised Rule
128 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
129
130 // reload the page
131 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=update");
132
133 // Select the contacts to be merged
134 $this->select("name=option51_length", "value=100");
135
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');
139
140 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", '_qf_Merge_cancel-bottom');
141
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.");
150
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.");
153
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.");
161
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");
167
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());
170
171 // Verify prefix merged
172 // $this->verifyText( "xpath=//div[@class='left-corner']/h2", preg_quote( "$prefix $firstName $lastName" ) );
173
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']");
176
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")
182 );
183
184 // Verify group merged
185 $this->click("css=li#tab_group a");
186 $this->waitForElementPresent("GroupContact");
187 $this->waitForElementPresent("xpath=//form[@id='GroupContact']//div[@class='view-content view-contact-groups']//div/table/tbody/tr/td/a");
188 $this->verifyText("xpath=//form[@id='GroupContact']//div[@class='view-content view-contact-groups']//div/table/tbody/tr/td/a",
189 preg_quote("$group")
190 );
191
192 // Verify tag merged
193 $this->click("css=li#tab_tag a");
194 $this->waitForElementPresent('check_5');
195 $this->assertChecked("check_3");
196 }
197
198 function addActivity($firstName, $lastName, $subject) {
199 $withContact = substr(sha1(rand()), 0, 7);
200 $this->webtestAddContact($withContact, "Anderson", $withContact . "@anderson.name");
201
202 $this->click("css=li#tab_activity a");
203
204 // waiting for the activity dropdown to show up
205 $this->waitForElementPresent("other_activity");
206
207 // Select the activity type from the activity dropdown
208 $this->select("other_activity", "label=Meeting");
209
210 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
211 // button at the end of this page to show up, to make sure it's fully loaded.
212 $this->waitForElementPresent("_qf_Activity_upload");
213
214 // ...and verifying if the page contains properly formatted display name for chosen contact.
215 $this->assertTrue($this->isTextPresent("Anderson, " . $withContact), "Contact not found in line " . __LINE__);
216
217 // Now we're filling the "Assigned To" field.
218 // Typing contact's name into the field (using typeKeys(), not type()!)...
219 $this->select2("assignee_contact_id", $firstName,TRUE,FALSE);
220
221 // ...and verifying if the page contains properly formatted display name for chosen contact.
222 $this->assertTrue($this->isTextPresent("$lastName, " . $firstName), "Contact not found in line " . __LINE__);
223
224 // Since we're here, let's check if screen help is being displayed properly
225 $this->assertTrue($this->isTextPresent("A copy of this activity will be emailed to each Assignee."));
226
227 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
228 // For simple input fields we can use field id as selector
229 $this->type("subject", $subject);
230 $this->type("location", "Some location needs to be put in this field.");
231
232 // Choosing the Date.
233 // Please note that we don't want to put in fixed date, since
234 // we want this test to work in the future and not fail because
235 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
236 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
237
238 // Setting duration.
239 $this->type("duration", "30");
240
241 // Putting in details.
242 $this->type("details", "Really brief details information.");
243
244 // Making sure that status is set to Scheduled (using value, not label).
245 $this->select("status_id", "value=1");
246
247 // Setting priority.
248 $this->select("priority_id", "value=1");
249
250 // Clicking save.
251 $this->click("_qf_Activity_upload");
252 $this->waitForElementPresent("crm-notification-container");
253
254 // Is status message correct?
255 $this->waitForText('crm-notification-container', "Activity '$subject' has been saved.", "Status message didn't show up after saving!");
256 }
257
258 function testMergeTest() {
259 $this->webtestLogin();
260
261 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
262
263 // add contact1
264 //fill in first name
265 $firstName = substr(sha1(rand()), 0, 7);
266 $this->type('first_name', $firstName);
267
268 //fill in last name
269 $lastName = substr(sha1(rand()), 0, 7);
270 $this->type('last_name', $lastName);
271
272 //fill in email id
273 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
274
275 //fill in billing email id
276 $this->click('addEmail');
277 $this->waitForElementPresent('email_2_email');
278 $this->type('email_2_email', "$firstName.$lastName@billing.com");
279 $this->select('email_2_location_type_id', 'value=5');
280
281 //fill in home phone no
282 $this->type('phone_1_phone', "9876543210");
283
284 //fill in billing phone id
285 $this->click('addPhone');
286 $this->waitForElementPresent('phone_2_phone');
287 $this->type('phone_2_phone', "9876543120");
288 $this->select('phone_2_location_type_id', 'value=5');
289
290 // Clicking save.
291 $this->click("_qf_Contact_upload_view");
292 $this->waitForPageToLoad($this->getTimeoutMsec());
293 $this->waitForText('crm-notification-container', "Contact Saved");
294
295 // contact2: duplicate of contact1.
296 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
297
298 //fill in first name
299 $this->type("first_name", $firstName);
300
301 //fill in last name
302 $this->type("last_name", $lastName);
303
304 //fill in email
305 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
306
307 //fill in home phone no
308 $this->type('phone_1_phone', "9876543211");
309
310 // Clicking save.
311 $this->click("_qf_Contact_refresh_dedupe");
312 $this->waitForPageToLoad($this->getTimeoutMsec());
313
314 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
315 $this->click("_qf_Contact_upload_duplicate");
316 $this->waitForPageToLoad($this->getTimeoutMsec());
317 $this->waitForText('crm-notification-container', "Contact Saved");
318
319 // Find and Merge Contacts with Supervised Rule
320 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
321
322 // Select the contacts to be merged
323 $this->select("name=option51_length", "value=100");
324 $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']");
325 $this->click("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']");
326 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
327 $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);
328 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[5]/td[4]/span[text()='(add)']");
329 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
330
331 $this->check("move_location_email_1");
332 $this->check("location[email][1][operation]");
333 $this->check("move_location_email_2");
334 $this->check("move_location_phone_1");
335 $this->check("location[phone][1][operation]");
336 $this->check("move_location_phone_2");
337 $this->click("_qf_Merge_next-bottom");
338 $this->waitForPageToLoad($this->getTimeoutMsec());
339
340 $this->assertTrue($this->isTextPresent('Contacts Merged'));
341 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
342 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[text() = '{$firstName}.{$lastName}@example.com']"));
343 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
344 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[text() ='{$firstName}.{$lastName}@example.com']"));
345 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
346 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[2]/a[text() ='$firstName.$lastName@billing.com']"));
347 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
348 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543211')]"));
349 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
350 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
351 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
352 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[2][contains(text(), '9876543120')]"));
353
354 //Merge with the feature of (add)
355 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
356
357 // add contact1
358 //fill in first name
359 $firstName1 = substr(sha1(rand()), 0, 7);
360 $this->type('first_name', $firstName1);
361
362 //fill in last name
363 $lastName1 = substr(sha1(rand()), 0, 7);
364 $this->type('last_name', $lastName1);
365
366 //fill in billing email id
367 $this->waitForElementPresent('email_1_email');
368 $this->type('email_1_email', "$firstName1.$lastName1@example.com");
369 $this->select('email_1_location_type_id', 'value=5');
370
371 $this->click('addEmail');
372 $this->waitForElementPresent('email_2_email');
373 $this->type('email_2_email', "$firstName.$lastName@home.com");
374 $this->select('email_2_location_type_id', 'value=1');
375
376 //fill in home phone no
377 $this->type('phone_1_phone', "9876543210");
378
379 // Clicking save.
380 $this->click("_qf_Contact_upload_view");
381 $this->waitForPageToLoad($this->getTimeoutMsec());
382 $this->waitForText('crm-notification-container', "Contact Saved");
383
384 // contact2: duplicate of contact1.
385 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
386
387 //fill in first name
388 $this->type("first_name", $firstName1);
389
390 //fill in last name
391 $this->type("last_name", $lastName1);
392
393 //fill in email
394 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
395
396 //fill in billing phone no
397 $this->type('phone_1_phone', "9876543120");
398 $this->select('phone_1_location_type_id', 'value=5');
399
400 // Clicking save.
401 $this->click("_qf_Contact_refresh_dedupe");
402 $this->waitForPageToLoad($this->getTimeoutMsec());
403 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
404 $this->click("_qf_Contact_upload_duplicate");
405 $this->waitForPageToLoad($this->getTimeoutMsec());
406 $this->waitForText('crm-notification-container', "Contact Saved");
407
408 // Find and Merge Contacts with Supervised Rule
409 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
410
411 // Select the contacts to be merged
412 $this->select("name=option51_length", "value=100");
413 $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']");
414 $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']");
415 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
416 $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)']");
417 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']");
418 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']");
419 $this->select('location_email_1_locTypeId', 'value=3');
420 $this->select('location_phone_1_locTypeId', 'value=1');
421 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']"));
422 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']"));
423 $this->assertTrue($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']"));
424 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
425
426 $this->check("move_location_email_1");
427 $this->check("move_location_phone_1");
428 $this->click("_qf_Merge_next-bottom");
429 $this->waitForPageToLoad($this->getTimeoutMsec());
430
431 $this->assertTrue($this->isTextPresent('Contacts Merged'));
432 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
433 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[text() ='{$firstName1}.{$lastName1}@example.com']"));
434 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Main')]"));
435 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[text() ='{$firstName1}.{$lastName1}@example.com']"));
436 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Billing')]"));
437 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543120')]"));
438 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
439 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
440 }
441
442 function testBatchMerge(){
443 $this->webtestLogin();
444
445 // add contact1 and its duplicate
446 //first name
447 $firstName = "Kerry".substr(sha1(rand()), 0, 7);
448 //last name
449 $lastName = "King".substr(sha1(rand()), 0, 7);
450 $this->_createContacts($firstName,$lastName);
451
452 //add contact2 and its duplicate
453 //These are the contacts with conflicts in communication preference.these contacts will be skipped during merge.
454 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
455
456 //fill in first name
457 $firstName1 = "Kurt".substr(sha1(rand()), 0, 7);
458 $this->type('first_name', $firstName1);
459
460 //fill in last name
461 $lastName1 = "Cobain".substr(sha1(rand()), 0, 7);
462 $this->type('last_name', $lastName1);
463
464 //fill in email id
465 $this->type('email_1_email', "{$firstName1}.{$lastName1}@example.com");
466
467 //fill in billing email id
468 $this->click('addEmail');
469 $this->waitForElementPresent('email_2_email');
470 $this->type('email_2_email', "$firstName1.$lastName1@billing.com");
471 $this->select('email_2_location_type_id', 'value=5');
472
473 //fill in home phone no
474 $this->type('phone_1_phone', "9876543210");
475
476 //fill in billing phone id
477 $this->click('addPhone');
478 $this->waitForElementPresent('phone_2_phone');
479 $this->type('phone_2_phone', "9876543120");
480 $this->select('phone_2_location_type_id', 'value=5');
481
482 //select communication preference
483 $this->check("privacy[do_not_phone]");
484
485 //Clicking save.
486 $this->click("_qf_Contact_upload_view");
487 $this->waitForPageToLoad($this->getTimeoutMsec());
488 $this->waitForText('crm-notification-container', "Contact Saved");
489
490 //duplicate of contact2.
491 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
492
493 //fill in first name
494 $this->type("first_name", $firstName1);
495
496 //fill in last name
497 $this->type("last_name", $lastName1);
498
499 //fill in email
500 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
501
502 //fill in home phone no
503 $this->type('phone_1_phone', "9876543211");
504
505 //select communication preference
506 $this->check("preferred_communication_method[1]");
507
508 // Clicking save.
509 $this->click("_qf_Contact_refresh_dedupe");
510 $this->waitForPageToLoad($this->getTimeoutMsec());
511
512 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
513 $this->click("_qf_Contact_upload_duplicate");
514 $this->waitForPageToLoad($this->getTimeoutMsec());
515 $this->waitForText('crm-notification-container', "Contact Saved");
516
517 // add contact3 and its duplicate
518 //fill in first name
519 $firstName2 = "David".substr(sha1(rand()), 0, 7);
520 //fill in last name
521 $lastName2 = "Gilmour".substr(sha1(rand()), 0, 7);
522 $this->_createContacts($firstName2,$lastName2);
523
524 // add contact4 and its duplicate
525 //fill in first name
526 $firstName3 = "Dave".substr(sha1(rand()), 0, 7);
527 //fill in last name
528 $lastName3 = "Mustaine".substr(sha1(rand()), 0, 7);
529 $this->_createContacts($firstName3,$lastName3);
530
531 // Find and Merge Contacts with Supervised Rule
532 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew", "css=#DedupeFind table.pagerDisplay tbody tr");
533
534 $this->select("name=option51_length", "value=100");
535 $totalContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
536 $this->click("xpath=//form[@id='DedupeFind']//a/span[text()='Batch Merge Duplicates']");
537
538 // Check confirmation alert.
539 $this->assertTrue(
540 (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./",
541 $this->getConfirmation()
542 ));
543 $this->chooseOkOnNextConfirmation();
544 $this->waitForPageToLoad($this->getTimeoutMsec());
545 $this->waitForElementPresent('civicrm-footer');
546 $this->waitForText('crm-notification-container', "safe mode");
547
548 // If we are still on the dedupe table page, count unmerged contacts
549 if ($this->isElementPresent("//table[@class='pagerDisplay']")) {
550 // Wait for datatable to load
551 $this->waitForElementPresent("//table[@class='pagerDisplay']/tbody/tr");
552 $unMergedContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
553 }
554 else {
555 $unMergedContacts = 0;
556 }
557
558 $mergedContacts = $totalContacts - $unMergedContacts;
559
560 //check the existence of merged contacts
561 $contactEmails = array(
562 1 => "{$firstName}.{$lastName}@example.com",
563 2 => "{$firstName2}.{$lastName2}@example.com",
564 3 => "{$firstName3}.{$lastName3}@example.com"
565 );
566
567 foreach($contactEmails as $key => $value) {
568 $this->click('sort_name_navigation');
569 $this->type('css=input#sort_name_navigation', $value);
570 $this->typeKeys('css=input#sort_name_navigation', $value);
571 // Wait for result list.
572 $this->waitForElementPresent("css=ul.ui-autocomplete li.ui-menu-item");
573
574 // Visit contact summary page.
575 $this->clickLink("css=ul.ui-autocomplete li.ui-menu-item", 'civicrm-footer');
576 }
577 }
578
579 /**
580 * Helper FN
581 */
582 function _createContacts($firstName = NULL, $lastName = NULL, $organizationName = NULL, $contactType = 'Individual') {
583 if ($contactType == 'Individual') {
584 // add contact
585 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
586 //fill in first name
587 $this->type('first_name', $firstName);
588
589 //fill in last name
590 $this->type('last_name', $lastName);
591
592 //fill in email id
593 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
594
595 //fill in billing email id
596 $this->click('addEmail');
597 $this->waitForElementPresent('email_2_email');
598 $this->type('email_2_email', "$firstName.$lastName@billing.com");
599 $this->select('email_2_location_type_id', 'value=5');
600
601 // Clicking save.
602 $this->click("_qf_Contact_upload_view");
603 $this->waitForPageToLoad($this->getTimeoutMsec());
604 $this->waitForText('crm-notification-container', "Contact Saved");
605
606 //duplicate of above contact.
607 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
608
609 //fill in first name
610 $this->type("first_name", $firstName);
611
612 //fill in last name
613 $this->type("last_name", $lastName);
614
615 //fill in email
616 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
617
618 // Clicking save.
619 $this->click("_qf_Contact_refresh_dedupe");
620 $this->waitForPageToLoad($this->getTimeoutMsec());
621
622 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
623 $this->click("_qf_Contact_upload_duplicate");
624 $this->waitForPageToLoad($this->getTimeoutMsec());
625 $this->waitForText('crm-notification-container', "Contact Saved");
626 }
627 elseif ($contactType == 'Organization') {
628 // add contact
629 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
630 //fill in Organization name
631 $this->type('organization_name', $organizationName);
632
633 //fill in email id
634 $this->type('email_1_email', "{$organizationName}@org.com");
635 // Clicking save.
636 $this->click("_qf_Contact_upload_view-bottom");
637 $this->waitForPageToLoad($this->getTimeoutMsec());
638 $this->waitForText('crm-notification-container', "Contact Saved");
639 $mainId = explode("CiviCRM ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
640 $mainId = trim($mainId[1]);
641
642 //Duplicate of above contact.
643 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
644
645 //fill in Organization name
646 $this->type('organization_name', $organizationName);
647
648 //fill in email id
649 $this->type('email_1_email', "{$organizationName}@org.com");
650
651 // Clicking save.
652 $this->click("_qf_Contact_upload_view-bottom");
653 $this->waitForPageToLoad($this->getTimeoutMsec());
654
655 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
656 $this->click("_qf_Contact_upload_duplicate");
657 $this->waitForPageToLoad($this->getTimeoutMsec());
658 $this->waitForText('crm-notification-container', "Contact Saved");
659 $duplicateId = explode("CiviCRM ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
660 $duplicateId = trim($duplicateId[1]);
661
662 return array(
663 'mainId' => $mainId,
664 'duplicateId' => $duplicateId
665 );
666 }
667 }
668
669 /**
670 * Helper FN
671 * to create new membershiptype
672 */
673 function addMembershipType($membershipOrganization) {
674 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
675 $this->click("link=Add Membership Type");
676 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
677
678 $this->type('name', "Membership Type $membershipOrganization");
679 $this->select2('member_of_contact_id', $membershipOrganization);
680
681 $this->type('minimum_fee', '1');
682 $this->select( 'financial_type_id', 'value=2' );
683 $this->type('duration_interval', 1);
684 $this->select('duration_unit', "label=year");
685
686 $this->select('period_type', "label=Fixed");
687 $this->waitForElementPresent('fixed_period_rollover_day[d]');
688
689 // fixed period start set to April 1
690 $this->select('fixed_period_start_day[M]', 'value=4');
691 // rollover date set to Jan 31
692 $this->select('fixed_period_rollover_day[M]', 'value=1');
693
694 // Employer of relationship
695 $this->select('relationship_type_id', 'value=5_b_a');
696 $this->click('_qf_MembershipType_upload-bottom');
697 $this->waitForElementPresent('link=Add Membership Type');
698 $this->waitForText("crm-notification-container", "The membership type 'Membership Type $membershipOrganization' has been saved.");
699 }
700
701 /**
702 * Test for CRM-12695 fix
703 */
704 function testMergeOrganizations() {
705 $this->webtestLogin();
706
707 // build organisation name
708 $orgnaizationName = 'org_'.substr(sha1(rand()), 0, 7);
709
710 $contactIds = array();
711 // create organization and its duplicate
712 $contactIds = $this->_createContacts(NULL, NULL, $orgnaizationName, 'Organization');
713
714 /*** Add Membership Type - start ***/
715 $this->addMembershipType($orgnaizationName);
716 /*** Add Membership Type - end ***/
717
718 //create a New Individual to be related to main organization
719 $firstName = substr(sha1(rand()), 0, 7);
720 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
721 $sortName = "Anderson, $firstName";
722
723 // go to main organization contact to add membership
724 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['mainId']}");
725 // click through to the membership view screen
726 $this->click("css=li#tab_member a");
727
728 $this->waitForElementPresent("link=Add Membership");
729 $this->click("link=Add Membership");
730
731 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
732
733 // fill in Membership Organization and Type
734 $this->select("membership_type_id[0]", "label={$orgnaizationName}");
735 $this->waitForElementPresent("membership_type_id[1]");
736 // Wait for membership type select to reload
737 $this->waitForTextPresent("Membership Type $orgnaizationName");
738 $this->select("membership_type_id[1]", "label=Membership Type $orgnaizationName");
739
740 $sourceText = "Membership-Organization Duplicate Merge Webtest";
741 // fill in Source
742 $this->type("source", $sourceText);
743
744 // Let Join Date stay default
745
746 // fill in Start Date
747 $this->webtestFillDate('start_date');
748
749 // Clicking save.
750 $this->click("_qf_Membership_upload");
751 $this->waitForElementPresent('crm-notification-container');
752 // page was loaded
753 $this->waitForTextPresent($sourceText);
754 // Is status message correct?
755 $this->waitForText('crm-notification-container', "membership for $orgnaizationName has been added.");
756
757 // add relationship "Employer of"
758 // click through to the relationship view screen
759 $this->click("css=li#tab_rel a");
760
761 // wait for add Relationship link
762 $this->waitForElementPresent('link=Add Relationship');
763 $this->click('link=Add Relationship');
764
765 //choose the created relationship type
766 $this->waitForElementPresent("relationship_type_id");
767 $this->select('relationship_type_id', "value=5_b_a");
768
769 //fill in the individual
770 $this->select2('related_contact_id', $sortName, TRUE, FALSE);
771
772 $this->waitForElementPresent("_qf_Relationship_upload");
773
774 //fill in the relationship start date
775 //$this->webtestFillDate('start_date', '-2 year');
776 //$this->webtestFillDate('end_date', '+1 year');
777
778 $description = "Well here is some description !!!!";
779 $this->type("description", $description);
780
781 //save the relationship
782 $this->click("_qf_Relationship_upload");
783 $this->isTextPresent("Current Relationships");
784
785 //check the status message
786 $this->waitForText('crm-notification-container', "Relationship created.");
787
788 $this->waitForElementPresent("xpath=//table[@id='crm-contact-relationship-selector-current']/tbody//tr/td[9]/span/a[text()='View']");
789 $this->waitForElementPresent("xpath=//a[text()='$sortName']");
790 $this->click("xpath=//a[text()='$sortName']");
791 $this->waitForPageToLoad($this->getTimeoutMsec());
792
793 // Check if Membership for the individual is created
794 $this->waitForElementPresent("xpath=//li[@id='tab_member']/a/em");
795 $this->verifyText("xpath=//li[@id='tab_member']/a/em", 1);
796
797 //create a New Individual to be related to duplicate organization
798 $firstNameOther = substr(sha1(rand()), 0, 7);
799 $this->webtestAddContact($firstNameOther, "Harmison", "$firstNameOther@harmison.name");
800 $sortNameOther = "Harmison, $firstNameOther";
801
802 // go to main organization contact to add membership
803 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['duplicateId']}");
804
805 // add relationship "Employer of"
806 // click through to the relationship view screen
807 $this->click("css=li#tab_rel a");
808
809 // wait for add Relationship link
810 $this->waitForElementPresent('link=Add Relationship');
811 $this->click('link=Add Relationship');
812
813 //choose the created relationship type
814 $this->waitForElementPresent("relationship_type_id");
815 $this->select('relationship_type_id', "value=5_b_a");
816
817 //fill in the individual
818 $this->select2('related_contact_id', $sortNameOther, TRUE, FALSE);
819
820 $this->waitForElementPresent("_qf_Relationship_upload");
821
822 //fill in the relationship start date
823 $this->webtestFillDate('start_date', '-2 year');
824 $this->webtestFillDate('end_date', '+1 year');
825
826 $description = "Well here is some description !!!!";
827 $this->type("description", $description);
828
829 //save the relationship
830 //$this->click("_qf_Relationship_upload");
831 $this->click("_qf_Relationship_upload");
832 $this->isTextPresent("Current Relationships");
833
834 //check the status message
835 $this->isTextPresent("Relationship created.");
836
837 $this->waitForElementPresent("xpath=//table[@id='crm-contact-relationship-selector-current']/tbody//tr/td[9]/span/a[text()='View']");
838
839 // go directly to contact merge page.
840 $this->openCiviPage("contact/merge", "reset=1&cid={$contactIds['mainId']}&oid={$contactIds['duplicateId']}&action=update&rgid=2");
841
842 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
843 $this->click('_qf_Merge_next-bottom');
844 $this->waitForPageToLoad($this->getTimeoutMsec());
845
846 // click through to the relationship view screen
847 $this->click("css=li#tab_rel a");
848
849 // wait for add Relationship link
850 $this->waitForElementPresent("xpath=//a[text()='$sortName']");
851 // go to duplicate organization's related contact
852 // to check if membership is added to that contact
853 $this->click("xpath=//a[text()='$sortName']");
854 $this->waitForPageToLoad($this->getTimeoutMsec());
855
856 // Check if Membership for the individual is created
857 $this->waitForElementPresent("xpath=//li[@id='tab_member']/a/em");
858 $this->verifyText("xpath=//li[@id='tab_member']/a/em", 1);
859 }
860 }
861