3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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_ContactTest
32 class WebTest_Import_ContactTest
extends ImportCiviSeleniumTestCase
{
34 protected function setUp() {
39 * Test contact import for Individuals.
41 function testIndividualImport() {
42 $this->webtestLogin();
44 // Get sample import data.
45 list($headers, $rows) = $this->_individualCSVData();
47 // Import and check Individual contacts in Skip mode.
49 'saveMapping' => TRUE,
50 'createGroup' => TRUE,
54 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
56 // Get imported contact Ids
57 $importedContactIds = $this->_getImportedContactIds($rows);
59 // Build update mode import headers
60 $updateHeaders = array(
61 'contact_id' => 'Internal Contact ID',
62 'first_name' => 'First Name',
63 'last_name' => 'Last Name',
66 // Create update mode import rows
67 $updateRows = array();
68 foreach ($importedContactIds as $cid) {
69 $updateRows[$cid] = array(
71 'first_name' => substr(sha1(rand()), 0, 7),
72 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
76 // Import and check Individual contacts in Update mode.
77 $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update');
79 // Visit contacts to check updated data.
80 foreach ($updateRows as $updatedRow) {
81 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
83 $displayName = "{$updatedRow['first_name']} {$updatedRow['last_name']}";
84 $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not update!");
87 // Headers that should not updated.
88 $fillHeaders = $updateHeaders;
90 // Headers that should fill.
91 $fillHeaders['gender'] = 'Gender';
92 $fillHeaders['dob'] = 'Birth Date';
95 foreach ($importedContactIds as $cid) {
96 $fillRows[$cid] = array(
99 'first_name' => substr(sha1(rand()), 0, 7),
101 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
103 'dob' => '1986-04-16',
107 // Import and check Individual contacts in Update mode.
108 $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill');
110 // Visit contacts to check filled data.
111 foreach ($fillRows as $cid => $fillRow) {
112 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
114 // Check old display name.
115 $displayName = "{$updateRows[$cid]['first_name']} {$updateRows[$cid]['last_name']}";
116 $this->assertTrue($this->isTextPresent("$displayName"), "Contact display name should not update in fill mode!");
118 $this->verifyText("css=div#contact-summary div.crm-contact-gender_display", preg_quote($fillRow['gender']));
121 // Recreate same conacts using 'No Duplicate Checking'
122 $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking');
126 * Test contact import for Organization.
128 function testOrganizationImport() {
130 $this->webtestLogin();
132 // Get sample import data.
133 list($headers, $rows) = $this->_organizationCSVData();
135 // Import and check Organization contacts
137 'saveMapping' => TRUE,
138 'createGroup' => TRUE,
142 $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other);
144 // Get imported contact Ids
145 $importedContactIds = $this->_getImportedContactIds($rows, 'Organization');
147 // Build update mode import headers
148 $updateHeaders = array(
149 'contact_id' => 'Internal Contact ID',
150 'organization_name' => 'Organization Name',
153 // Create update mode import rows
154 $updateRows = array();
155 foreach ($importedContactIds as $cid) {
156 $updateRows[$cid] = array(
157 'contact_id' => $cid,
158 'organization_name' => 'UpdatedOrg ' . substr(sha1(rand()), 0, 7),
162 // Import and check Individual contacts in Update mode.
163 $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update');
165 // Visit contacts to check updated data.
166 foreach ($updateRows as $updatedRow) {
167 $organizationName = $updatedRow['organization_name'];
168 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
170 $this->assertTrue($this->isTextPresent("$organizationName"), "Contact did not update!");
173 // Headers that should not updated.
174 $fillHeaders = $updateHeaders;
176 // Headers that should fill.
177 $fillHeaders['legal_name'] = 'Legal Name';
180 foreach ($importedContactIds as $cid) {
181 $fillRows[$cid] = array(
182 'contact_id' => $cid,
184 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7),
185 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7),
189 // Import and check Individual contacts in Update mode.
190 $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill');
192 // Visit contacts to check filled data.
193 foreach ($fillRows as $cid => $fillRow) {
194 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
196 // Check old Organization name.
197 $organizationName = $updateRows[$cid]['organization_name'];
198 $this->assertTrue($this->isTextPresent("$organizationName"), "Contact should not update in fill mode!");
199 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[3]/div[2]", preg_quote($fillRow['legal_name']));
202 // Recreate same conacts using 'No Duplicate Checking'
203 $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking');
207 * Test contact import for Household.
209 function testHouseholdImport() {
211 $this->webtestLogin();
213 // Get sample import data.
214 list($headers, $rows) = $this->_householdCSVData();
216 // Import and check Household contacts
218 'saveMapping' => TRUE,
219 'createGroup' => TRUE,
223 $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other);
225 // Get imported contact Ids
226 $importedContactIds = $this->_getImportedContactIds($rows, 'Household');
228 // Build update mode import headers
229 $updateHeaders = array(
230 'contact_id' => 'Internal Contact ID',
231 'household_name' => 'Household Name',
234 // Create update mode import rows
235 $updateRows = array();
236 foreach ($importedContactIds as $cid) {
237 $updateRows[$cid] = array(
238 'contact_id' => $cid,
239 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
243 // Import and check Individual contacts in Update mode.
244 $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update');
246 // Visit contacts to check updated data.
247 foreach ($updateRows as $updatedRow) {
248 $householdName = $updatedRow['household_name'];
249 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
251 $this->assertTrue($this->isTextPresent("$householdName"), "Contact did not update!");
254 // Headers that should not updated.
255 $fillHeaders = $updateHeaders;
257 // Headers that should fill.
258 $fillHeaders['nick_name'] = 'Nick Name';
261 foreach ($importedContactIds as $cid) {
262 $fillRows[$cid] = array(
263 'contact_id' => $cid,
265 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
266 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7),
270 // Import and check Individual contacts in Update mode.
271 $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill');
273 // Visit contacts to check filled data.
274 foreach ($fillRows as $cid => $fillRow) {
275 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
277 // Check old Household name.
278 $householdName = $updateRows[$cid]['household_name'];
279 $this->assertTrue($this->isTextPresent("$householdName"), "Contact should not update in fill mode!");
280 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[2]/div[2]", preg_quote($fillRow['nick_name']));
283 // Recreate same conacts using 'No Duplicate Checking'
284 $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking');
288 * Helper function to provide data for contact import for Individuals.
293 function _individualCSVData() {
295 'first_name' => 'First Name',
296 'middle_name' => 'Middle Name',
297 'last_name' => 'Last Name',
300 'address_1' => 'Additional Address 1',
301 'address_2' => 'Additional Address 2',
304 'country' => 'Country',
308 array('first_name' => substr(sha1(rand()), 0, 7),
309 'middle_name' => substr(sha1(rand()), 0, 7),
310 'last_name' => 'Anderson',
311 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
312 'phone' => '6949912154',
313 'address_1' => 'Add 1',
314 'address_2' => 'Add 2',
317 'country' => 'United States',
319 array('first_name' => substr(sha1(rand()), 0, 7),
320 'middle_name' => substr(sha1(rand()), 0, 7),
321 'last_name' => 'Summerson',
322 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
323 'phone' => '6944412154',
324 'address_1' => 'Add 1',
325 'address_2' => 'Add 2',
328 'country' => 'United States',
332 return array($headers, $rows);
336 * Helper function to provide data for contact import for Organizations.
341 function _organizationCSVData() {
343 'organization_name' => 'Organization Name',
346 'address_1' => 'Additional Address 1',
347 'address_2' => 'Additional Address 2',
350 'country' => 'Country',
354 array('organization_name' => 'org_' . substr(sha1(rand()), 0, 7),
355 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
356 'phone' => '9949912154',
357 'address_1' => 'Add 1',
358 'address_2' => 'Add 2',
361 'country' => 'United States',
363 array('organization_name' => 'org_' . substr(sha1(rand()), 0, 7),
364 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
365 'phone' => '6949412154',
366 'address_1' => 'Add 1',
367 'address_2' => 'Add 2',
370 'country' => 'United States',
374 return array($headers, $rows);
378 * Helper function to provide data for contact import for Household.
383 function _householdCSVData() {
385 'household_name' => 'Household Name',
388 'address_1' => 'Additional Address 1',
389 'address_2' => 'Additional Address 2',
392 'country' => 'Country',
396 array('household_name' => 'household_' . substr(sha1(rand()), 0, 7),
397 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
398 'phone' => '3949912154',
399 'address_1' => 'Add 1',
400 'address_2' => 'Add 2',
403 'country' => 'United States',
405 array('household_name' => 'household_' . substr(sha1(rand()), 0, 7),
406 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
407 'phone' => '5949412154',
408 'address_1' => 'Add 1',
409 'address_2' => 'Add 2',
412 'country' => 'United States',
416 return array($headers, $rows);