3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 +--------------------------------------------------------------------+
28 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
29 class WebTest_Import_DuplicateMatchingTest
extends ImportCiviSeleniumTestCase
{
31 protected function setUp() {
36 * Test contact import for Individuals Duplicate Matching.
38 function testIndividualDuplicateMatchingImport() {
39 // This is the path where our testing install resides.
40 // The rest of URL is defined in CiviSeleniumTestCase base class, in
42 $this->open($this->sboxPath
);
44 // Logging in. Remember to wait for page to load. In most cases,
45 // you can rely on 30000 as the value that allows your test to pass, however,
46 // sometimes your test might fail because of this. In such cases, it's better to pick one element
47 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
48 // page contents loaded and you can continue your test execution.
49 $this->webtestLogin();
51 // Go directly to the URL of New Individual.
52 $this->open($this->sboxPath
. 'civicrm/contact/add?reset=1&ct=Individual');
53 $this->waitForElementPresent('first_name');
55 $email = substr(sha1(rand()), 0, 7) . '@example.com';
58 $firstName = substr(sha1(rand()), 0, 7);
59 $this->type('first_name', $firstName);
62 $lastName = substr(sha1(rand()), 0, 7);
63 $this->type('last_name', $lastName);
66 $this->type('email_1_email', $email);
69 $this->click('_qf_Contact_upload_view');
70 $this->waitForPageToLoad($this->getTimeoutMsec());
71 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
73 $existingContact = array(
74 'first_name' => $firstName,
75 'last_name' => $lastName,
79 // Get sample import data.
80 list($headers, $rows) = $this->_individualDuplicateMatchingCSVData($existingContact);
82 // Import and check Individual contacts in Skip mode.
83 $other = array('callbackImportSummary' => 'checkDuplicateContacts');
84 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
86 // Get imported contact Ids
87 $importedContactIds = $this->_getImportedContactIds($rows);
89 // Build update mode import headers
90 $updateHeaders = array(
92 'first_name' => 'First Name',
93 'last_name' => 'Last Name',
96 // Create update mode import rows
97 $updateRows = array();
98 $contact = current($rows);
99 foreach ($importedContactIds as $cid) {
100 $updateRows[$cid] = array(
101 'email' => $contact['email'],
102 'first_name' => substr(sha1(rand()), 0, 7),
103 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
105 $contact = next($rows);
108 // Import and check Individual contacts in Update mode.
109 $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update');
111 // Headers that should not updated.
112 $fillHeaders = $updateHeaders;
114 // Headers that should fill.
115 $fillHeaders['gender'] = 'Gender';
116 $fillHeaders['dob'] = 'Birth Date';
119 foreach ($importedContactIds as $cid) {
120 $fillRows[$cid] = array(
121 'email' => $updateRows[$cid]['email'],
123 'first_name' => substr(sha1(rand()), 0, 7),
125 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
127 'dob' => '1986-04-16',
131 // Import and check Individual contacts in Fill mode.
132 $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill');
134 foreach ($importedContactIds as $cid) {
135 $this->open($this->sboxPath
. "civicrm/contact/view?reset=1&cid={$cid}");
136 $this->waitForPageToLoad($this->getTimeoutMsec());
138 // Check old display name.
139 $displayName = "{$updateRows[$cid]['first_name']} {$updateRows[$cid]['last_name']}";
140 $this->assertTrue($this->isTextPresent("$displayName"), 'Contact display name should not update in fill mode!');
142 $this->verifyText('css=div.crm-contact-gender_display', preg_quote($fillRows[$cid]['gender']));
145 // Recreate same conacts using 'No Duplicate Checking'
146 $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking');
150 * Test contact import for Organization Duplicate Matching.
152 function testOrganizationDuplicateMatchingImport() {
153 // This is the path where our testing install resides.
154 // The rest of URL is defined in CiviSeleniumTestCase base class, in
156 $this->open($this->sboxPath
);
158 // Logging in. Remember to wait for page to load. In most cases,
159 // you can rely on 30000 as the value that allows your test to pass, however,
160 // sometimes your test might fail because of this. In such cases, it's better to pick one element
161 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
162 // page contents loaded and you can continue your test execution.
163 $this->webtestLogin();
166 $this->open($this->sboxPath
. 'civicrm/contact/add?reset=1&ct=Organization');
167 $this->waitForElementPresent('organization_name');
169 // get value for organization contact
170 $organizationName = 'org_' . substr(sha1(rand()), 0, 7);
171 $organizationEmail = substr(sha1(rand()), 0, 7) . '@example.org';
173 $this->click('organization_name');
176 $this->type('organization_name', $organizationName);
179 $this->type('email_1_email', $organizationEmail);
182 $this->click('_qf_Contact_upload_view');
183 $this->waitForPageToLoad($this->getTimeoutMsec());
185 // Reset Organization strict dedupe rule for Organization name
186 // and Organization email (default)
187 $this->webtestStrictDedupeRuleDefault('Organization');
189 $organizationFields = array(
190 'organization_name' => $organizationName,
191 'email' => $organizationEmail,
193 // Get sample import data.
194 list($headers, $rows) = $this->_organizationDuplicateMatchingCSVData($organizationFields);
196 // Import and check Individual contacts in Skip mode.
197 $other = array('callbackImportSummary' => 'checkDuplicateContacts');
198 $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other);
200 // Get imported contact Ids
201 $importedContactIds = $this->_getImportedContactIds($rows, 'Organization');
204 // Build update mode import headers
205 $updateHeaders = array(
207 'organization_name' => 'Organization Name',
210 // Create update mode import rows
211 $updateRows = array();
212 $contact = current($rows);
213 foreach ($importedContactIds as $cid) {
214 $updateRows[$cid] = array(
215 'email' => $contact['email'],
216 'organization_name' => 'UpdatedOrg ' . substr(sha1(rand()), 0, 7),
218 $contact = next($rows);
221 // Import and check Individual contacts in Update mode.
222 $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update');
224 // Headers that should not updated.
225 $fillHeaders = $updateHeaders;
227 // Headers that should fill.
228 $fillHeaders['legal_name'] = 'Legal Name';
231 foreach ($importedContactIds as $cid) {
232 $fillRows[$cid] = array(
233 'email' => $updateRows[$cid]['email'],
235 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7),
236 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7),
240 // Import and check Individual contacts in Fill mode.
241 $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill');
243 foreach ($importedContactIds as $cid) {
244 $this->open($this->sboxPath
. "civicrm/contact/view?reset=1&cid={$cid}");
245 $this->waitForPageToLoad($this->getTimeoutMsec());
247 // Check old Organization name.
248 $organizationName = $updateRows[$cid]['organization_name'];
249 $this->assertTrue($this->isTextPresent("$organizationName"), 'Contact should not update in fill mode!');
250 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[3]/div[2]", preg_quote($fillRows[$cid]['legal_name']));
253 // Recreate same conacts using 'No Duplicate Checking'
254 $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking');
258 * Test contact import for Household Duplicate Matching.
260 function testHouseholdDuplicateMatchingImport() {
261 // This is the path where our testing install resides.
262 // The rest of URL is defined in CiviSeleniumTestCase base class, in
264 $this->open($this->sboxPath
);
266 // Logging in. Remember to wait for page to load. In most cases,
267 // you can rely on 30000 as the value that allows your test to pass, however,
268 // sometimes your test might fail because of this. In such cases, it's better to pick one element
269 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
270 // page contents loaded and you can continue your test execution.
271 $this->webtestLogin();
274 $this->open($this->sboxPath
. 'civicrm/contact/add?reset=1&ct=Household');
275 $this->waitForElementPresent('household_name');
277 // get values for household contact
278 $householdName = 'household_' . substr(sha1(rand()), 0, 7);
279 $householdEmail = substr(sha1(rand()), 0, 7) . '@example.com';
281 //fill in household name
282 $this->type('household_name', $householdName);
285 $this->type('email_1_email', $householdEmail);
288 $this->click('_qf_Contact_upload_view');
289 $this->waitForPageToLoad($this->getTimeoutMsec());
291 // Reset Household strict dedupe rule for Household name
292 // and Household email (default)
293 $this->webtestStrictDedupeRuleDefault('Household');
295 $this->waitForPageToLoad($this->getTimeoutMsec());
297 // Store household contact value in array
298 $householdFields = array(
299 'household_name' => $householdName,
300 'email' => $householdEmail,
303 // Get sample import data.
304 list($headers, $rows) = $this->_householdDuplicateMatchingCSVData($householdFields);
306 // Import and check Individual contacts in Skip mode.
307 $other = array('callbackImportSummary' => 'checkDuplicateContacts');
308 $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other);
310 // Get imported contact Ids
311 $importedContactIds = $this->_getImportedContactIds($rows, 'Household');
313 // Build update mode import headers
314 $updateHeaders = array(
316 'household_name' => 'Household Name',
319 // Create update mode import rows
320 $updateRows = array();
321 $contact = current($rows);
322 foreach ($importedContactIds as $cid) {
323 $updateRows[$cid] = array(
324 'email' => $contact['email'],
325 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
327 $contact = next($rows);
330 $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update');
332 // Headers that should not updated.
333 $fillHeaders = $updateHeaders;
335 // Headers that should fill.
336 $fillHeaders['nick_name'] = 'Nick Name';
339 foreach ($importedContactIds as $cid) {
340 $fillRows[$cid] = array(
341 'email' => $updateRows[$cid]['email'],
343 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
344 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7),
348 // Import and check Individual contacts in Fill mode.
349 $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill');
351 foreach ($importedContactIds as $cid) {
352 $this->open($this->sboxPath
. "civicrm/contact/view?reset=1&cid={$cid}");
353 $this->waitForPageToLoad($this->getTimeoutMsec());
355 // Check old Household name.
356 $householdName = $updateRows[$cid]['household_name'];
357 $this->assertTrue($this->isTextPresent("$householdName"), 'Contact should not update in fill mode!');
358 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[2]/div[2]", preg_quote($fillRows[$cid]['nick_name']));
361 // Recreate same conacts using 'No Duplicate Checking'
362 $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking');
365 function checkDuplicateContacts($originalHeaders, $originalRows, $checkSummary) {
366 $this->assertTrue($this->isTextPresent('CiviCRM has detected one record which is a duplicate of existing CiviCRM contact record. These records have not been imported.'));
368 $checkSummary = array(
370 'Duplicate Rows' => '1',
371 'Total Contacts' => '1',
374 foreach ($checkSummary as $label => $value) {
375 $this->verifyText("xpath=//table[@id='summary-counts']/tbody/tr/td[text()='{$label}']/following-sibling::td", preg_quote($value));
380 * Helper function to provide data for contact import for
381 * Individual Duplicate Matching.
383 function _individualDuplicateMatchingCSVData($individualFields) {
385 'first_name' => 'First Name',
386 'middle_name' => 'Middle Name',
387 'last_name' => 'Last Name',
390 'address_1' => 'Additional Address 1',
391 'address_2' => 'Additional Address 2',
394 'country' => 'Country',
398 array('first_name' => isset($individualFields['first_name']) ?
$individualFields['first_name'] : substr(sha1(rand()), 0, 7),
399 'middle_name' => isset($individualFields['middle_name']) ?
$individualFields['middle_name'] : substr(sha1(rand()), 0, 7),
400 'last_name' => isset($individualFields['last_name']) ?
$individualFields['last_name'] : 'Anderson',
401 'email' => isset($individualFields['email']) ?
$individualFields['email'] : substr(sha1(rand()), 0, 7) . '@example.com',
402 'phone' => '6949912154',
403 'address_1' => 'Add 1',
404 'address_2' => 'Add 2',
407 'country' => 'United States',
409 array('first_name' => substr(sha1(rand()), 0, 7),
410 'middle_name' => substr(sha1(rand()), 0, 7),
411 'last_name' => 'Summerson',
412 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
413 'phone' => '6944412154',
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
427 * Organizations Duplicate Matching.
429 function _organizationDuplicateMatchingCSVData($organizationFields) {
431 'organization_name' => 'Organization Name',
434 'address_1' => 'Additional Address 1',
435 'address_2' => 'Additional Address 2',
438 'country' => 'Country',
441 array('organization_name' => isset($organizationFields['organization_name']) ?
$organizationFields['organization_name'] : 'org_' . substr(sha1(rand()), 0, 7),
442 'email' => isset($organizationFields['email']) ?
$organizationFields['email'] : substr(sha1(rand()), 0, 7) . 'example.org',
443 'phone' => '9949912154',
444 'address_1' => 'Add 1',
445 'address_2' => 'Add 2',
448 'country' => 'United States',
450 array('organization_name' => 'org_' . substr(sha1(rand()), 0, 7),
451 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
452 'phone' => '6949412154',
453 'address_1' => 'Add 1',
454 'address_2' => 'Add 2',
457 'country' => 'United States',
461 return array($headers, $rows);
465 * Helper function to provide data for contact import for Household
466 * Duplicate Matching.
468 function _householdDuplicateMatchingCSVData($householdFields) {
470 'household_name' => 'Household Name',
473 'address_1' => 'Additional Address 1',
474 'address_2' => 'Additional Address 2',
477 'country' => 'Country',
481 array('household_name' => isset($householdFields['household_name']) ?
$householdFields['household_name'] : 'household_' . substr(sha1(rand()), 0, 7),
482 'email' => isset($householdFields['email']) ?
$householdFields['email'] : substr(sha1(rand()), 0, 7) . '@example.com',
483 'phone' => '3949912154',
484 'address_1' => 'Add 1',
485 'address_2' => 'Add 2',
488 'country' => 'United States',
490 array('household_name' => 'household_' . substr(sha1(rand()), 0, 7),
491 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
492 'phone' => '5949412154',
493 'address_1' => 'Add 1',
494 'address_2' => 'Add 2',
497 'country' => 'United States',
501 return array($headers, $rows);