3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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';
30 * Class WebTest_Import_DuplicateMatchingTest
32 class WebTest_Import_DuplicateMatchingTest
extends ImportCiviSeleniumTestCase
{
34 protected function setUp() {
39 * Test contact import for Individuals Duplicate Matching.
41 public function testIndividualDuplicateMatchingImport() {
42 $this->webtestLogin();
44 $this->openCiviPage("contact/add", "reset=1&ct=Individual", 'first_name');
46 $email = substr(sha1(rand()), 0, 7) . '@example.com';
49 $firstName = substr(sha1(rand()), 0, 7);
50 $this->type('first_name', $firstName);
53 $lastName = substr(sha1(rand()), 0, 7);
54 $this->type('last_name', $lastName);
57 $this->type('email_1_email', $email);
60 $this->click('_qf_Contact_upload_view');
61 $this->waitForPageToLoad($this->getTimeoutMsec());
62 $this->waitForText('crm-notification-container', "Contact Saved");
64 $existingContact = array(
65 'first_name' => $firstName,
66 'last_name' => $lastName,
70 // Get sample import data.
71 list($headers, $rows) = $this->_individualDuplicateMatchingCSVData($existingContact);
73 // Import and check Individual contacts in Skip mode.
74 $other = array('callbackImportSummary' => 'checkDuplicateContacts');
75 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
77 // Get imported contact Ids
78 $importedContactIds = $this->_getImportedContactIds($rows);
80 // Build update mode import headers
81 $updateHeaders = array(
83 'first_name' => 'First Name',
84 'last_name' => 'Last Name',
87 // Create update mode import rows
88 $updateRows = array();
89 $contact = current($rows);
90 foreach ($importedContactIds as $cid) {
91 $updateRows[$cid] = array(
92 'email' => $contact['email'],
93 'first_name' => substr(sha1(rand()), 0, 7),
94 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
96 $contact = next($rows);
99 // Import and check Individual contacts in Update mode.
100 $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update');
102 // Headers that should not updated.
103 $fillHeaders = $updateHeaders;
105 // Headers that should fill.
106 $fillHeaders['gender'] = 'Gender';
107 $fillHeaders['dob'] = 'Birth Date';
110 foreach ($importedContactIds as $cid) {
111 $fillRows[$cid] = array(
112 'email' => $updateRows[$cid]['email'],
114 'first_name' => substr(sha1(rand()), 0, 7),
116 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
118 'dob' => '1986-04-16',
122 // Import and check Individual contacts in Fill mode.
123 $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill');
125 foreach ($importedContactIds as $cid) {
126 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
128 // Check old display name.
129 $displayName = "{$updateRows[$cid]['first_name']} {$updateRows[$cid]['last_name']}";
130 $this->assertTrue($this->isTextPresent("$displayName"), 'Contact display name should not update in fill mode!');
132 $this->verifyText('css=div.crm-contact-gender_display', preg_quote($fillRows[$cid]['gender']));
135 // Recreate same conacts using 'No Duplicate Checking'
136 $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking');
140 * Test contact import for Organization Duplicate Matching.
142 public function testOrganizationDuplicateMatchingImport() {
143 $this->webtestLogin();
146 $this->openCiviPage("contact/add", "reset=1&ct=Organization", 'organization_name');
148 // get value for organization contact
149 $organizationName = 'org_' . substr(sha1(rand()), 0, 7);
150 $organizationEmail = substr(sha1(rand()), 0, 7) . '@example.org';
152 $this->click('organization_name');
155 $this->type('organization_name', $organizationName);
158 $this->type('email_1_email', $organizationEmail);
161 $this->click('_qf_Contact_upload_view');
162 $this->waitForPageToLoad($this->getTimeoutMsec());
164 // Reset Organization strict dedupe rule for Organization name
165 // and Organization email (default)
166 $this->webtestStrictDedupeRuleDefault('Organization');
168 $organizationFields = array(
169 'organization_name' => $organizationName,
170 'email' => $organizationEmail,
172 // Get sample import data.
173 list($headers, $rows) = $this->_organizationDuplicateMatchingCSVData($organizationFields);
175 // Import and check Individual contacts in Skip mode.
176 $other = array('callbackImportSummary' => 'checkDuplicateContacts');
177 $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other);
179 // Get imported contact Ids
180 $importedContactIds = $this->_getImportedContactIds($rows, 'Organization');
182 // Build update mode import headers
183 $updateHeaders = array(
185 'organization_name' => 'Organization Name',
188 // Create update mode import rows
189 $updateRows = array();
190 $contact = current($rows);
191 foreach ($importedContactIds as $cid) {
192 $updateRows[$cid] = array(
193 'email' => $contact['email'],
194 'organization_name' => 'UpdatedOrg ' . substr(sha1(rand()), 0, 7),
196 $contact = next($rows);
199 // Import and check Individual contacts in Update mode.
200 $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update');
202 // Headers that should not updated.
203 $fillHeaders = $updateHeaders;
205 // Headers that should fill.
206 $fillHeaders['legal_name'] = 'Legal Name';
209 foreach ($importedContactIds as $cid) {
210 $fillRows[$cid] = array(
211 'email' => $updateRows[$cid]['email'],
213 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7),
214 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7),
218 // Import and check Individual contacts in Fill mode.
219 $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill');
221 foreach ($importedContactIds as $cid) {
222 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
224 // Check old Organization name.
225 $organizationName = $updateRows[$cid]['organization_name'];
226 $this->assertTrue($this->isTextPresent("$organizationName"), 'Contact should not update in fill mode!');
227 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[3]/div[2]", preg_quote($fillRows[$cid]['legal_name']));
230 // Recreate same conacts using 'No Duplicate Checking'
231 $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking');
235 * Test contact import for Household Duplicate Matching.
237 public function testHouseholdDuplicateMatchingImport() {
238 $this->webtestLogin();
241 $this->openCiviPage("contact/add", "reset=1&ct=Household", 'household_name');
243 // get values for household contact
244 $householdName = 'household_' . substr(sha1(rand()), 0, 7);
245 $householdEmail = substr(sha1(rand()), 0, 7) . '@example.com';
247 //fill in household name
248 $this->type('household_name', $householdName);
251 $this->type('email_1_email', $householdEmail);
254 $this->click('_qf_Contact_upload_view');
255 $this->waitForPageToLoad($this->getTimeoutMsec());
257 // Reset Household strict dedupe rule for Household name
258 // and Household email (default)
259 $this->webtestStrictDedupeRuleDefault('Household');
261 $this->waitForPageToLoad($this->getTimeoutMsec());
263 // Store household contact value in array
264 $householdFields = array(
265 'household_name' => $householdName,
266 'email' => $householdEmail,
269 // Get sample import data.
270 list($headers, $rows) = $this->_householdDuplicateMatchingCSVData($householdFields);
272 // Import and check Individual contacts in Skip mode.
273 $other = array('callbackImportSummary' => 'checkDuplicateContacts');
274 $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other);
276 // Get imported contact Ids
277 $importedContactIds = $this->_getImportedContactIds($rows, 'Household');
279 // Build update mode import headers
280 $updateHeaders = array(
282 'household_name' => 'Household Name',
285 // Create update mode import rows
286 $updateRows = array();
287 $contact = current($rows);
288 foreach ($importedContactIds as $cid) {
289 $updateRows[$cid] = array(
290 'email' => $contact['email'],
291 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
293 $contact = next($rows);
296 $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update');
298 // Headers that should not updated.
299 $fillHeaders = $updateHeaders;
301 // Headers that should fill.
302 $fillHeaders['nick_name'] = 'Nick Name';
305 foreach ($importedContactIds as $cid) {
306 $fillRows[$cid] = array(
307 'email' => $updateRows[$cid]['email'],
309 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
310 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7),
314 // Import and check Individual contacts in Fill mode.
315 $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill');
317 foreach ($importedContactIds as $cid) {
318 $this->openCiviPage("contact/view", "reset=1&cid={$cid}");
320 // Check old Household name.
321 $householdName = $updateRows[$cid]['household_name'];
322 $this->assertTrue($this->isTextPresent("$householdName"), 'Contact should not update in fill mode!');
323 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[2]/div[2]", preg_quote($fillRows[$cid]['nick_name']));
326 // Recreate same conacts using 'No Duplicate Checking'
327 $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking');
331 * @param $originalHeaders
332 * @param $originalRows
333 * @param $checkSummary
335 public function checkDuplicateContacts($originalHeaders, $originalRows, $checkSummary) {
336 $this->assertTrue($this->isTextPresent('CiviCRM has detected one record which is a duplicate of existing CiviCRM contact record. These records have not been imported.'));
338 $checkSummary = array(
340 'Duplicate Rows' => '1',
341 'Total Contacts' => '1',
344 foreach ($checkSummary as $label => $value) {
345 $this->verifyText("xpath=//table[@id='summary-counts']/tbody/tr/td[text()='{$label}']/following-sibling::td", preg_quote($value));
350 * Helper function to provide data for contact import for
351 * Individual Duplicate Matching.
354 * @param $individualFields
358 public function _individualDuplicateMatchingCSVData($individualFields) {
360 'first_name' => 'First Name',
361 'middle_name' => 'Middle Name',
362 'last_name' => 'Last Name',
365 'address_1' => 'Additional Address 1',
366 'address_2' => 'Additional Address 2',
369 'country' => 'Country',
374 'first_name' => isset($individualFields['first_name']) ?
$individualFields['first_name'] : substr(sha1(rand()), 0, 7),
375 'middle_name' => isset($individualFields['middle_name']) ?
$individualFields['middle_name'] : substr(sha1(rand()), 0, 7),
376 'last_name' => isset($individualFields['last_name']) ?
$individualFields['last_name'] : 'Anderson',
377 'email' => isset($individualFields['email']) ?
$individualFields['email'] : substr(sha1(rand()), 0, 7) . '@example.com',
378 'phone' => '6949912154',
379 'address_1' => 'Add 1',
380 'address_2' => 'Add 2',
383 'country' => 'UNITED STATES',
386 'first_name' => substr(sha1(rand()), 0, 7),
387 'middle_name' => substr(sha1(rand()), 0, 7),
388 'last_name' => 'Summerson',
389 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
390 'phone' => '6944412154',
391 'address_1' => 'Add 1',
392 'address_2' => 'Add 2',
395 'country' => 'UNITED STATES',
399 return array($headers, $rows);
403 * Helper function to provide data for contact import for
404 * Organizations Duplicate Matching.
407 * @param $organizationFields
411 public function _organizationDuplicateMatchingCSVData($organizationFields) {
413 'organization_name' => 'Organization Name',
416 'address_1' => 'Additional Address 1',
417 'address_2' => 'Additional Address 2',
420 'country' => 'Country',
424 'organization_name' => isset($organizationFields['organization_name']) ?
$organizationFields['organization_name'] : 'org_' . substr(sha1(rand()), 0, 7),
425 'email' => isset($organizationFields['email']) ?
$organizationFields['email'] : substr(sha1(rand()), 0, 7) . 'example.org',
426 'phone' => '9949912154',
427 'address_1' => 'Add 1',
428 'address_2' => 'Add 2',
431 'country' => 'UNITED STATES',
434 'organization_name' => 'org_' . substr(sha1(rand()), 0, 7),
435 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
436 'phone' => '6949412154',
437 'address_1' => 'Add 1',
438 'address_2' => 'Add 2',
441 'country' => 'UNITED STATES',
445 return array($headers, $rows);
449 * Helper function to provide data for contact import for Household.
450 * Duplicate Matching.
452 * @param $householdFields
456 public function _householdDuplicateMatchingCSVData($householdFields) {
458 'household_name' => 'Household Name',
461 'address_1' => 'Additional Address 1',
462 'address_2' => 'Additional Address 2',
465 'country' => 'Country',
470 'household_name' => isset($householdFields['household_name']) ?
$householdFields['household_name'] : 'household_' . substr(sha1(rand()), 0, 7),
471 'email' => isset($householdFields['email']) ?
$householdFields['email'] : substr(sha1(rand()), 0, 7) . '@example.com',
472 'phone' => '3949912154',
473 'address_1' => 'Add 1',
474 'address_2' => 'Add 2',
477 'country' => 'UNITED STATES',
480 'household_name' => 'household_' . substr(sha1(rand()), 0, 7),
481 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
482 'phone' => '5949412154',
483 'address_1' => 'Add 1',
484 'address_2' => 'Add 2',
487 'country' => 'UNITED STATES',
491 return array($headers, $rows);