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