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_ContactTest
extends ImportCiviSeleniumTestCase
{
30 protected function setUp() {
35 * Test contact import for Individuals.
37 function testIndividualImport() {
38 $this->webtestLogin();
40 // Get sample import data.
41 list($headers, $rows) = $this->_individualCSVData();
43 // Import and check Individual contacts in Skip mode.
45 'saveMapping' => TRUE,
46 'createGroup' => TRUE,
50 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
52 // Get imported contact Ids
53 $importedContactIds = $this->_getImportedContactIds($rows);
55 // Build update mode import headers
56 $updateHeaders = array(
57 'contact_id' => 'Internal Contact ID',
58 'first_name' => 'First Name',
59 'last_name' => 'Last Name',
62 // Create update mode import rows
63 $updateRows = array();
64 foreach ($importedContactIds as $cid) {
65 $updateRows[$cid] = array(
67 'first_name' => substr(sha1(rand()), 0, 7),
68 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
72 // Import and check Individual contacts in Update mode.
73 $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update');
75 // Visit contacts to check updated data.
76 foreach ($updateRows as $updatedRow) {
77 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
79 $displayName = "{$updatedRow['first_name']} {$updatedRow['last_name']}";
80 $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not update!");
83 // Headers that should not updated.
84 $fillHeaders = $updateHeaders;
86 // Headers that should fill.
87 $fillHeaders['gender'] = 'Gender';
88 $fillHeaders['dob'] = 'Birth Date';
91 foreach ($importedContactIds as $cid) {
92 $fillRows[$cid] = array(
95 'first_name' => substr(sha1(rand()), 0, 7),
97 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
99 'dob' => '1986-04-16',
103 // Import and check Individual contacts in Update mode.
104 $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill');
106 // Visit contacts to check filled data.
107 foreach ($fillRows as $cid => $fillRow) {
108 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
110 // Check old display name.
111 $displayName = "{$updateRows[$cid]['first_name']} {$updateRows[$cid]['last_name']}";
112 $this->assertTrue($this->isTextPresent("$displayName"), "Contact display name should not update in fill mode!");
114 $this->verifyText("css=div#contact-summary div.crm-contact-gender_display", preg_quote($fillRow['gender']));
117 // Recreate same conacts using 'No Duplicate Checking'
118 $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking');
122 * Test contact import for Organization.
124 function testOrganizationImport() {
126 $this->webtestLogin();
128 // Get sample import data.
129 list($headers, $rows) = $this->_organizationCSVData();
131 // Import and check Organization contacts
133 'saveMapping' => TRUE,
134 'createGroup' => TRUE,
138 $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other);
140 // Get imported contact Ids
141 $importedContactIds = $this->_getImportedContactIds($rows, 'Organization');
143 // Build update mode import headers
144 $updateHeaders = array(
145 'contact_id' => 'Internal Contact ID',
146 'organization_name' => 'Organization Name',
149 // Create update mode import rows
150 $updateRows = array();
151 foreach ($importedContactIds as $cid) {
152 $updateRows[$cid] = array(
153 'contact_id' => $cid,
154 'organization_name' => 'UpdatedOrg ' . substr(sha1(rand()), 0, 7),
158 // Import and check Individual contacts in Update mode.
159 $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update');
161 // Visit contacts to check updated data.
162 foreach ($updateRows as $updatedRow) {
163 $organizationName = $updatedRow['organization_name'];
164 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
166 $this->assertTrue($this->isTextPresent("$organizationName"), "Contact did not update!");
169 // Headers that should not updated.
170 $fillHeaders = $updateHeaders;
172 // Headers that should fill.
173 $fillHeaders['legal_name'] = 'Legal Name';
176 foreach ($importedContactIds as $cid) {
177 $fillRows[$cid] = array(
178 'contact_id' => $cid,
180 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7),
181 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7),
185 // Import and check Individual contacts in Update mode.
186 $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill');
188 // Visit contacts to check filled data.
189 foreach ($fillRows as $cid => $fillRow) {
190 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
192 // Check old Organization name.
193 $organizationName = $updateRows[$cid]['organization_name'];
194 $this->assertTrue($this->isTextPresent("$organizationName"), "Contact should not update in fill mode!");
195 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[3]/div[2]", preg_quote($fillRow['legal_name']));
198 // Recreate same conacts using 'No Duplicate Checking'
199 $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking');
203 * Test contact import for Household.
205 function testHouseholdImport() {
207 $this->webtestLogin();
209 // Get sample import data.
210 list($headers, $rows) = $this->_householdCSVData();
212 // Import and check Household contacts
214 'saveMapping' => TRUE,
215 'createGroup' => TRUE,
219 $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other);
221 // Get imported contact Ids
222 $importedContactIds = $this->_getImportedContactIds($rows, 'Household');
224 // Build update mode import headers
225 $updateHeaders = array(
226 'contact_id' => 'Internal Contact ID',
227 'household_name' => 'Household Name',
230 // Create update mode import rows
231 $updateRows = array();
232 foreach ($importedContactIds as $cid) {
233 $updateRows[$cid] = array(
234 'contact_id' => $cid,
235 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
239 // Import and check Individual contacts in Update mode.
240 $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update');
242 // Visit contacts to check updated data.
243 foreach ($updateRows as $updatedRow) {
244 $householdName = $updatedRow['household_name'];
245 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
247 $this->assertTrue($this->isTextPresent("$householdName"), "Contact did not update!");
250 // Headers that should not updated.
251 $fillHeaders = $updateHeaders;
253 // Headers that should fill.
254 $fillHeaders['nick_name'] = 'Nick Name';
257 foreach ($importedContactIds as $cid) {
258 $fillRows[$cid] = array(
259 'contact_id' => $cid,
261 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
262 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7),
266 // Import and check Individual contacts in Update mode.
267 $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill');
269 // Visit contacts to check filled data.
270 foreach ($fillRows as $cid => $fillRow) {
271 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
273 // Check old Household name.
274 $householdName = $updateRows[$cid]['household_name'];
275 $this->assertTrue($this->isTextPresent("$householdName"), "Contact should not update in fill mode!");
276 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[2]/div[2]", preg_quote($fillRow['nick_name']));
279 // Recreate same conacts using 'No Duplicate Checking'
280 $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking');
284 * Helper function to provide data for contact import for Individuals.
286 function _individualCSVData() {
288 'first_name' => 'First Name',
289 'middle_name' => 'Middle Name',
290 'last_name' => 'Last Name',
293 'address_1' => 'Additional Address 1',
294 'address_2' => 'Additional Address 2',
297 'country' => 'Country',
301 array('first_name' => substr(sha1(rand()), 0, 7),
302 'middle_name' => substr(sha1(rand()), 0, 7),
303 'last_name' => 'Anderson',
304 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
305 'phone' => '6949912154',
306 'address_1' => 'Add 1',
307 'address_2' => 'Add 2',
310 'country' => 'United States',
312 array('first_name' => substr(sha1(rand()), 0, 7),
313 'middle_name' => substr(sha1(rand()), 0, 7),
314 'last_name' => 'Summerson',
315 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
316 'phone' => '6944412154',
317 'address_1' => 'Add 1',
318 'address_2' => 'Add 2',
321 'country' => 'United States',
325 return array($headers, $rows);
329 * Helper function to provide data for contact import for Organizations.
331 function _organizationCSVData() {
333 'organization_name' => 'Organization Name',
336 'address_1' => 'Additional Address 1',
337 'address_2' => 'Additional Address 2',
340 'country' => 'Country',
344 array('organization_name' => 'org_' . substr(sha1(rand()), 0, 7),
345 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
346 'phone' => '9949912154',
347 'address_1' => 'Add 1',
348 'address_2' => 'Add 2',
351 'country' => 'United States',
353 array('organization_name' => 'org_' . substr(sha1(rand()), 0, 7),
354 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
355 'phone' => '6949412154',
356 'address_1' => 'Add 1',
357 'address_2' => 'Add 2',
360 'country' => 'United States',
364 return array($headers, $rows);
368 * Helper function to provide data for contact import for Household.
370 function _householdCSVData() {
372 'household_name' => 'Household Name',
375 'address_1' => 'Additional Address 1',
376 'address_2' => 'Additional Address 2',
379 'country' => 'Country',
383 array('household_name' => 'household_' . substr(sha1(rand()), 0, 7),
384 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
385 'phone' => '3949912154',
386 'address_1' => 'Add 1',
387 'address_2' => 'Add 2',
390 'country' => 'United States',
392 array('household_name' => 'household_' . substr(sha1(rand()), 0, 7),
393 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
394 'phone' => '5949412154',
395 'address_1' => 'Add 1',
396 'address_2' => 'Add 2',
399 'country' => 'United States',
403 return array($headers, $rows);