Merge pull request #9783 from mattwire/back_to_single_lang
[civicrm-core.git] / tests / phpunit / WebTest / Contact / MergeContactsTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
15a4309a 6 | Copyright CiviCRM LLC (c) 2004-2017 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Contact_MergeContactsTest
31 */
6a488035
TO
32class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
00be9182 38 public function testIndividualAdd() {
a49e5dea 39 $this->markTestSkipped('Skipping for now as it works fine locally.');
6a488035
TO
40 $this->webtestLogin();
41
071a6d2e 42 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
6a488035
TO
43
44 // add contact1
45 //select prefix
46 $prefix = 'Mr.';
47 $this->click("prefix_id");
48 $this->select("prefix_id", "label=$prefix");
49
50 //fill in first name
51 $firstName = substr(sha1(rand()), 0, 7);
52 $this->type('first_name', $firstName);
53
54 //fill in last name
55 $lastName = substr(sha1(rand()), 0, 7);
56 $this->type('last_name', $lastName);
57
58 //fill in email id
59 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
60
61 //fill in billing email id
62 $this->click('addEmail');
63 $this->waitForElementPresent('email_2_email');
64 $this->type('email_2_email', "$firstName.$lastName@billing.com");
65 $this->select('email_2_location_type_id', 'value=5');
66
67 // Clicking save.
68 $this->click("_qf_Contact_upload_view");
69 $this->waitForPageToLoad($this->getTimeoutMsec());
6c5f7368 70 $this->waitForText('crm-notification-container', "Contact Saved");
6a488035
TO
71
72 // Add Contact to a group
73 $group = 'Newsletter Subscribers';
74 $this->click('css=li#tab_group a');
75 $this->waitForElementPresent('_qf_GroupContact_next');
76 $this->select('group_id', "label=$group");
77 $this->click('_qf_GroupContact_next');
0cff9fd6 78 $this->waitForElementPresent('link=Delete');
6c5f7368 79 $this->waitForText('crm-notification-container', "Added to Group");
6a488035
TO
80
81 // Add Tags to the contact
82 $tag = 'Government Entity';
83 $this->click("css=li#tab_tag a");
84 $this->waitForElementPresent('tagtree');
bf333c47 85 $this->click("xpath=//div[@id='tagtree']/ul//li/input/../span/label[text()='$tag']");
6a488035
TO
86 $this->click("css=#tab_summary a");
87 $this->assertElementContainsText('css=.crm-summary-block #tags', $tag);
88
89 // Add an activity
90 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
91 $this->addActivity($firstName, $lastName, $subject);
92
93 // contact2: duplicate of contact1.
071a6d2e 94 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
6a488035
TO
95
96 //fill in first name
97 $this->type("first_name", $firstName);
98
99 //fill in last name
100 $this->type("last_name", $lastName);
101
102 //fill in email
103 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
104
105 // Clicking save.
106 $this->click("_qf_Contact_refresh_dedupe");
107 $this->waitForPageToLoad($this->getTimeoutMsec());
108
baaf85ee 109 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
6a488035
TO
110 $this->click("_qf_Contact_upload_duplicate");
111 $this->waitForPageToLoad($this->getTimeoutMsec());
6c5f7368 112 $this->waitForText('crm-notification-container', "Contact Saved");
6a488035
TO
113
114 // Add second pair of dupes so we can test Merge and Goto Next Pair
115 $fname2 = 'Janet';
116 $lname2 = 'Rogers' . substr(sha1(rand()), 0, 7);
117 $email2 = "{$fname2}.{$lname2}@example.org";
118 $this->webtestAddContact($fname2, $lname2, $email2);
119
120 // Can not use helper for 2nd contact since it is a dupe
071a6d2e 121 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
6a488035
TO
122 $this->type("first_name", $fname2);
123 $this->type("last_name", $lname2);
124 $this->type("email_1_email", $email2);
125 $this->click("_qf_Contact_refresh_dedupe");
126 $this->waitForPageToLoad($this->getTimeoutMsec());
baaf85ee 127 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
6a488035
TO
128 $this->click("_qf_Contact_upload_duplicate");
129 $this->waitForPageToLoad($this->getTimeoutMsec());
6c5f7368 130 $this->waitForText('crm-notification-container', "Contact Saved");
6a488035
TO
131
132 // Find and Merge Contacts with Supervised Rule
071a6d2e 133 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
6a488035
TO
134
135 // reload the page
071a6d2e 136 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=update");
6a488035
TO
137
138 // Select the contacts to be merged
f952d4f0
WA
139 $this->waitForElementPresent('dupePairs_length');
140 $this->select("name=dupePairs_length", "value=100");
141 $this->waitForElementPresent("xpath=//table[@id='dupePairs']/tbody//tr/td[5]/a[text()='$firstName $lastName']/../../td[8]/a[text()='merge']");
142 $this->click("xpath=//table[@id='dupePairs']/tbody//tr/td[5]/a[text()='$firstName $lastName']/../../td[8]/a[text()='merge']");
6a488035
TO
143 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
144
225a8648 145 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a", '_qf_Merge_cancel-bottom');
6a488035
TO
146
147 // Move the activities, groups, etc to the main contact and merge using Merge and Goto Next Pair
148 $this->check('move_prefix_id');
149 $this->check('move_location_email_2');
150 $this->check('move_rel_table_activities');
151 $this->check('move_rel_table_groups');
152 $this->check('move_rel_table_tags');
225a8648 153 $this->clickLink('_qf_Merge_next-bottom', '_qf_Merge_cancel-bottom');
6a488035
TO
154 $this->assertTrue($this->isTextPresent('Contacts Merged'), "Contacts Merged text was not found after merge.");
155
156 // Check that we are viewing the next Merge Pair (our 2nd contact, since the merge list is ordered by contact_id)
157 $this->assertTrue($this->isTextPresent("{$fname2} {$lname2}"), "Redirect for Goto Next Pair after merge did not work.");
158
159 // Ensure that the duplicate contact has been deleted
42daf119 160 $this->openCiviPage("contact/search/advanced", "reset=1", '_qf_Advanced_refresh');
6a488035 161 $this->type('sort_name', $firstName);
bf333c47 162 $this->click('deleted_contacts');
6a488035
TO
163 $this->click('_qf_Advanced_refresh');
164 $this->waitForPageToLoad($this->getTimeoutMsec());
165 $this->assertTrue($this->isTextPresent('1 Contact'), "Deletion of duplicate contact during merge was not successful. Dupe contact not found when searching trash.");
166
167 // Search for the main contact
42daf119 168 $this->openCiviPage("contact/search/advanced", "reset=1", '_qf_Advanced_refresh');
6a488035
TO
169 $this->type('sort_name', $firstName);
170 $this->click('_qf_Advanced_refresh');
171 $this->waitForElementPresent("xpath=//form[@id='Advanced']/div[3]/div/div[2]/table/tbody/tr");
172
173 $this->click("//form[@id='Advanced']/div[3]/div/div[2]/table/tbody/tr/td[11]/span[1]/a[text()='View']");
174 $this->waitForPageToLoad($this->getTimeoutMsec());
175
176 // Verify prefix merged
177 // $this->verifyText( "xpath=//div[@class='left-corner']/h2", preg_quote( "$prefix $firstName $lastName" ) );
178
179 // Verify billing email merged
180 $this->isElementPresent("xpath=//div[@class='contact_details']/div[1][@class='contact_panel']/div[1][@class='contactCardLeft']/table/tbody/tr[4]/td[2]/span/a[text()='$firstName.$lastName@billing.com']");
181
182 // Verify activity merged
183 $this->click("css=li#tab_activity a");
dd055b5e
WA
184 $this->waitForAjaxContent();
185 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr");
186 $this->verifyText("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[5]/a", preg_quote("$lastName, $firstName"));
6a488035
TO
187
188 // Verify group merged
189 $this->click("css=li#tab_group a");
e9322446 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",
6a488035
TO
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
00be9182 202 public function testMergeContactSubType() {
18ba3f33
RK
203 $this->webtestLogin();
204 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
205 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
206 //fill in first name
92fcb95f 207 $firstName = "Anderson" . substr(sha1(rand()), 0, 4);
18ba3f33 208 $this->type('first_name', $firstName);
48b420d7 209
18ba3f33
RK
210 //fill in last name
211 $lastName = substr(sha1(rand()), 0, 4);
212 $this->type('last_name', $lastName);
213
214 //fill in email id
215 $this->waitForElementPresent('email_1_email');
216 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
217 $this->waitForElementPresent('contact_sub_type');
0175cea5 218 $this->select('contact_sub_type', "Parent");
18ba3f33
RK
219
220 // Clicking save.
221 $this->click("_qf_Contact_upload_view");
222 $this->waitForPageToLoad($this->getTimeoutMsec());
223 $this->waitForText('crm-notification-container', "Contact Saved");
224
225 // contact2: contact with same email id as contact 1.
226 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
227 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
228
92fcb95f 229 $fName = "John" . substr(sha1(rand()), 0, 4);
18ba3f33
RK
230 $this->type('first_name', $fName);
231 $lName = substr(sha1(rand()), 0, 4);
232 $this->type('last_name', $lName);
233 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
234 $this->waitForElementPresent('contact_sub_type');
0175cea5 235 $this->multiselect2('contact_sub_type', array("Student", "Staff"));
18ba3f33
RK
236 $this->click("_qf_Contact_upload_view");
237 $this->waitForText('crm-notification-container', "Contact Saved");
238 $this->openCiviPage("contact/deduperules", "reset=1");
239 $this->click("xpath=//*[@id='option12']/tbody/tr[3]/td[3]/span/a[1][contains(text(),'Use Rule')]");
240 $this->waitForElementPresent('_qf_DedupeFind_submit-bottom');
241 $this->click("_qf_DedupeFind_next-bottom");
242
dd055b5e 243 $this->waitForElementPresent("xpath=//table[@id='dupePairs']/tbody//tr/td[3]/a[text()='{$firstName} {$lastName}']/../../td[8]/a[2][text()='merge']");
f952d4f0
WA
244 $this->waitForElementPresent("xpath=//form[@id='DedupeFind']//a/span[contains(text(),'Done')]");
245 $this->isElementPresent("xpath=//table[@id='dupePairs']/tbody//tr//td/a[text()='$firstName $lastName']/../../td[5]/a[text()='{$fName} {$lName}']/../../td[8]/a[text()='merge']");
dd055b5e 246 $this->click("xpath=//table[@id='dupePairs']/tbody//tr/td[3]/a[text()='{$firstName} {$lastName}']/../../td[8]/a[2][text()='merge']");
18ba3f33
RK
247 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
248 $this->click('toggleSelect');
249 $this->click('_qf_Merge_next-bottom');
fdb227e0 250 $this->waitForPageToLoad($this->getTimeoutMsec());
0175cea5 251 $this->assertTrue($this->isTextPresent("Staff, Student"));
18ba3f33 252 }
92915c55 253
4cbe18b8 254 /**
100fef9d
CW
255 * @param string $firstName
256 * @param string $lastName
4cbe18b8
EM
257 * @param $subject
258 */
00be9182 259 public function addActivity($firstName, $lastName, $subject) {
6a488035
TO
260 $withContact = substr(sha1(rand()), 0, 7);
261 $this->webtestAddContact($withContact, "Anderson", $withContact . "@anderson.name");
262
263 $this->click("css=li#tab_activity a");
264
265 // waiting for the activity dropdown to show up
266 $this->waitForElementPresent("other_activity");
267
268 // Select the activity type from the activity dropdown
269 $this->select("other_activity", "label=Meeting");
270
271 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
272 // button at the end of this page to show up, to make sure it's fully loaded.
273 $this->waitForElementPresent("_qf_Activity_upload");
274
6a488035
TO
275 // ...and verifying if the page contains properly formatted display name for chosen contact.
276 $this->assertTrue($this->isTextPresent("Anderson, " . $withContact), "Contact not found in line " . __LINE__);
277
278 // Now we're filling the "Assigned To" field.
279 // Typing contact's name into the field (using typeKeys(), not type()!)...
6c6e6187 280 $this->select2("assignee_contact_id", $firstName, TRUE, FALSE);
6a488035
TO
281
282 // ...and verifying if the page contains properly formatted display name for chosen contact.
283 $this->assertTrue($this->isTextPresent("$lastName, " . $firstName), "Contact not found in line " . __LINE__);
284
285 // Since we're here, let's check if screen help is being displayed properly
0cff9fd6 286 $this->assertTrue($this->isTextPresent("A copy of this activity will be emailed to each Assignee."));
6a488035
TO
287
288 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
289 // For simple input fields we can use field id as selector
290 $this->type("subject", $subject);
291 $this->type("location", "Some location needs to be put in this field.");
292
293 // Choosing the Date.
294 // Please note that we don't want to put in fixed date, since
295 // we want this test to work in the future and not fail because
296 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
297 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
298
299 // Setting duration.
300 $this->type("duration", "30");
301
302 // Putting in details.
303 $this->type("details", "Really brief details information.");
304
305 // Making sure that status is set to Scheduled (using value, not label).
306 $this->select("status_id", "value=1");
307
308 // Setting priority.
309 $this->select("priority_id", "value=1");
310
311 // Clicking save.
312 $this->click("_qf_Activity_upload");
0cff9fd6 313 $this->waitForElementPresent("crm-notification-container");
6a488035
TO
314
315 // Is status message correct?
baaf85ee 316 $this->waitForText('crm-notification-container', "Activity '$subject' has been saved.", "Status message didn't show up after saving!");
6a488035
TO
317 }
318
00be9182 319 public function testMergeTest() {
6a488035
TO
320 $this->webtestLogin();
321
071a6d2e 322 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
6a488035
TO
323
324 // add contact1
325 //fill in first name
326 $firstName = substr(sha1(rand()), 0, 7);
327 $this->type('first_name', $firstName);
328
329 //fill in last name
330 $lastName = substr(sha1(rand()), 0, 7);
331 $this->type('last_name', $lastName);
332
333 //fill in email id
334 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
335
336 //fill in billing email id
337 $this->click('addEmail');
338 $this->waitForElementPresent('email_2_email');
339 $this->type('email_2_email', "$firstName.$lastName@billing.com");
340 $this->select('email_2_location_type_id', 'value=5');
341
342 //fill in home phone no
343 $this->type('phone_1_phone', "9876543210");
344
345 //fill in billing phone id
346 $this->click('addPhone');
347 $this->waitForElementPresent('phone_2_phone');
348 $this->type('phone_2_phone', "9876543120");
349 $this->select('phone_2_location_type_id', 'value=5');
350
351 // Clicking save.
352 $this->click("_qf_Contact_upload_view");
353 $this->waitForPageToLoad($this->getTimeoutMsec());
6c5f7368 354 $this->waitForText('crm-notification-container', "Contact Saved");
6a488035
TO
355
356 // contact2: duplicate of contact1.
071a6d2e 357 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
6a488035
TO
358
359 //fill in first name
360 $this->type("first_name", $firstName);
361
362 //fill in last name
363 $this->type("last_name", $lastName);
364
365 //fill in email
366 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
367
368 //fill in home phone no
369 $this->type('phone_1_phone', "9876543211");
370
371 // Clicking save.
372 $this->click("_qf_Contact_refresh_dedupe");
373 $this->waitForPageToLoad($this->getTimeoutMsec());
374
baaf85ee 375 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
6a488035
TO
376 $this->click("_qf_Contact_upload_duplicate");
377 $this->waitForPageToLoad($this->getTimeoutMsec());
6c5f7368 378 $this->waitForText('crm-notification-container', "Contact Saved");
6a488035
TO
379
380 // Find and Merge Contacts with Supervised Rule
071a6d2e 381 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
6a488035
TO
382
383 // Select the contacts to be merged
f952d4f0 384 $this->waitForElementPresent('dupePairs_length');
6a488035 385 $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']");
9fdcdf6f 386 $this->click("xpath=//a[text()='$firstName $lastName']/../../td[8]/a[text()='merge']");
6a488035 387 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
e2414672 388 $this->clickLink("css=div.crm-contact-merge-form-block div.action-link a");
389
390 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(overwrite)']");
e9322446 391 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[5]/td[4]/span[text()='(add)']");
6a488035
TO
392 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
393
394 $this->check("move_location_email_1");
395 $this->check("location[email][1][operation]");
396 $this->check("move_location_email_2");
397 $this->check("move_location_phone_1");
398 $this->check("location[phone][1][operation]");
399 $this->check("move_location_phone_2");
400 $this->click("_qf_Merge_next-bottom");
401 $this->waitForPageToLoad($this->getTimeoutMsec());
402
403 $this->assertTrue($this->isTextPresent('Contacts Merged'));
404 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
bf333c47 405 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]"));
6a488035 406 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
bf333c47 407 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]"));
6a488035 408 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
bf333c47 409 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[2]/a[contains(text(), '$firstName.$lastName@billing.com')]"));
6a488035
TO
410 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
411 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543211')]"));
412 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
413 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
414 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]"));
415 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[2][contains(text(), '9876543120')]"));
416
417 //Merge with the feature of (add)
071a6d2e 418 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
6a488035
TO
419
420 // add contact1
421 //fill in first name
422 $firstName1 = substr(sha1(rand()), 0, 7);
423 $this->type('first_name', $firstName1);
424
425 //fill in last name
426 $lastName1 = substr(sha1(rand()), 0, 7);
427 $this->type('last_name', $lastName1);
428
429 //fill in billing email id
430 $this->waitForElementPresent('email_1_email');
431 $this->type('email_1_email', "$firstName1.$lastName1@example.com");
432 $this->select('email_1_location_type_id', 'value=5');
433
434 $this->click('addEmail');
435 $this->waitForElementPresent('email_2_email');
436 $this->type('email_2_email', "$firstName.$lastName@home.com");
437 $this->select('email_2_location_type_id', 'value=1');
438
439 //fill in home phone no
440 $this->type('phone_1_phone', "9876543210");
441
442 // Clicking save.
443 $this->click("_qf_Contact_upload_view");
444 $this->waitForPageToLoad($this->getTimeoutMsec());
6c5f7368 445 $this->waitForText('crm-notification-container', "Contact Saved");
6a488035
TO
446
447 // contact2: duplicate of contact1.
071a6d2e 448 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
6a488035
TO
449
450 //fill in first name
451 $this->type("first_name", $firstName1);
452
453 //fill in last name
454 $this->type("last_name", $lastName1);
455
456 //fill in email
457 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
458
459 //fill in billing phone no
460 $this->type('phone_1_phone', "9876543120");
461 $this->select('phone_1_location_type_id', 'value=5');
462
463 // Clicking save.
464 $this->click("_qf_Contact_refresh_dedupe");
465 $this->waitForPageToLoad($this->getTimeoutMsec());
baaf85ee 466 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
6a488035
TO
467 $this->click("_qf_Contact_upload_duplicate");
468 $this->waitForPageToLoad($this->getTimeoutMsec());
6c5f7368 469 $this->waitForText('crm-notification-container', "Contact Saved");
6a488035
TO
470
471 // Find and Merge Contacts with Supervised Rule
071a6d2e 472 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew");
6a488035
TO
473
474 // Select the contacts to be merged
f952d4f0 475 $this->waitForElementPresent('dupePairs_length');
2f231370
SB
476 $this->waitForElementPresent("xpath=//a[text()='$firstName1 $lastName1']");
477 $this->click("xpath=//a[text()='$firstName1 $lastName1']/../../td[8]/a[text()='merge']");
6a488035 478 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
e9322446 479 $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)']");
480 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']");
481 $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']");
6a488035
TO
482 $this->select('location_email_1_locTypeId', 'value=3');
483 $this->select('location_phone_1_locTypeId', 'value=1');
484 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']"));
485 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']"));
486 $this->assertTrue($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']"));
487 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
488
489 $this->check("move_location_email_1");
490 $this->check("move_location_phone_1");
491 $this->click("_qf_Merge_next-bottom");
492 $this->waitForPageToLoad($this->getTimeoutMsec());
493
494 $this->assertTrue($this->isTextPresent('Contacts Merged'));
495 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
bf333c47 496 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[contains(text(), '{$firstName1}.{$lastName1}@example.com')]"));
6a488035 497 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Main')]"));
bf333c47 498 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[contains(text(), '{$firstName1}.{$lastName1}@example.com')]"));
6a488035
TO
499 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Billing')]"));
500 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543120')]"));
501 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]"));
502 $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]"));
503 }
504
9b873358 505 public function testBatchMerge() {
6a488035
TO
506 $this->webtestLogin();
507
508 // add contact1 and its duplicate
509 //first name
92fcb95f 510 $firstName = "Kerry" . substr(sha1(rand()), 0, 7);
6a488035 511 //last name
92fcb95f 512 $lastName = "King" . substr(sha1(rand()), 0, 7);
6c6e6187 513 $this->_createContacts($firstName, $lastName);
6a488035
TO
514
515 //add contact2 and its duplicate
516 //These are the contacts with conflicts in communication preference.these contacts will be skipped during merge.
071a6d2e 517 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
6a488035
TO
518
519 //fill in first name
92fcb95f 520 $firstName1 = "Kurt" . substr(sha1(rand()), 0, 7);
6a488035
TO
521 $this->type('first_name', $firstName1);
522
523 //fill in last name
92fcb95f 524 $lastName1 = "Cobain" . substr(sha1(rand()), 0, 7);
6a488035
TO
525 $this->type('last_name', $lastName1);
526
527 //fill in email id
528 $this->type('email_1_email', "{$firstName1}.{$lastName1}@example.com");
529
530 //fill in billing email id
531 $this->click('addEmail');
532 $this->waitForElementPresent('email_2_email');
533 $this->type('email_2_email', "$firstName1.$lastName1@billing.com");
534 $this->select('email_2_location_type_id', 'value=5');
535
536 //fill in home phone no
537 $this->type('phone_1_phone', "9876543210");
538
539 //fill in billing phone id
540 $this->click('addPhone');
541 $this->waitForElementPresent('phone_2_phone');
542 $this->type('phone_2_phone', "9876543120");
543 $this->select('phone_2_location_type_id', 'value=5');
544
545 //select communication preference
546 $this->check("privacy[do_not_phone]");
547
548 //Clicking save.
549 $this->click("_qf_Contact_upload_view");
550 $this->waitForPageToLoad($this->getTimeoutMsec());
6c5f7368 551 $this->waitForText('crm-notification-container', "Contact Saved");
6a488035
TO
552
553 //duplicate of contact2.
071a6d2e 554 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
6a488035
TO
555
556 //fill in first name
557 $this->type("first_name", $firstName1);
558
559 //fill in last name
560 $this->type("last_name", $lastName1);
561
562 //fill in email
563 $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com");
564
565 //fill in home phone no
566 $this->type('phone_1_phone', "9876543211");
567
568 //select communication preference
569 $this->check("preferred_communication_method[1]");
570
571 // Clicking save.
572 $this->click("_qf_Contact_refresh_dedupe");
573 $this->waitForPageToLoad($this->getTimeoutMsec());
574
baaf85ee 575 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
6a488035
TO
576 $this->click("_qf_Contact_upload_duplicate");
577 $this->waitForPageToLoad($this->getTimeoutMsec());
6c5f7368 578 $this->waitForText('crm-notification-container', "Contact Saved");
6a488035
TO
579
580 // add contact3 and its duplicate
581 //fill in first name
92fcb95f 582 $firstName2 = "David" . substr(sha1(rand()), 0, 7);
6a488035 583 //fill in last name
92fcb95f 584 $lastName2 = "Gilmour" . substr(sha1(rand()), 0, 7);
6c6e6187 585 $this->_createContacts($firstName2, $lastName2);
6a488035
TO
586
587 // add contact4 and its duplicate
588 //fill in first name
92fcb95f 589 $firstName3 = "Dave" . substr(sha1(rand()), 0, 7);
6a488035 590 //fill in last name
92fcb95f 591 $lastName3 = "Mustaine" . substr(sha1(rand()), 0, 7);
6c6e6187 592 $this->_createContacts($firstName3, $lastName3);
6a488035
TO
593
594 // Find and Merge Contacts with Supervised Rule
dd055b5e 595 $this->openCiviPage("contact/dedupefind", "reset=1&rgid=1&action=renew", "dupePairs");
6a488035 596
f952d4f0 597 $this->waitForElementPresent('dupePairs_length');
a6f95222 598 $this->select("name=dupePairs_length", "value=100");
dd055b5e
WA
599 $totalContacts = $this->getXpathCount("//table[@id='dupePairs']/tbody/tr");
600 $this->click("//form[@id='DedupeFind']//a/span[contains(text(),' Batch Merge All Duplicates')]");
6a488035
TO
601
602 // Check confirmation alert.
603 $this->assertTrue(
6c6e6187 604 (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./",
6a488035 605 $this->getConfirmation()
e70a7fc0
TO
606 )
607 );
6a488035
TO
608 $this->chooseOkOnNextConfirmation();
609 $this->waitForPageToLoad($this->getTimeoutMsec());
efb29358 610 $this->waitForElementPresent('civicrm-footer');
dd055b5e 611 $this->waitForElementPresent("crm-main-content-wrapper");
efb29358
CW
612
613 // If we are still on the dedupe table page, count unmerged contacts
614 if ($this->isElementPresent("//table[@class='pagerDisplay']")) {
615 // Wait for datatable to load
616 $this->waitForElementPresent("//table[@class='pagerDisplay']/tbody/tr");
617 $unMergedContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr");
618 }
619 else {
620 $unMergedContacts = 0;
621 }
6a488035 622
6a488035 623 $mergedContacts = $totalContacts - $unMergedContacts;
6a488035
TO
624
625 //check the existence of merged contacts
626 $contactEmails = array(
627 1 => "{$firstName}.{$lastName}@example.com",
628 2 => "{$firstName2}.{$lastName2}@example.com",
21dfd5f5 629 3 => "{$firstName3}.{$lastName3}@example.com",
6a488035
TO
630 );
631
22e263ad 632 foreach ($contactEmails as $key => $value) {
6a488035
TO
633 $this->click('sort_name_navigation');
634 $this->type('css=input#sort_name_navigation', $value);
635 $this->typeKeys('css=input#sort_name_navigation', $value);
636 // Wait for result list.
0cff9fd6 637 $this->waitForElementPresent("css=ul.ui-autocomplete li.ui-menu-item");
6a488035
TO
638
639 // Visit contact summary page.
0cff9fd6 640 $this->clickLink("css=ul.ui-autocomplete li.ui-menu-item", 'civicrm-footer');
6a488035
TO
641 }
642 }
643
644 /**
eceb18cc 645 * Helper FN.
1e1fdcf6
EM
646 * @param null $firstName
647 * @param null $lastName
648 * @param null $organizationName
649 * @param string $contactType
650 * @return array
6a488035 651 */
00be9182 652 public function _createContacts($firstName = NULL, $lastName = NULL, $organizationName = NULL, $contactType = 'Individual') {
ada104d5
AW
653 if ($contactType == 'Individual') {
654 // add contact
655 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
656 //fill in first name
657 $this->type('first_name', $firstName);
6a488035 658
ada104d5
AW
659 //fill in last name
660 $this->type('last_name', $lastName);
6a488035 661
ada104d5
AW
662 //fill in email id
663 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
6a488035 664
ada104d5
AW
665 //fill in billing email id
666 $this->click('addEmail');
667 $this->waitForElementPresent('email_2_email');
668 $this->type('email_2_email', "$firstName.$lastName@billing.com");
669 $this->select('email_2_location_type_id', 'value=5');
670
671 // Clicking save.
672 $this->click("_qf_Contact_upload_view");
673 $this->waitForPageToLoad($this->getTimeoutMsec());
674 $this->waitForText('crm-notification-container', "Contact Saved");
675
676 //duplicate of above contact.
677 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
678
679 //fill in first name
680 $this->type("first_name", $firstName);
681
682 //fill in last name
683 $this->type("last_name", $lastName);
684
685 //fill in email
686 $this->type("email_1_email", "{$firstName}.{$lastName}@example.com");
687
688 // Clicking save.
689 $this->click("_qf_Contact_refresh_dedupe");
690 $this->waitForPageToLoad($this->getTimeoutMsec());
691
692 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
693 $this->click("_qf_Contact_upload_duplicate");
694 $this->waitForPageToLoad($this->getTimeoutMsec());
695 $this->waitForText('crm-notification-container', "Contact Saved");
696 }
697 elseif ($contactType == 'Organization') {
698 // add contact
699 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
700 //fill in Organization name
701 $this->type('organization_name', $organizationName);
702
703 //fill in email id
704 $this->type('email_1_email', "{$organizationName}@org.com");
705 // Clicking save.
706 $this->click("_qf_Contact_upload_view-bottom");
707 $this->waitForPageToLoad($this->getTimeoutMsec());
708 $this->waitForText('crm-notification-container', "Contact Saved");
d79be26c 709 $mainId = explode("Contact ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
ada104d5
AW
710 $mainId = trim($mainId[1]);
711
712 //Duplicate of above contact.
713 $this->openCiviPage("contact/add", "reset=1&ct=Organization");
714
715 //fill in Organization name
716 $this->type('organization_name', $organizationName);
717
718 //fill in email id
719 $this->type('email_1_email', "{$organizationName}@org.com");
720
721 // Clicking save.
722 $this->click("_qf_Contact_upload_view-bottom");
723 $this->waitForPageToLoad($this->getTimeoutMsec());
724
725 $this->waitForText('crm-notification-container', "One matching contact was found. You can View or Edit the existing contact.");
726 $this->click("_qf_Contact_upload_duplicate");
727 $this->waitForPageToLoad($this->getTimeoutMsec());
728 $this->waitForText('crm-notification-container', "Contact Saved");
d79be26c 729 $duplicateId = explode("Contact ID:", trim($this->getText("xpath=//div[@id='crm-record-log']/span[@class='col1']")));
ada104d5
AW
730 $duplicateId = trim($duplicateId[1]);
731
732 return array(
733 'mainId' => $mainId,
21dfd5f5 734 'duplicateId' => $duplicateId,
ada104d5
AW
735 );
736 }
737 }
738
739 /**
eceb18cc 740 * Helper FN.
91d49cae 741 * to create new membership type
1e1fdcf6 742 * @param $membershipOrganization
ada104d5 743 */
00be9182 744 public function addMembershipType($membershipOrganization) {
ada104d5
AW
745 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
746 $this->click("link=Add Membership Type");
747 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
748
749 $this->type('name', "Membership Type $membershipOrganization");
0cff9fd6 750 $this->select2('member_of_contact_id', $membershipOrganization);
ada104d5
AW
751
752 $this->type('minimum_fee', '1');
481a74f4 753 $this->select('financial_type_id', 'value=2');
ada104d5
AW
754 $this->type('duration_interval', 1);
755 $this->select('duration_unit', "label=year");
756
0cff9fd6 757 $this->select('period_type', "label=Fixed");
ada104d5
AW
758 $this->waitForElementPresent('fixed_period_rollover_day[d]');
759
760 // fixed period start set to April 1
761 $this->select('fixed_period_start_day[M]', 'value=4');
762 // rollover date set to Jan 31
763 $this->select('fixed_period_rollover_day[M]', 'value=1');
764
765 // Employer of relationship
766 $this->select('relationship_type_id', 'value=5_b_a');
767 $this->click('_qf_MembershipType_upload-bottom');
768 $this->waitForElementPresent('link=Add Membership Type');
0cff9fd6 769 $this->waitForText("crm-notification-container", "The membership type 'Membership Type $membershipOrganization' has been saved.");
ada104d5
AW
770 }
771
772 /**
773 * Test for CRM-12695 fix
774 */
00be9182 775 public function testMergeOrganizations() {
ada104d5
AW
776 $this->webtestLogin();
777
778 // build organisation name
92fcb95f 779 $orgnaizationName = 'org_' . substr(sha1(rand()), 0, 7);
ada104d5
AW
780
781 $contactIds = array();
782 // create organization and its duplicate
783 $contactIds = $this->_createContacts(NULL, NULL, $orgnaizationName, 'Organization');
784
785 /*** Add Membership Type - start ***/
786 $this->addMembershipType($orgnaizationName);
787 /*** Add Membership Type - end ***/
788
789 //create a New Individual to be related to main organization
790 $firstName = substr(sha1(rand()), 0, 7);
791 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
792 $sortName = "Anderson, $firstName";
793
794 // go to main organization contact to add membership
795 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['mainId']}");
796 // click through to the membership view screen
797 $this->click("css=li#tab_member a");
798
799 $this->waitForElementPresent("link=Add Membership");
800 $this->click("link=Add Membership");
801
802 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
803
804 // fill in Membership Organization and Type
805 $this->select("membership_type_id[0]", "label={$orgnaizationName}");
806 $this->waitForElementPresent("membership_type_id[1]");
807 // Wait for membership type select to reload
808 $this->waitForTextPresent("Membership Type $orgnaizationName");
809 $this->select("membership_type_id[1]", "label=Membership Type $orgnaizationName");
810
811 $sourceText = "Membership-Organization Duplicate Merge Webtest";
812 // fill in Source
813 $this->type("source", $sourceText);
814
815 // Let Join Date stay default
816
817 // fill in Start Date
818 $this->webtestFillDate('start_date');
6a488035
TO
819
820 // Clicking save.
ada104d5 821 $this->click("_qf_Membership_upload");
0cff9fd6 822 $this->waitForElementPresent('crm-notification-container');
ada104d5
AW
823 // page was loaded
824 $this->waitForTextPresent($sourceText);
825 // Is status message correct?
826 $this->waitForText('crm-notification-container', "membership for $orgnaizationName has been added.");
6a488035 827
ada104d5
AW
828 // add relationship "Employer of"
829 // click through to the relationship view screen
e684c1ae 830 $this->waitForAjaxContent();
ada104d5 831 $this->click("css=li#tab_rel a");
6a488035 832
ada104d5
AW
833 // wait for add Relationship link
834 $this->waitForElementPresent('link=Add Relationship');
835 $this->click('link=Add Relationship');
6a488035 836
ada104d5
AW
837 //choose the created relationship type
838 $this->waitForElementPresent("relationship_type_id");
839 $this->select('relationship_type_id', "value=5_b_a");
6a488035 840
ada104d5 841 //fill in the individual
bfb4aadb 842 $this->waitForElementPresent('related_contact_id');
0cff9fd6 843 $this->select2('related_contact_id', $sortName, TRUE, FALSE);
6a488035 844
0cff9fd6 845 $this->waitForElementPresent("_qf_Relationship_upload");
ada104d5
AW
846
847 //fill in the relationship start date
848 //$this->webtestFillDate('start_date', '-2 year');
849 //$this->webtestFillDate('end_date', '+1 year');
850
851 $description = "Well here is some description !!!!";
852 $this->type("description", $description);
853
854 //save the relationship
0cff9fd6 855 $this->click("_qf_Relationship_upload");
856 $this->isTextPresent("Current Relationships");
ada104d5
AW
857
858 //check the status message
0cff9fd6 859 $this->waitForText('crm-notification-container', "Relationship created.");
dd055b5e 860 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]/span/a[text()='View']");
9fdcdf6f 861 $this->waitForAjaxContent();
ada104d5 862 $this->click("xpath=//a[text()='$sortName']");
9fdcdf6f 863 $this->waitForAjaxContent();
6a488035 864
ada104d5
AW
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 //create a New Individual to be related to duplicate organization
870 $firstNameOther = substr(sha1(rand()), 0, 7);
871 $this->webtestAddContact($firstNameOther, "Harmison", "$firstNameOther@harmison.name");
872 $sortNameOther = "Harmison, $firstNameOther";
873
874 // go to main organization contact to add membership
875 $this->openCiviPage("contact/view", "reset=1&cid={$contactIds['duplicateId']}");
876
877 // add relationship "Employer of"
878 // click through to the relationship view screen
e684c1ae 879 $this->waitForAjaxContent();
ada104d5
AW
880 $this->click("css=li#tab_rel a");
881
882 // wait for add Relationship link
883 $this->waitForElementPresent('link=Add Relationship');
884 $this->click('link=Add Relationship');
885
886 //choose the created relationship type
887 $this->waitForElementPresent("relationship_type_id");
888 $this->select('relationship_type_id', "value=5_b_a");
889
890 //fill in the individual
03b0e225 891 $this->waitForElementPresent('related_contact_id');
0cff9fd6 892 $this->select2('related_contact_id', $sortNameOther, TRUE, FALSE);
ada104d5 893
0cff9fd6 894 $this->waitForElementPresent("_qf_Relationship_upload");
ada104d5
AW
895
896 //fill in the relationship start date
897 $this->webtestFillDate('start_date', '-2 year');
898 $this->webtestFillDate('end_date', '+1 year');
899
900 $description = "Well here is some description !!!!";
901 $this->type("description", $description);
902
903 //save the relationship
904 //$this->click("_qf_Relationship_upload");
0cff9fd6 905 $this->click("_qf_Relationship_upload");
906 $this->isTextPresent("Current Relationships");
ada104d5
AW
907
908 //check the status message
0cff9fd6 909 $this->isTextPresent("Relationship created.");
ada104d5 910
dd055b5e 911 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]/span/a[text()='View']");
ada104d5
AW
912
913 // go directly to contact merge page.
914 $this->openCiviPage("contact/merge", "reset=1&cid={$contactIds['mainId']}&oid={$contactIds['duplicateId']}&action=update&rgid=2");
915
916 $this->waitForElementPresent('_qf_Merge_cancel-bottom');
917 $this->click('_qf_Merge_next-bottom');
6a488035 918 $this->waitForPageToLoad($this->getTimeoutMsec());
ada104d5
AW
919
920 // click through to the relationship view screen
e684c1ae 921 $this->waitForAjaxContent();
ada104d5
AW
922 $this->click("css=li#tab_rel a");
923
924 // wait for add Relationship link
03b0e225 925 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody//tr//td//a[text()='$sortName']");
ada104d5
AW
926 // go to duplicate organization's related contact
927 // to check if membership is added to that contact
03b0e225 928 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody//tr//td//a[text()='$sortName']");
ada104d5
AW
929 $this->waitForPageToLoad($this->getTimeoutMsec());
930
931 // Check if Membership for the individual is created
932 $this->waitForElementPresent("xpath=//li[@id='tab_member']/a/em");
a1497b6c 933 $this->verifyText("xpath=//li[@id='tab_member']/a/em", 0);
6a488035 934 }
668e7477 935
936 /**
937 * Test for CRM-15658 fix
938 */
00be9182 939 public function testMergeEmailAndAddress() {
668e7477 940 $this->webtestLogin();
941 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
942 $firstName = substr(sha1(rand()), 0, 7);
943 $this->type('first_name', $firstName);
944
945 //fill in last name
946 $lastName = substr(sha1(rand()), 0, 7);
947 $this->type('last_name', $lastName);
948
949 //fill in email id
950 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
951
952 //address section
953 $this->click("addressBlock");
954 $this->waitForElementPresent("address_1_street_address");
955 $this->type("address_1_street_address", "902C El Camino Way SW");
956 $this->type("address_1_city", "Dumfries");
957 $this->type("address_1_postal_code", "1234");
958
959 // Clicking save.
960 $this->click("_qf_Contact_upload_view");
961 $this->waitForPageToLoad($this->getTimeoutMsec());
962 $this->waitForText('crm-notification-container', "Contact Saved");
963
964 //duplicate contact with same email id
965 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
966 $firstName2 = substr(sha1(rand()), 0, 7);
967 $this->type('first_name', $firstName2);
968
969 //fill in last name
970 $lastName2 = substr(sha1(rand()), 0, 7);
971 $this->type('last_name', $lastName2);
972
973 //fill in email id
974 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
975
976 //address section
977 $this->click("addressBlock");
978 $this->waitForElementPresent("address_1_street_address");
979 $this->type("address_1_street_address", "2782Y Dowlen Path W");
980 $this->type("address_1_city", "Birmingham");
981 $this->type("address_1_postal_code", "3456");
982
983 // Clicking save.
984 $this->click("_qf_Contact_upload_view");
985 $this->waitForPageToLoad($this->getTimeoutMsec());
986 $this->waitForText('crm-notification-container', "Contact Saved");
987
988 $this->openCiviPage("contact/dedupefind", "reset=1&action=update&rgid=4");
fdb227e0 989 $this->click("//a/span[contains(text(),'Refresh Duplicates')]");
6c6e6187 990 $this->assertTrue((bool) preg_match("/This will refresh the duplicates list. Click OK to proceed./", $this->getConfirmation()));
668e7477 991 $this->chooseOkOnNextConfirmation();
992 $this->waitForPageToLoad($this->getTimeoutMsec());
dd055b5e
WA
993 $this->waitForElementPresent("xpath=//table[@id='dupePairs']/tbody//tr/td[3]/a[text()='$firstName $lastName']/../../td[8]//a[text()='merge']");
994 $this->click("xpath=//table[@id='dupePairs']/tbody//tr/td[3]/a[text()='$firstName $lastName']/../../td[8]//a[text()='merge']");
995 $this->waitForPageToLoad($this->getTimeoutMsec());
668e7477 996
997 //merge without specifying any criteria
998 $this->click("_qf_Merge_next-bottom");
999 $this->waitForPageToLoad($this->getTimeoutMsec());
1000
1001 $this->assertTrue($this->isTextPresent('Contacts Merged'));
1002 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]"));
1003 $this->verifyElementNotPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Home')]");
1004 $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]"));
1005 $this->verifyElementNotPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[contains(text(), '{$firstName}.{$lastName}@example.com')]");
1006
1007 $this->assertElementContainsText('address-block-1', "902C El Camino Way SW");
1008 $this->assertElementContainsText('address-block-1', "Dumfries");
1009 $this->assertElementContainsText('address-block-1', "1234");
1010
1011 $this->assertElementNotContainsText("address-block-2", "2782Y Dowlen Path W");
1012 $this->assertElementNotContainsText("address-block-2", "Birmingham");
1013 $this->assertElementNotContainsText("address-block-2", "3456");
1014 }
96025800 1015
6a488035 1016}