Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | ||
28 | require_once 'CiviTest/CiviSeleniumTestCase.php'; | |
29 | class WebTest_Contact_MergeContactsTest extends CiviSeleniumTestCase { | |
30 | ||
31 | protected function setUp() { | |
32 | parent::setUp(); | |
33 | } | |
34 | ||
35 | function testIndividualAdd() { | |
36 | // Logging in. Remember to wait for page to load. In most cases, | |
37 | // you can rely on 30000 as the value that allows your test to pass, however, | |
38 | // sometimes your test might fail because of this. In such cases, it's better to pick one element | |
39 | // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole | |
40 | // page contents loaded and you can continue your test execution. | |
41 | $this->webtestLogin(); | |
42 | ||
43 | // Go directly to the URL of New Individual. | |
44 | $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual"); | |
45 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
46 | ||
47 | // add contact1 | |
48 | //select prefix | |
49 | $prefix = 'Mr.'; | |
50 | $this->click("prefix_id"); | |
51 | $this->select("prefix_id", "label=$prefix"); | |
52 | ||
53 | //fill in first name | |
54 | $firstName = substr(sha1(rand()), 0, 7); | |
55 | $this->type('first_name', $firstName); | |
56 | ||
57 | //fill in last name | |
58 | $lastName = substr(sha1(rand()), 0, 7); | |
59 | $this->type('last_name', $lastName); | |
60 | ||
61 | //fill in email id | |
62 | $this->type('email_1_email', "{$firstName}.{$lastName}@example.com"); | |
63 | ||
64 | //fill in billing email id | |
65 | $this->click('addEmail'); | |
66 | $this->waitForElementPresent('email_2_email'); | |
67 | $this->type('email_2_email', "$firstName.$lastName@billing.com"); | |
68 | $this->select('email_2_location_type_id', 'value=5'); | |
69 | ||
70 | // Clicking save. | |
71 | $this->click("_qf_Contact_upload_view"); | |
72 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
73 | $this->assertElementContainsText('crm-notification-container', "Contact Saved"); | |
74 | ||
75 | // Add Contact to a group | |
76 | $group = 'Newsletter Subscribers'; | |
77 | $this->click('css=li#tab_group a'); | |
78 | $this->waitForElementPresent('_qf_GroupContact_next'); | |
79 | $this->select('group_id', "label=$group"); | |
80 | $this->click('_qf_GroupContact_next'); | |
81 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
82 | $this->assertElementContainsText('crm-notification-container', "Added to Group"); | |
83 | ||
84 | // Add Tags to the contact | |
85 | $tag = 'Government Entity'; | |
86 | $this->click("css=li#tab_tag a"); | |
87 | $this->waitForElementPresent('tagtree'); | |
88 | $this->click("xpath=//div[@id='tagtree']/ul//li/input/../label[text()='$tag']"); | |
89 | $this->click("css=#tab_summary a"); | |
90 | $this->assertElementContainsText('css=.crm-summary-block #tags', $tag); | |
91 | ||
92 | // Add an activity | |
93 | $subject = "This is subject of test activity being added through activity tab of contact summary screen."; | |
94 | $this->addActivity($firstName, $lastName, $subject); | |
95 | ||
96 | // contact2: duplicate of contact1. | |
97 | $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual"); | |
98 | ||
99 | //fill in first name | |
100 | $this->type("first_name", $firstName); | |
101 | ||
102 | //fill in last name | |
103 | $this->type("last_name", $lastName); | |
104 | ||
105 | //fill in email | |
106 | $this->type("email_1_email", "{$firstName}.{$lastName}@example.com"); | |
107 | ||
108 | // Clicking save. | |
109 | $this->click("_qf_Contact_refresh_dedupe"); | |
110 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
111 | ||
112 | $this->assertTrue($this->isTextPresent("One matching contact was found. You can View or Edit the existing contact.")); | |
113 | $this->click("_qf_Contact_upload_duplicate"); | |
114 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
115 | $this->assertElementContainsText('crm-notification-container', "Contact Saved"); | |
116 | ||
117 | // Add second pair of dupes so we can test Merge and Goto Next Pair | |
118 | $fname2 = 'Janet'; | |
119 | $lname2 = 'Rogers' . substr(sha1(rand()), 0, 7); | |
120 | $email2 = "{$fname2}.{$lname2}@example.org"; | |
121 | $this->webtestAddContact($fname2, $lname2, $email2); | |
122 | ||
123 | // Can not use helper for 2nd contact since it is a dupe | |
124 | $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual"); | |
125 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
126 | $this->type("first_name", $fname2); | |
127 | $this->type("last_name", $lname2); | |
128 | $this->type("email_1_email", $email2); | |
129 | $this->click("_qf_Contact_refresh_dedupe"); | |
130 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
131 | $this->assertTrue($this->isTextPresent("One matching contact was found. You can View or Edit the existing contact.")); | |
132 | $this->click("_qf_Contact_upload_duplicate"); | |
133 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
134 | $this->assertElementContainsText('crm-notification-container', "Contact Saved"); | |
135 | ||
136 | // Find and Merge Contacts with Supervised Rule | |
137 | $this->open($this->sboxPath . 'civicrm/contact/dedupefind?reset=1&rgid=1&action=renew'); | |
138 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
139 | ||
140 | // reload the page | |
141 | $this->open($this->sboxPath . 'civicrm/contact/dedupefind?reset=1&rgid=1&action=update'); | |
142 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
143 | ||
144 | // Select the contacts to be merged | |
145 | $this->select("name=option51_length", "value=100"); | |
146 | $this->waitForTextPresent("$firstName $lastName"); | |
147 | ||
148 | // sleep seems to work here, not sure why | |
149 | sleep(3); | |
150 | $this->click("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']"); | |
151 | $this->waitForElementPresent('_qf_Merge_cancel-bottom'); | |
152 | ||
153 | $this->click("css=div.crm-contact-merge-form-block div.action-link a"); | |
154 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
155 | $this->waitForElementPresent('_qf_Merge_cancel-bottom'); | |
156 | ||
157 | // Move the activities, groups, etc to the main contact and merge using Merge and Goto Next Pair | |
158 | $this->check('move_prefix_id'); | |
159 | $this->check('move_location_email_2'); | |
160 | $this->check('move_rel_table_activities'); | |
161 | $this->check('move_rel_table_groups'); | |
162 | $this->check('move_rel_table_tags'); | |
163 | $this->click('_qf_Merge_next-bottom'); | |
164 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
165 | $this->waitForElementPresent('_qf_Merge_cancel-bottom'); | |
166 | $this->assertTrue($this->isTextPresent('Contacts Merged'), "Contacts Merged text was not found after merge."); | |
167 | ||
168 | // Check that we are viewing the next Merge Pair (our 2nd contact, since the merge list is ordered by contact_id) | |
169 | $this->assertTrue($this->isTextPresent("{$fname2} {$lname2}"), "Redirect for Goto Next Pair after merge did not work."); | |
170 | ||
171 | // Ensure that the duplicate contact has been deleted | |
172 | $this->open($this->sboxPath . 'civicrm/contact/search/advanced?reset=1'); | |
173 | $this->waitForElementPresent('_qf_Advanced_refresh'); | |
174 | $this->type('sort_name', $firstName); | |
175 | $this->check('deleted_contacts'); | |
176 | $this->click('_qf_Advanced_refresh'); | |
177 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
178 | $this->assertTrue($this->isTextPresent('1 Contact'), "Deletion of duplicate contact during merge was not successful. Dupe contact not found when searching trash."); | |
179 | ||
180 | // Search for the main contact | |
181 | $this->open($this->sboxPath . 'civicrm/contact/search/advanced?reset=1'); | |
182 | $this->waitForElementPresent('_qf_Advanced_refresh'); | |
183 | $this->type('sort_name', $firstName); | |
184 | $this->click('_qf_Advanced_refresh'); | |
185 | $this->waitForElementPresent("xpath=//form[@id='Advanced']/div[3]/div/div[2]/table/tbody/tr"); | |
186 | ||
187 | $this->click("//form[@id='Advanced']/div[3]/div/div[2]/table/tbody/tr/td[11]/span[1]/a[text()='View']"); | |
188 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
189 | ||
190 | // Verify prefix merged | |
191 | // $this->verifyText( "xpath=//div[@class='left-corner']/h2", preg_quote( "$prefix $firstName $lastName" ) ); | |
192 | ||
193 | // Verify billing email merged | |
194 | $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']"); | |
195 | ||
196 | // Verify activity merged | |
197 | $this->click("css=li#tab_activity a"); | |
198 | $this->waitForElementPresent("xpath=//table[@id='contact-activity-selector-activity']/tbody/tr"); | |
199 | $this->verifyText("xpath=//table[@id='contact-activity-selector-activity']/tbody/tr/td[5]/a", | |
200 | preg_quote("$lastName, $firstName") | |
201 | ); | |
202 | ||
203 | // Verify group merged | |
204 | $this->click("css=li#tab_group a"); | |
fb06ea42 DS |
205 | $this->waitForElementPresent("xpath=//form[@id='GroupContact']//div[@class='view-content']//div[@class='dataTables_wrapper']/table/tbody/tr"); |
206 | $this->verifyText("xpath=//form[@id='GroupContact']//div[@class='view-content']//div[@class='dataTables_wrapper']/table/tbody/tr/td/a", | |
6a488035 TO |
207 | preg_quote("$group") |
208 | ); | |
209 | ||
210 | // Verify tag merged | |
211 | $this->click("css=li#tab_tag a"); | |
212 | $this->waitForElementPresent('check_5'); | |
213 | $this->assertChecked("check_3"); | |
214 | } | |
215 | ||
216 | function addActivity($firstName, $lastName, $subject) { | |
217 | $withContact = substr(sha1(rand()), 0, 7); | |
218 | $this->webtestAddContact($withContact, "Anderson", $withContact . "@anderson.name"); | |
219 | ||
220 | $this->click("css=li#tab_activity a"); | |
221 | ||
222 | // waiting for the activity dropdown to show up | |
223 | $this->waitForElementPresent("other_activity"); | |
224 | ||
225 | // Select the activity type from the activity dropdown | |
226 | $this->select("other_activity", "label=Meeting"); | |
227 | ||
228 | // waitForPageToLoad is not always reliable. Below, we're waiting for the submit | |
229 | // button at the end of this page to show up, to make sure it's fully loaded. | |
230 | $this->waitForElementPresent("_qf_Activity_upload"); | |
231 | ||
232 | // Let's start filling the form with values. | |
233 | ||
234 | // ...and verifying if the page contains properly formatted display name for chosen contact. | |
235 | $this->assertTrue($this->isTextPresent("Anderson, " . $withContact), "Contact not found in line " . __LINE__); | |
236 | ||
237 | // Now we're filling the "Assigned To" field. | |
238 | // Typing contact's name into the field (using typeKeys(), not type()!)... | |
239 | $this->click("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id"); | |
240 | $this->type("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName); | |
241 | $this->typeKeys("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName); | |
242 | ||
243 | // ...waiting for drop down with results to show up... | |
244 | $this->waitForElementPresent("css=div.token-input-dropdown-facebook"); | |
245 | $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook"); | |
246 | ||
247 | //..need to use mouseDownAt on first result (which is a li element), click does not work | |
248 | $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook"); | |
249 | ||
250 | // ...again, waiting for the box with contact name to show up... | |
251 | $this->waitForElementPresent("css=tr.crm-activity-form-block-assignee_contact_id td ul li span.token-input-delete-token-facebook"); | |
252 | ||
253 | // ...and verifying if the page contains properly formatted display name for chosen contact. | |
254 | $this->assertTrue($this->isTextPresent("$lastName, " . $firstName), "Contact not found in line " . __LINE__); | |
255 | ||
256 | // Since we're here, let's check if screen help is being displayed properly | |
257 | $this->assertTrue($this->isTextPresent("Assigned activities will appear in their Activities listing at CiviCRM Home")); | |
258 | ||
259 | // Putting the contents into subject field - assigning the text to variable, it'll come in handy later | |
260 | // For simple input fields we can use field id as selector | |
261 | $this->type("subject", $subject); | |
262 | $this->type("location", "Some location needs to be put in this field."); | |
263 | ||
264 | // Choosing the Date. | |
265 | // Please note that we don't want to put in fixed date, since | |
266 | // we want this test to work in the future and not fail because | |
267 | // of date being set in the past. Therefore, using helper webtestFillDateTime function. | |
268 | $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM'); | |
269 | ||
270 | // Setting duration. | |
271 | $this->type("duration", "30"); | |
272 | ||
273 | // Putting in details. | |
274 | $this->type("details", "Really brief details information."); | |
275 | ||
276 | // Making sure that status is set to Scheduled (using value, not label). | |
277 | $this->select("status_id", "value=1"); | |
278 | ||
279 | // Setting priority. | |
280 | $this->select("priority_id", "value=1"); | |
281 | ||
282 | // Clicking save. | |
283 | $this->click("_qf_Activity_upload"); | |
284 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
285 | ||
286 | // Is status message correct? | |
287 | $this->assertTrue($this->isTextPresent("Activity '$subject' has been saved."), "Status message didn't show up after saving!"); | |
288 | } | |
289 | ||
290 | ||
291 | function testMergeTest() { | |
292 | // Logging in. Remember to wait for page to load. In most cases, | |
293 | // you can rely on 30000 as the value that allows your test to pass, however, | |
294 | // sometimes your test might fail because of this. In such cases, it's better to pick one element | |
295 | // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole | |
296 | // page contents loaded and you can continue your test execution. | |
297 | $this->webtestLogin(); | |
298 | ||
299 | // Go directly to the URL of New Individual. | |
300 | $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual"); | |
301 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
302 | ||
303 | // add contact1 | |
304 | //fill in first name | |
305 | $firstName = substr(sha1(rand()), 0, 7); | |
306 | $this->type('first_name', $firstName); | |
307 | ||
308 | //fill in last name | |
309 | $lastName = substr(sha1(rand()), 0, 7); | |
310 | $this->type('last_name', $lastName); | |
311 | ||
312 | //fill in email id | |
313 | $this->type('email_1_email', "{$firstName}.{$lastName}@example.com"); | |
314 | ||
315 | //fill in billing email id | |
316 | $this->click('addEmail'); | |
317 | $this->waitForElementPresent('email_2_email'); | |
318 | $this->type('email_2_email', "$firstName.$lastName@billing.com"); | |
319 | $this->select('email_2_location_type_id', 'value=5'); | |
320 | ||
321 | //fill in home phone no | |
322 | $this->type('phone_1_phone', "9876543210"); | |
323 | ||
324 | //fill in billing phone id | |
325 | $this->click('addPhone'); | |
326 | $this->waitForElementPresent('phone_2_phone'); | |
327 | $this->type('phone_2_phone', "9876543120"); | |
328 | $this->select('phone_2_location_type_id', 'value=5'); | |
329 | ||
330 | // Clicking save. | |
331 | $this->click("_qf_Contact_upload_view"); | |
332 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
333 | $this->assertElementContainsText('crm-notification-container', "Contact Saved"); | |
334 | ||
335 | // contact2: duplicate of contact1. | |
336 | $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual"); | |
337 | ||
338 | //fill in first name | |
339 | $this->type("first_name", $firstName); | |
340 | ||
341 | //fill in last name | |
342 | $this->type("last_name", $lastName); | |
343 | ||
344 | //fill in email | |
345 | $this->type("email_1_email", "{$firstName}.{$lastName}@example.com"); | |
346 | ||
347 | //fill in home phone no | |
348 | $this->type('phone_1_phone', "9876543211"); | |
349 | ||
350 | // Clicking save. | |
351 | $this->click("_qf_Contact_refresh_dedupe"); | |
352 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
353 | ||
354 | $this->assertTrue($this->isTextPresent("One matching contact was found. You can View or Edit the existing contact.")); | |
355 | $this->click("_qf_Contact_upload_duplicate"); | |
356 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
357 | $this->assertElementContainsText('crm-notification-container', "Contact Saved"); | |
358 | ||
359 | // Find and Merge Contacts with Supervised Rule | |
360 | $this->open($this->sboxPath . 'civicrm/contact/dedupefind?reset=1&rgid=1&action=renew'); | |
361 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
362 | ||
363 | // Select the contacts to be merged | |
364 | $this->select("name=option51_length", "value=100"); | |
365 | $this->waitForElementPresent("xpath=//a[text()='$firstName $lastName']"); | |
366 | $this->click("xpath=//a[text()='$firstName $lastName']/../../td[4]/a[text()='merge']"); | |
367 | $this->waitForElementPresent('_qf_Merge_cancel-bottom'); | |
368 | $this->click("css=div.crm-contact-merge-form-block div.action-link a"); | |
369 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
370 | $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']"); | |
371 | $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']"); | |
372 | $this->waitForElementPresent('_qf_Merge_cancel-bottom'); | |
373 | ||
374 | $this->check("move_location_email_1"); | |
375 | $this->check("location[email][1][operation]"); | |
376 | $this->check("move_location_email_2"); | |
377 | $this->check("move_location_phone_1"); | |
378 | $this->check("location[phone][1][operation]"); | |
379 | $this->check("move_location_phone_2"); | |
380 | $this->click("_qf_Merge_next-bottom"); | |
381 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
382 | ||
383 | $this->assertTrue($this->isTextPresent('Contacts Merged')); | |
384 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]")); | |
385 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[text() = '{$firstName}.{$lastName}@example.com']")); | |
386 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Home')]")); | |
387 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[text() ='{$firstName}.{$lastName}@example.com']")); | |
388 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]")); | |
389 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[4]/div[2]/a[text() ='$firstName.$lastName@billing.com']")); | |
390 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Home')]")); | |
391 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543211')]")); | |
392 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]")); | |
393 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]")); | |
394 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[1][contains(text(), 'Billing')]")); | |
395 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[4]/div[2][contains(text(), '9876543120')]")); | |
396 | ||
397 | //Merge with the feature of (add) | |
398 | // Go directly to the URL of New Individual. | |
399 | $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual"); | |
400 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
401 | ||
402 | // add contact1 | |
403 | //fill in first name | |
404 | $firstName1 = substr(sha1(rand()), 0, 7); | |
405 | $this->type('first_name', $firstName1); | |
406 | ||
407 | //fill in last name | |
408 | $lastName1 = substr(sha1(rand()), 0, 7); | |
409 | $this->type('last_name', $lastName1); | |
410 | ||
411 | //fill in billing email id | |
412 | $this->waitForElementPresent('email_1_email'); | |
413 | $this->type('email_1_email', "$firstName1.$lastName1@example.com"); | |
414 | $this->select('email_1_location_type_id', 'value=5'); | |
415 | ||
416 | $this->click('addEmail'); | |
417 | $this->waitForElementPresent('email_2_email'); | |
418 | $this->type('email_2_email', "$firstName.$lastName@home.com"); | |
419 | $this->select('email_2_location_type_id', 'value=1'); | |
420 | ||
421 | //fill in home phone no | |
422 | $this->type('phone_1_phone', "9876543210"); | |
423 | ||
424 | // Clicking save. | |
425 | $this->click("_qf_Contact_upload_view"); | |
426 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
427 | $this->assertElementContainsText('crm-notification-container', "Contact Saved"); | |
428 | ||
429 | // contact2: duplicate of contact1. | |
430 | $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual"); | |
431 | ||
432 | //fill in first name | |
433 | $this->type("first_name", $firstName1); | |
434 | ||
435 | //fill in last name | |
436 | $this->type("last_name", $lastName1); | |
437 | ||
438 | //fill in email | |
439 | $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com"); | |
440 | ||
441 | //fill in billing phone no | |
442 | $this->type('phone_1_phone', "9876543120"); | |
443 | $this->select('phone_1_location_type_id', 'value=5'); | |
444 | ||
445 | // Clicking save. | |
446 | $this->click("_qf_Contact_refresh_dedupe"); | |
447 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
448 | $this->assertTrue($this->isTextPresent("One matching contact was found. You can View or Edit the existing contact.")); | |
449 | $this->click("_qf_Contact_upload_duplicate"); | |
450 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
451 | $this->assertElementContainsText('crm-notification-container', "Contact Saved"); | |
452 | ||
453 | // Find and Merge Contacts with Supervised Rule | |
454 | $this->open($this->sboxPath . 'civicrm/contact/dedupefind?reset=1&rgid=1&action=renew'); | |
455 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
456 | ||
457 | // Select the contacts to be merged | |
458 | $this->select("name=option51_length", "value=100"); | |
459 | $this->waitForElementPresent("xpath=//table[@class='pagerDisplay']/tbody//tr/td[1]/a[text()='$firstName1 $lastName1']/../../td[2]/a[text()='$firstName1 $lastName1']"); | |
460 | $this->click("xpath=//table[@class='pagerDisplay']/tbody//tr/td[1]/a[text()='$firstName1 $lastName1']/../../td[2]/a[text()='$firstName1 $lastName1']/../../td[4]/a[text()='merge']"); | |
461 | $this->waitForElementPresent('_qf_Merge_cancel-bottom'); | |
462 | $this->click("css=div.crm-contact-merge-form-block div.action-link a"); | |
463 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
464 | $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']"); | |
465 | $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']"); | |
466 | $this->waitForElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']"); | |
467 | $this->select('location_email_1_locTypeId', 'value=3'); | |
468 | $this->select('location_phone_1_locTypeId', 'value=1'); | |
469 | $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[2]/td[4]/span[text()='(overwrite)']")); | |
470 | $this->assertFalse($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[4]/td[4]/span[text()='(overwrite)']")); | |
471 | $this->assertTrue($this->isElementPresent("xpath=//form[@id='Merge']/div[2]/table/tbody/tr[3]/td[4]/span[text()='(add)']")); | |
472 | $this->waitForElementPresent('_qf_Merge_cancel-bottom'); | |
473 | ||
474 | $this->check("move_location_email_1"); | |
475 | $this->check("move_location_phone_1"); | |
476 | $this->click("_qf_Merge_next-bottom"); | |
477 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
478 | ||
479 | $this->assertTrue($this->isTextPresent('Contacts Merged')); | |
480 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[1][contains(text(), 'Home')]")); | |
481 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[2]/div[2]/a[text() ='{$firstName1}.{$lastName1}@example.com']")); | |
482 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[1][contains(text(), 'Main')]")); | |
483 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='email-block']/div/div/div[3]/div[2]/a[text() ='{$firstName1}.{$lastName1}@example.com']")); | |
484 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[1][contains(text(), 'Billing')]")); | |
485 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[2]/div[2][contains(text(), '9876543120')]")); | |
486 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[1][contains(text(), 'Home')]")); | |
487 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='phone-block']/div/div/div[3]/div[2][contains(text(), '9876543210')]")); | |
488 | } | |
489 | ||
490 | function testBatchMerge(){ | |
491 | // Logging in. Remember to wait for page to load. In most cases, | |
492 | // you can rely on 30000 as the value that allows your test to pass, however, | |
493 | // sometimes your test might fail because of this. In such cases, it's better to pick one element | |
494 | // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole | |
495 | // page contents loaded and you can continue your test execution. | |
496 | $this->webtestLogin(); | |
497 | ||
498 | // add contact1 and its duplicate | |
499 | //first name | |
500 | $firstName = "Kerry".substr(sha1(rand()), 0, 7); | |
501 | //last name | |
502 | $lastName = "King".substr(sha1(rand()), 0, 7); | |
503 | $this->_createContacts($firstName,$lastName); | |
504 | ||
505 | //add contact2 and its duplicate | |
506 | //These are the contacts with conflicts in communication preference.these contacts will be skipped during merge. | |
507 | $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual"); | |
508 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
509 | ||
510 | //fill in first name | |
511 | $firstName1 = "Kurt".substr(sha1(rand()), 0, 7); | |
512 | $this->type('first_name', $firstName1); | |
513 | ||
514 | //fill in last name | |
515 | $lastName1 = "Cobain".substr(sha1(rand()), 0, 7); | |
516 | $this->type('last_name', $lastName1); | |
517 | ||
518 | //fill in email id | |
519 | $this->type('email_1_email', "{$firstName1}.{$lastName1}@example.com"); | |
520 | ||
521 | //fill in billing email id | |
522 | $this->click('addEmail'); | |
523 | $this->waitForElementPresent('email_2_email'); | |
524 | $this->type('email_2_email', "$firstName1.$lastName1@billing.com"); | |
525 | $this->select('email_2_location_type_id', 'value=5'); | |
526 | ||
527 | //fill in home phone no | |
528 | $this->type('phone_1_phone', "9876543210"); | |
529 | ||
530 | //fill in billing phone id | |
531 | $this->click('addPhone'); | |
532 | $this->waitForElementPresent('phone_2_phone'); | |
533 | $this->type('phone_2_phone', "9876543120"); | |
534 | $this->select('phone_2_location_type_id', 'value=5'); | |
535 | ||
536 | //select communication preference | |
537 | $this->check("privacy[do_not_phone]"); | |
538 | ||
539 | //Clicking save. | |
540 | $this->click("_qf_Contact_upload_view"); | |
541 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
542 | $this->assertElementContainsText('crm-notification-container', "Contact Saved"); | |
543 | ||
544 | //duplicate of contact2. | |
545 | $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual"); | |
546 | ||
547 | //fill in first name | |
548 | $this->type("first_name", $firstName1); | |
549 | ||
550 | //fill in last name | |
551 | $this->type("last_name", $lastName1); | |
552 | ||
553 | //fill in email | |
554 | $this->type("email_1_email", "{$firstName1}.{$lastName1}@example.com"); | |
555 | ||
556 | //fill in home phone no | |
557 | $this->type('phone_1_phone', "9876543211"); | |
558 | ||
559 | //select communication preference | |
560 | $this->check("preferred_communication_method[1]"); | |
561 | ||
562 | // Clicking save. | |
563 | $this->click("_qf_Contact_refresh_dedupe"); | |
564 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
565 | ||
566 | $this->assertTrue($this->isTextPresent("One matching contact was found. You can View or Edit the existing contact.")); | |
567 | $this->click("_qf_Contact_upload_duplicate"); | |
568 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
569 | $this->assertElementContainsText('crm-notification-container', "Contact Saved"); | |
570 | ||
571 | // add contact3 and its duplicate | |
572 | //fill in first name | |
573 | $firstName2 = "David".substr(sha1(rand()), 0, 7); | |
574 | //fill in last name | |
575 | $lastName2 = "Gilmour".substr(sha1(rand()), 0, 7); | |
576 | $this->_createContacts($firstName2,$lastName2); | |
577 | ||
578 | // add contact4 and its duplicate | |
579 | //fill in first name | |
580 | $firstName3 = "Dave".substr(sha1(rand()), 0, 7); | |
581 | //fill in last name | |
582 | $lastName3 = "Mustaine".substr(sha1(rand()), 0, 7); | |
583 | $this->_createContacts($firstName3,$lastName3); | |
584 | ||
585 | // Find and Merge Contacts with Supervised Rule | |
586 | $this->open($this->sboxPath . 'civicrm/contact/dedupefind?reset=1&rgid=1&action=renew'); | |
587 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
588 | sleep(3); | |
589 | ||
590 | $this->select("name=option51_length", "value=100"); | |
591 | $totalContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr"); | |
592 | $this->click("xpath=//form[@id='DedupeFind']//a/span[text()='Batch Merge Duplicates']"); | |
593 | ||
594 | // Check confirmation alert. | |
595 | $this->assertTrue( | |
596 | (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./", | |
597 | $this->getConfirmation() | |
598 | )); | |
599 | $this->chooseOkOnNextConfirmation(); | |
600 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
601 | sleep(5); | |
602 | ||
603 | $unMergedContacts = $this->getXpathCount("//table[@class='pagerDisplay']/tbody/tr"); | |
604 | $mergedContacts = $totalContacts - $unMergedContacts; | |
605 | $this->assertElementContainsText('crm-notification-container', "safe mode"); | |
606 | ||
607 | //check the existence of merged contacts | |
608 | $contactEmails = array( | |
609 | 1 => "{$firstName}.{$lastName}@example.com", | |
610 | 2 => "{$firstName2}.{$lastName2}@example.com", | |
611 | 3 => "{$firstName3}.{$lastName3}@example.com" | |
612 | ); | |
613 | ||
614 | foreach( $contactEmails as $key => $value ) { | |
615 | $this->click('sort_name_navigation'); | |
616 | $this->type('css=input#sort_name_navigation', $value); | |
617 | $this->typeKeys('css=input#sort_name_navigation', $value); | |
618 | // Wait for result list. | |
619 | $this->waitForElementPresent("css=div.ac_results-inner li"); | |
620 | ||
621 | // Visit contact summary page. | |
622 | $this->click("css=div.ac_results-inner li"); | |
623 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
624 | sleep(2); | |
625 | } | |
626 | } | |
627 | ||
628 | /** | |
629 | * Helper FN | |
630 | */ | |
631 | function _createContacts($firstName,$lastName){ | |
632 | // add contact | |
633 | $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual"); | |
634 | //fill in first name | |
635 | $this->type('first_name', $firstName); | |
636 | ||
637 | //fill in last name | |
638 | $this->type('last_name', $lastName); | |
639 | ||
640 | //fill in email id | |
641 | $this->type('email_1_email', "{$firstName}.{$lastName}@example.com"); | |
642 | ||
643 | //fill in billing email id | |
644 | $this->click('addEmail'); | |
645 | $this->waitForElementPresent('email_2_email'); | |
646 | $this->type('email_2_email', "$firstName.$lastName@billing.com"); | |
647 | $this->select('email_2_location_type_id', 'value=5'); | |
648 | ||
649 | // Clicking save. | |
650 | $this->click("_qf_Contact_upload_view"); | |
651 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
652 | $this->assertElementContainsText('crm-notification-container', "Contact Saved"); | |
653 | ||
654 | //duplicate of above contact. | |
655 | $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual"); | |
656 | ||
657 | //fill in first name | |
658 | $this->type("first_name", $firstName); | |
659 | ||
660 | //fill in last name | |
661 | $this->type("last_name", $lastName); | |
662 | ||
663 | //fill in email | |
664 | $this->type("email_1_email", "{$firstName}.{$lastName}@example.com"); | |
665 | ||
666 | // Clicking save. | |
667 | $this->click("_qf_Contact_refresh_dedupe"); | |
668 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
669 | ||
670 | $this->assertTrue($this->isTextPresent("One matching contact was found. You can View or Edit the existing contact.")); | |
671 | $this->click("_qf_Contact_upload_duplicate"); | |
672 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
673 | $this->assertElementContainsText('crm-notification-container', "Contact Saved"); | |
674 | } | |
675 | } | |
676 |