3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
28 class WebTest_Import_DuplicateMatchingTest
extends ImportCiviSeleniumTestCase
{
30 protected function setUp() {
35 * Test contact import for Individuals Duplicate Matching.
37 function testIndividualDuplicateMatchingImport() {
38 $this->webtestLogin();
40 $this->openCiviPage("contact/add", "reset=1&ct=Individual", 'first_name');
42 $email = substr(sha1(rand()), 0, 7) . '@example.com';
45 $firstName = substr(sha1(rand()), 0, 7);
46 $this->type('first_name', $firstName);
49 $lastName = substr(sha1(rand()), 0, 7);
50 $this->type('last_name', $lastName);
53 $this->type('email_1_email', $email);
56 $this->click('_qf_Contact_upload_view');
57 $this->waitForPageToLoad($this->getTimeoutMsec());
58 $this->waitForText('crm-notification-container', "Contact Saved");
60 $existingContact = array(
61 'first_name' => $firstName,
62 'last_name' => $lastName,
66 // Get sample import data.
67 list($headers, $rows) = $this->_individualDuplicateMatchingCSVData($existingContact);
69 // Import and check Individual contacts in Skip mode.
70 $other = array('callbackImportSummary' => 'checkDuplicateContacts');
71 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
73 // Get imported contact Ids
74 $importedContactIds = $this->_getImportedContactIds($rows);
76 // Build update mode import headers
77 $updateHeaders = array(
79 'first_name' => 'First Name',
80 'last_name' => 'Last Name',
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),
92 $contact = next($rows);
95 // Import and check Individual contacts in Update mode.
96 $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update');
98 // Headers that should not updated.
99 $fillHeaders = $updateHeaders;
101 // Headers that should fill.
102 $fillHeaders['gender'] = 'Gender';
103 $fillHeaders['dob'] = 'Birth Date';
106 foreach ($importedContactIds as $cid) {
107 $fillRows[$cid] = array(
108 'email' => $updateRows[$cid]['email'],
110 'first_name' => substr(sha1(rand()), 0, 7),
112 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
114 'dob' => '1986-04-16',
118 // Import and check Individual contacts in Fill mode.
119 $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill');
121 foreach ($importedContactIds as $cid) {
122 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
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!');
128 $this->verifyText('css=div.crm-contact-gender_display', preg_quote($fillRows[$cid]['gender']));
131 // Recreate same conacts using 'No Duplicate Checking'
132 $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking');
136 * Test contact import for Organization Duplicate Matching.
138 function testOrganizationDuplicateMatchingImport() {
139 $this->webtestLogin();
142 $this->openCiviPage("contact/add", "reset=1&ct=Organization", 'organization_name');
144 // get value for organization contact
145 $organizationName = 'org_' . substr(sha1(rand()), 0, 7);
146 $organizationEmail = substr(sha1(rand()), 0, 7) . '@example.org';
148 $this->click('organization_name');
151 $this->type('organization_name', $organizationName);
154 $this->type('email_1_email', $organizationEmail);
157 $this->click('_qf_Contact_upload_view');
158 $this->waitForPageToLoad($this->getTimeoutMsec());
160 // Reset Organization strict dedupe rule for Organization name
161 // and Organization email (default)
162 $this->webtestStrictDedupeRuleDefault('Organization');
164 $organizationFields = array(
165 'organization_name' => $organizationName,
166 'email' => $organizationEmail,
168 // Get sample import data.
169 list($headers, $rows) = $this->_organizationDuplicateMatchingCSVData($organizationFields);
171 // Import and check Individual contacts in Skip mode.
172 $other = array('callbackImportSummary' => 'checkDuplicateContacts');
173 $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other);
175 // Get imported contact Ids
176 $importedContactIds = $this->_getImportedContactIds($rows, 'Organization');
178 // Build update mode import headers
179 $updateHeaders = array(
181 'organization_name' => 'Organization Name',
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),
192 $contact = next($rows);
195 // Import and check Individual contacts in Update mode.
196 $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update');
198 // Headers that should not updated.
199 $fillHeaders = $updateHeaders;
201 // Headers that should fill.
202 $fillHeaders['legal_name'] = 'Legal Name';
205 foreach ($importedContactIds as $cid) {
206 $fillRows[$cid] = array(
207 'email' => $updateRows[$cid]['email'],
209 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7),
210 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7),
214 // Import and check Individual contacts in Fill mode.
215 $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill');
217 foreach ($importedContactIds as $cid) {
218 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
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']));
226 // Recreate same conacts using 'No Duplicate Checking'
227 $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking');
231 * Test contact import for Household Duplicate Matching.
233 function testHouseholdDuplicateMatchingImport() {
234 $this->webtestLogin();
237 $this->openCiviPage("contact/add", "reset=1&ct=Household", 'household_name');
239 // get values for household contact
240 $householdName = 'household_' . substr(sha1(rand()), 0, 7);
241 $householdEmail = substr(sha1(rand()), 0, 7) . '@example.com';
243 //fill in household name
244 $this->type('household_name', $householdName);
247 $this->type('email_1_email', $householdEmail);
250 $this->click('_qf_Contact_upload_view');
251 $this->waitForPageToLoad($this->getTimeoutMsec());
253 // Reset Household strict dedupe rule for Household name
254 // and Household email (default)
255 $this->webtestStrictDedupeRuleDefault('Household');
257 $this->waitForPageToLoad($this->getTimeoutMsec());
259 // Store household contact value in array
260 $householdFields = array(
261 'household_name' => $householdName,
262 'email' => $householdEmail,
265 // Get sample import data.
266 list($headers, $rows) = $this->_householdDuplicateMatchingCSVData($householdFields);
268 // Import and check Individual contacts in Skip mode.
269 $other = array('callbackImportSummary' => 'checkDuplicateContacts');
270 $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other);
272 // Get imported contact Ids
273 $importedContactIds = $this->_getImportedContactIds($rows, 'Household');
275 // Build update mode import headers
276 $updateHeaders = array(
278 'household_name' => 'Household Name',
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),
289 $contact = next($rows);
292 $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update');
294 // Headers that should not updated.
295 $fillHeaders = $updateHeaders;
297 // Headers that should fill.
298 $fillHeaders['nick_name'] = 'Nick Name';
301 foreach ($importedContactIds as $cid) {
302 $fillRows[$cid] = array(
303 'email' => $updateRows[$cid]['email'],
305 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
306 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7),
310 // Import and check Individual contacts in Fill mode.
311 $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill');
313 foreach ($importedContactIds as $cid) {
314 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
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']));
322 // Recreate same conacts using 'No Duplicate Checking'
323 $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking');
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.'));
329 $checkSummary = array(
331 'Duplicate Rows' => '1',
332 'Total Contacts' => '1',
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));
341 * Helper function to provide data for contact import for
342 * Individual Duplicate Matching.
344 function _individualDuplicateMatchingCSVData($individualFields) {
346 'first_name' => 'First Name',
347 'middle_name' => 'Middle Name',
348 'last_name' => 'Last Name',
351 'address_1' => 'Additional Address 1',
352 'address_2' => 'Additional Address 2',
355 'country' => 'Country',
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',
368 'country' => 'United States',
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',
379 'country' => 'United States',
383 return array($headers, $rows);
387 * Helper function to provide data for contact import for
388 * Organizations Duplicate Matching.
390 function _organizationDuplicateMatchingCSVData($organizationFields) {
392 'organization_name' => 'Organization Name',
395 'address_1' => 'Additional Address 1',
396 'address_2' => 'Additional Address 2',
399 'country' => 'Country',
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',
409 'country' => 'United States',
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',
418 'country' => 'United States',
422 return array($headers, $rows);
426 * Helper function to provide data for contact import for Household
427 * Duplicate Matching.
429 function _householdDuplicateMatchingCSVData($householdFields) {
431 'household_name' => 'Household Name',
434 'address_1' => 'Additional Address 1',
435 'address_2' => 'Additional Address 2',
438 'country' => 'Country',
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',
449 'country' => 'United States',
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',
458 'country' => 'United States',
462 return array($headers, $rows);