Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
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 | ||
6a488035 TO |
27 | require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php'; |
28 | class WebTest_Import_DuplicateMatchingTest extends ImportCiviSeleniumTestCase { | |
29 | ||
30 | protected function setUp() { | |
31 | parent::setUp(); | |
32 | } | |
33 | ||
34 | /* | |
35 | * Test contact import for Individuals Duplicate Matching. | |
36 | */ | |
37 | function testIndividualDuplicateMatchingImport() { | |
6a488035 TO |
38 | $this->webtestLogin(); |
39 | ||
42daf119 | 40 | $this->openCiviPage("contact/add", "reset=1&ct=Individual", 'first_name'); |
6a488035 TO |
41 | |
42 | $email = substr(sha1(rand()), 0, 7) . '@example.com'; | |
43 | ||
44 | // fill in first name | |
45 | $firstName = substr(sha1(rand()), 0, 7); | |
46 | $this->type('first_name', $firstName); | |
47 | ||
48 | // fill in last name | |
49 | $lastName = substr(sha1(rand()), 0, 7); | |
50 | $this->type('last_name', $lastName); | |
51 | ||
52 | //fill in email | |
53 | $this->type('email_1_email', $email); | |
54 | ||
55 | // Clicking save. | |
56 | $this->click('_qf_Contact_upload_view'); | |
57 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
6c5f7368 | 58 | $this->waitForText('crm-notification-container', "Contact Saved"); |
6a488035 TO |
59 | |
60 | $existingContact = array( | |
61 | 'first_name' => $firstName, | |
62 | 'last_name' => $lastName, | |
63 | 'email' => $email, | |
64 | ); | |
65 | ||
66 | // Get sample import data. | |
67 | list($headers, $rows) = $this->_individualDuplicateMatchingCSVData($existingContact); | |
68 | ||
69 | // Import and check Individual contacts in Skip mode. | |
70 | $other = array('callbackImportSummary' => 'checkDuplicateContacts'); | |
71 | $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other); | |
72 | ||
73 | // Get imported contact Ids | |
74 | $importedContactIds = $this->_getImportedContactIds($rows); | |
75 | ||
76 | // Build update mode import headers | |
77 | $updateHeaders = array( | |
78 | 'email' => 'Email', | |
79 | 'first_name' => 'First Name', | |
80 | 'last_name' => 'Last Name', | |
81 | ); | |
82 | ||
83 | // Create update mode import rows | |
84 | $updateRows = array(); | |
85 | $contact = current($rows); | |
86 | foreach ($importedContactIds as $cid) { | |
87 | $updateRows[$cid] = array( | |
88 | 'email' => $contact['email'], | |
89 | 'first_name' => substr(sha1(rand()), 0, 7), | |
90 | 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7), | |
91 | ); | |
92 | $contact = next($rows); | |
93 | } | |
94 | ||
95 | // Import and check Individual contacts in Update mode. | |
96 | $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update'); | |
97 | ||
98 | // Headers that should not updated. | |
99 | $fillHeaders = $updateHeaders; | |
100 | ||
101 | // Headers that should fill. | |
102 | $fillHeaders['gender'] = 'Gender'; | |
103 | $fillHeaders['dob'] = 'Birth Date'; | |
104 | ||
105 | $fillRows = array(); | |
106 | foreach ($importedContactIds as $cid) { | |
107 | $fillRows[$cid] = array( | |
108 | 'email' => $updateRows[$cid]['email'], | |
109 | // should not update | |
110 | 'first_name' => substr(sha1(rand()), 0, 7), | |
111 | // should not update | |
112 | 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7), | |
113 | 'gender' => 'Male', | |
114 | 'dob' => '1986-04-16', | |
115 | ); | |
116 | } | |
117 | ||
118 | // Import and check Individual contacts in Fill mode. | |
119 | $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill'); | |
120 | ||
121 | foreach ($importedContactIds as $cid) { | |
071a6d2e | 122 | $this->openCiviPage("contact/view", "reset=1&cid={$cid}"); |
6a488035 TO |
123 | |
124 | // Check old display name. | |
125 | $displayName = "{$updateRows[$cid]['first_name']} {$updateRows[$cid]['last_name']}"; | |
126 | $this->assertTrue($this->isTextPresent("$displayName"), 'Contact display name should not update in fill mode!'); | |
127 | ||
128 | $this->verifyText('css=div.crm-contact-gender_display', preg_quote($fillRows[$cid]['gender'])); | |
129 | } | |
130 | ||
131 | // Recreate same conacts using 'No Duplicate Checking' | |
132 | $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking'); | |
133 | } | |
134 | ||
135 | /* | |
136 | * Test contact import for Organization Duplicate Matching. | |
137 | */ | |
138 | function testOrganizationDuplicateMatchingImport() { | |
6a488035 TO |
139 | $this->webtestLogin(); |
140 | ||
141 | //create oranization | |
42daf119 | 142 | $this->openCiviPage("contact/add", "reset=1&ct=Organization", 'organization_name'); |
6a488035 TO |
143 | |
144 | // get value for organization contact | |
145 | $organizationName = 'org_' . substr(sha1(rand()), 0, 7); | |
146 | $organizationEmail = substr(sha1(rand()), 0, 7) . '@example.org'; | |
147 | ||
148 | $this->click('organization_name'); | |
149 | ||
150 | //fill in first name | |
151 | $this->type('organization_name', $organizationName); | |
152 | ||
153 | //fill in Email | |
154 | $this->type('email_1_email', $organizationEmail); | |
155 | ||
156 | // Clicking save. | |
157 | $this->click('_qf_Contact_upload_view'); | |
158 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
159 | ||
160 | // Reset Organization strict dedupe rule for Organization name | |
161 | // and Organization email (default) | |
162 | $this->webtestStrictDedupeRuleDefault('Organization'); | |
163 | ||
164 | $organizationFields = array( | |
165 | 'organization_name' => $organizationName, | |
166 | 'email' => $organizationEmail, | |
167 | ); | |
168 | // Get sample import data. | |
169 | list($headers, $rows) = $this->_organizationDuplicateMatchingCSVData($organizationFields); | |
170 | ||
171 | // Import and check Individual contacts in Skip mode. | |
172 | $other = array('callbackImportSummary' => 'checkDuplicateContacts'); | |
173 | $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other); | |
174 | ||
175 | // Get imported contact Ids | |
176 | $importedContactIds = $this->_getImportedContactIds($rows, 'Organization'); | |
177 | ||
6a488035 TO |
178 | // Build update mode import headers |
179 | $updateHeaders = array( | |
180 | 'email' => 'Email', | |
181 | 'organization_name' => 'Organization Name', | |
182 | ); | |
183 | ||
184 | // Create update mode import rows | |
185 | $updateRows = array(); | |
186 | $contact = current($rows); | |
187 | foreach ($importedContactIds as $cid) { | |
188 | $updateRows[$cid] = array( | |
189 | 'email' => $contact['email'], | |
190 | 'organization_name' => 'UpdatedOrg ' . substr(sha1(rand()), 0, 7), | |
191 | ); | |
192 | $contact = next($rows); | |
193 | } | |
194 | ||
195 | // Import and check Individual contacts in Update mode. | |
196 | $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update'); | |
197 | ||
198 | // Headers that should not updated. | |
199 | $fillHeaders = $updateHeaders; | |
200 | ||
201 | // Headers that should fill. | |
202 | $fillHeaders['legal_name'] = 'Legal Name'; | |
203 | ||
204 | $fillRows = array(); | |
205 | foreach ($importedContactIds as $cid) { | |
206 | $fillRows[$cid] = array( | |
207 | 'email' => $updateRows[$cid]['email'], | |
208 | // should not update | |
209 | 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7), | |
210 | 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7), | |
211 | ); | |
212 | } | |
213 | ||
214 | // Import and check Individual contacts in Fill mode. | |
215 | $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill'); | |
216 | ||
217 | foreach ($importedContactIds as $cid) { | |
071a6d2e | 218 | $this->openCiviPage("contact/view", "reset=1&cid={$cid}"); |
6a488035 TO |
219 | |
220 | // Check old Organization name. | |
221 | $organizationName = $updateRows[$cid]['organization_name']; | |
222 | $this->assertTrue($this->isTextPresent("$organizationName"), 'Contact should not update in fill mode!'); | |
223 | $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[3]/div[2]", preg_quote($fillRows[$cid]['legal_name'])); | |
224 | } | |
225 | ||
226 | // Recreate same conacts using 'No Duplicate Checking' | |
227 | $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking'); | |
228 | } | |
229 | ||
230 | /* | |
231 | * Test contact import for Household Duplicate Matching. | |
232 | */ | |
233 | function testHouseholdDuplicateMatchingImport() { | |
6a488035 TO |
234 | $this->webtestLogin(); |
235 | ||
236 | // create household | |
42daf119 | 237 | $this->openCiviPage("contact/add", "reset=1&ct=Household", 'household_name'); |
6a488035 TO |
238 | |
239 | // get values for household contact | |
240 | $householdName = 'household_' . substr(sha1(rand()), 0, 7); | |
241 | $householdEmail = substr(sha1(rand()), 0, 7) . '@example.com'; | |
242 | ||
243 | //fill in household name | |
244 | $this->type('household_name', $householdName); | |
245 | ||
246 | //fill in Email | |
247 | $this->type('email_1_email', $householdEmail); | |
248 | ||
249 | // Clicking save. | |
250 | $this->click('_qf_Contact_upload_view'); | |
251 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
252 | ||
253 | // Reset Household strict dedupe rule for Household name | |
254 | // and Household email (default) | |
255 | $this->webtestStrictDedupeRuleDefault('Household'); | |
256 | ||
257 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
258 | ||
259 | // Store household contact value in array | |
260 | $householdFields = array( | |
261 | 'household_name' => $householdName, | |
262 | 'email' => $householdEmail, | |
263 | ); | |
264 | ||
265 | // Get sample import data. | |
266 | list($headers, $rows) = $this->_householdDuplicateMatchingCSVData($householdFields); | |
267 | ||
268 | // Import and check Individual contacts in Skip mode. | |
269 | $other = array('callbackImportSummary' => 'checkDuplicateContacts'); | |
270 | $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other); | |
271 | ||
272 | // Get imported contact Ids | |
273 | $importedContactIds = $this->_getImportedContactIds($rows, 'Household'); | |
274 | ||
275 | // Build update mode import headers | |
276 | $updateHeaders = array( | |
277 | 'email' => 'Email', | |
278 | 'household_name' => 'Household Name', | |
279 | ); | |
280 | ||
281 | // Create update mode import rows | |
282 | $updateRows = array(); | |
283 | $contact = current($rows); | |
284 | foreach ($importedContactIds as $cid) { | |
285 | $updateRows[$cid] = array( | |
286 | 'email' => $contact['email'], | |
287 | 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7), | |
288 | ); | |
289 | $contact = next($rows); | |
290 | } | |
291 | ||
292 | $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update'); | |
293 | ||
294 | // Headers that should not updated. | |
295 | $fillHeaders = $updateHeaders; | |
296 | ||
297 | // Headers that should fill. | |
298 | $fillHeaders['nick_name'] = 'Nick Name'; | |
299 | ||
300 | $fillRows = array(); | |
301 | foreach ($importedContactIds as $cid) { | |
302 | $fillRows[$cid] = array( | |
303 | 'email' => $updateRows[$cid]['email'], | |
304 | // should not update | |
305 | 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7), | |
306 | 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7), | |
307 | ); | |
308 | } | |
309 | ||
310 | // Import and check Individual contacts in Fill mode. | |
311 | $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill'); | |
312 | ||
313 | foreach ($importedContactIds as $cid) { | |
071a6d2e | 314 | $this->openCiviPage("contact/view", "reset=1&cid={$cid}"); |
6a488035 TO |
315 | |
316 | // Check old Household name. | |
317 | $householdName = $updateRows[$cid]['household_name']; | |
318 | $this->assertTrue($this->isTextPresent("$householdName"), 'Contact should not update in fill mode!'); | |
319 | $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[2]/div[2]", preg_quote($fillRows[$cid]['nick_name'])); | |
320 | } | |
321 | ||
322 | // Recreate same conacts using 'No Duplicate Checking' | |
323 | $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking'); | |
324 | } | |
325 | ||
326 | function checkDuplicateContacts($originalHeaders, $originalRows, $checkSummary) { | |
327 | $this->assertTrue($this->isTextPresent('CiviCRM has detected one record which is a duplicate of existing CiviCRM contact record. These records have not been imported.')); | |
328 | ||
329 | $checkSummary = array( | |
330 | 'Total Rows' => '2', | |
331 | 'Duplicate Rows' => '1', | |
332 | 'Total Contacts' => '1', | |
333 | ); | |
334 | ||
335 | foreach ($checkSummary as $label => $value) { | |
336 | $this->verifyText("xpath=//table[@id='summary-counts']/tbody/tr/td[text()='{$label}']/following-sibling::td", preg_quote($value)); | |
337 | } | |
338 | } | |
339 | ||
340 | /* | |
341 | * Helper function to provide data for contact import for | |
342 | * Individual Duplicate Matching. | |
343 | */ | |
344 | function _individualDuplicateMatchingCSVData($individualFields) { | |
345 | $headers = array( | |
346 | 'first_name' => 'First Name', | |
347 | 'middle_name' => 'Middle Name', | |
348 | 'last_name' => 'Last Name', | |
349 | 'email' => 'Email', | |
350 | 'phone' => 'Phone', | |
351 | 'address_1' => 'Additional Address 1', | |
352 | 'address_2' => 'Additional Address 2', | |
353 | 'city' => 'City', | |
354 | 'state' => 'State', | |
355 | 'country' => 'Country', | |
356 | ); | |
357 | ||
358 | $rows = array( | |
359 | array('first_name' => isset($individualFields['first_name']) ? $individualFields['first_name'] : substr(sha1(rand()), 0, 7), | |
360 | 'middle_name' => isset($individualFields['middle_name']) ? $individualFields['middle_name'] : substr(sha1(rand()), 0, 7), | |
361 | 'last_name' => isset($individualFields['last_name']) ? $individualFields['last_name'] : 'Anderson', | |
362 | 'email' => isset($individualFields['email']) ? $individualFields['email'] : substr(sha1(rand()), 0, 7) . '@example.com', | |
363 | 'phone' => '6949912154', | |
364 | 'address_1' => 'Add 1', | |
365 | 'address_2' => 'Add 2', | |
366 | 'city' => 'Watson', | |
367 | 'state' => 'NY', | |
368 | 'country' => 'United States', | |
369 | ), | |
370 | array('first_name' => substr(sha1(rand()), 0, 7), | |
371 | 'middle_name' => substr(sha1(rand()), 0, 7), | |
372 | 'last_name' => 'Summerson', | |
373 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', | |
374 | 'phone' => '6944412154', | |
375 | 'address_1' => 'Add 1', | |
376 | 'address_2' => 'Add 2', | |
377 | 'city' => 'Watson', | |
378 | 'state' => 'NY', | |
379 | 'country' => 'United States', | |
380 | ), | |
381 | ); | |
382 | ||
383 | return array($headers, $rows); | |
384 | } | |
385 | ||
386 | /* | |
387 | * Helper function to provide data for contact import for | |
388 | * Organizations Duplicate Matching. | |
389 | */ | |
390 | function _organizationDuplicateMatchingCSVData($organizationFields) { | |
391 | $headers = array( | |
392 | 'organization_name' => 'Organization Name', | |
393 | 'email' => 'Email', | |
394 | 'phone' => 'Phone', | |
395 | 'address_1' => 'Additional Address 1', | |
396 | 'address_2' => 'Additional Address 2', | |
397 | 'city' => 'City', | |
398 | 'state' => 'State', | |
399 | 'country' => 'Country', | |
400 | ); | |
401 | $rows = array( | |
402 | array('organization_name' => isset($organizationFields['organization_name']) ? $organizationFields['organization_name'] : 'org_' . substr(sha1(rand()), 0, 7), | |
403 | 'email' => isset($organizationFields['email']) ? $organizationFields['email'] : substr(sha1(rand()), 0, 7) . 'example.org', | |
404 | 'phone' => '9949912154', | |
405 | 'address_1' => 'Add 1', | |
406 | 'address_2' => 'Add 2', | |
407 | 'city' => 'Watson', | |
408 | 'state' => 'NY', | |
409 | 'country' => 'United States', | |
410 | ), | |
411 | array('organization_name' => 'org_' . substr(sha1(rand()), 0, 7), | |
412 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', | |
413 | 'phone' => '6949412154', | |
414 | 'address_1' => 'Add 1', | |
415 | 'address_2' => 'Add 2', | |
416 | 'city' => 'Watson', | |
417 | 'state' => 'NY', | |
418 | 'country' => 'United States', | |
419 | ), | |
420 | ); | |
421 | ||
422 | return array($headers, $rows); | |
423 | } | |
424 | ||
425 | /* | |
426 | * Helper function to provide data for contact import for Household | |
427 | * Duplicate Matching. | |
428 | */ | |
429 | function _householdDuplicateMatchingCSVData($householdFields) { | |
430 | $headers = array( | |
431 | 'household_name' => 'Household Name', | |
432 | 'email' => 'Email', | |
433 | 'phone' => 'Phone', | |
434 | 'address_1' => 'Additional Address 1', | |
435 | 'address_2' => 'Additional Address 2', | |
436 | 'city' => 'City', | |
437 | 'state' => 'State', | |
438 | 'country' => 'Country', | |
439 | ); | |
440 | ||
441 | $rows = array( | |
442 | array('household_name' => isset($householdFields['household_name']) ? $householdFields['household_name'] : 'household_' . substr(sha1(rand()), 0, 7), | |
443 | 'email' => isset($householdFields['email']) ? $householdFields['email'] : substr(sha1(rand()), 0, 7) . '@example.com', | |
444 | 'phone' => '3949912154', | |
445 | 'address_1' => 'Add 1', | |
446 | 'address_2' => 'Add 2', | |
447 | 'city' => 'Watson', | |
448 | 'state' => 'NY', | |
449 | 'country' => 'United States', | |
450 | ), | |
451 | array('household_name' => 'household_' . substr(sha1(rand()), 0, 7), | |
452 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', | |
453 | 'phone' => '5949412154', | |
454 | 'address_1' => 'Add 1', | |
455 | 'address_2' => 'Add 2', | |
456 | 'city' => 'Watson', | |
457 | 'state' => 'NY', | |
458 | 'country' => 'United States', | |
459 | ), | |
460 | ); | |
461 | ||
462 | return array($headers, $rows); | |
463 | } | |
464 | } | |
465 |