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_ContactTest
extends ImportCiviSeleniumTestCase
{
31 protected $captureScreenshotOnFailure = TRUE;
32 protected $screenshotPath = '/var/www/api.dev.civicrm.org/public/sc';
33 protected $screenshotUrl = 'http://api.dev.civicrm.org/sc/';
35 protected function setUp() {
40 * Test contact import for Individuals.
42 function testIndividualImport() {
43 $this->webtestLogin();
45 // Get sample import data.
46 list($headers, $rows) = $this->_individualCSVData();
48 // Import and check Individual contacts in Skip mode.
50 'saveMapping' => TRUE,
51 'createGroup' => TRUE,
55 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
57 // Get imported contact Ids
58 $importedContactIds = $this->_getImportedContactIds($rows);
60 // Build update mode import headers
61 $updateHeaders = array(
62 'contact_id' => 'Internal Contact ID',
63 'first_name' => 'First Name',
64 'last_name' => 'Last Name',
67 // Create update mode import rows
68 $updateRows = array();
69 foreach ($importedContactIds as $cid) {
70 $updateRows[$cid] = array(
72 'first_name' => substr(sha1(rand()), 0, 7),
73 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
77 // Import and check Individual contacts in Update mode.
78 $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update');
80 // Visit contacts to check updated data.
81 foreach ($updateRows as $updatedRow) {
82 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
84 $displayName = "{$updatedRow['first_name']} {$updatedRow['last_name']}";
85 $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not update!");
88 // Headers that should not updated.
89 $fillHeaders = $updateHeaders;
91 // Headers that should fill.
92 $fillHeaders['gender'] = 'Gender';
93 $fillHeaders['dob'] = 'Birth Date';
96 foreach ($importedContactIds as $cid) {
97 $fillRows[$cid] = array(
100 'first_name' => substr(sha1(rand()), 0, 7),
102 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7),
104 'dob' => '1986-04-16',
108 // Import and check Individual contacts in Update mode.
109 $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill');
111 // Visit contacts to check filled data.
112 foreach ($fillRows as $cid => $fillRow) {
113 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
115 // Check old display name.
116 $displayName = "{$updateRows[$cid]['first_name']} {$updateRows[$cid]['last_name']}";
117 $this->assertTrue($this->isTextPresent("$displayName"), "Contact display name should not update in fill mode!");
119 $this->verifyText("css=div#contact-summary div.crm-contact-gender_display", preg_quote($fillRow['gender']));
122 // Recreate same conacts using 'No Duplicate Checking'
123 $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking');
127 * Test contact import for Organization.
129 function testOrganizationImport() {
131 $this->webtestLogin();
133 // Get sample import data.
134 list($headers, $rows) = $this->_organizationCSVData();
136 // Import and check Organization contacts
138 'saveMapping' => TRUE,
139 'createGroup' => TRUE,
143 $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other);
145 // Get imported contact Ids
146 $importedContactIds = $this->_getImportedContactIds($rows, 'Organization');
148 // Build update mode import headers
149 $updateHeaders = array(
150 'contact_id' => 'Internal Contact ID',
151 'organization_name' => 'Organization Name',
154 // Create update mode import rows
155 $updateRows = array();
156 foreach ($importedContactIds as $cid) {
157 $updateRows[$cid] = array(
158 'contact_id' => $cid,
159 'organization_name' => 'UpdatedOrg ' . substr(sha1(rand()), 0, 7),
163 // Import and check Individual contacts in Update mode.
164 $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update');
166 // Visit contacts to check updated data.
167 foreach ($updateRows as $updatedRow) {
168 $organizationName = $updatedRow['organization_name'];
169 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
171 $this->assertTrue($this->isTextPresent("$organizationName"), "Contact did not update!");
174 // Headers that should not updated.
175 $fillHeaders = $updateHeaders;
177 // Headers that should fill.
178 $fillHeaders['legal_name'] = 'Legal Name';
181 foreach ($importedContactIds as $cid) {
182 $fillRows[$cid] = array(
183 'contact_id' => $cid,
185 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7),
186 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7),
190 // Import and check Individual contacts in Update mode.
191 $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill');
193 // Visit contacts to check filled data.
194 foreach ($fillRows as $cid => $fillRow) {
195 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
197 // Check old Organization name.
198 $organizationName = $updateRows[$cid]['organization_name'];
199 $this->assertTrue($this->isTextPresent("$organizationName"), "Contact should not update in fill mode!");
200 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[3]/div[2]", preg_quote($fillRow['legal_name']));
203 // Recreate same conacts using 'No Duplicate Checking'
204 $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking');
208 * Test contact import for Household.
210 function testHouseholdImport() {
212 $this->webtestLogin();
214 // Get sample import data.
215 list($headers, $rows) = $this->_householdCSVData();
217 // Import and check Household contacts
219 'saveMapping' => TRUE,
220 'createGroup' => TRUE,
224 $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other);
226 // Get imported contact Ids
227 $importedContactIds = $this->_getImportedContactIds($rows, 'Household');
229 // Build update mode import headers
230 $updateHeaders = array(
231 'contact_id' => 'Internal Contact ID',
232 'household_name' => 'Household Name',
235 // Create update mode import rows
236 $updateRows = array();
237 foreach ($importedContactIds as $cid) {
238 $updateRows[$cid] = array(
239 'contact_id' => $cid,
240 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
244 // Import and check Individual contacts in Update mode.
245 $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update');
247 // Visit contacts to check updated data.
248 foreach ($updateRows as $updatedRow) {
249 $householdName = $updatedRow['household_name'];
250 $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}");
252 $this->assertTrue($this->isTextPresent("$householdName"), "Contact did not update!");
255 // Headers that should not updated.
256 $fillHeaders = $updateHeaders;
258 // Headers that should fill.
259 $fillHeaders['nick_name'] = 'Nick Name';
262 foreach ($importedContactIds as $cid) {
263 $fillRows[$cid] = array(
264 'contact_id' => $cid,
266 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7),
267 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7),
271 // Import and check Individual contacts in Update mode.
272 $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill');
274 // Visit contacts to check filled data.
275 foreach ($fillRows as $cid => $fillRow) {
276 $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}");
278 // Check old Household name.
279 $householdName = $updateRows[$cid]['household_name'];
280 $this->assertTrue($this->isTextPresent("$householdName"), "Contact should not update in fill mode!");
281 $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[2]/div[2]", preg_quote($fillRow['nick_name']));
284 // Recreate same conacts using 'No Duplicate Checking'
285 $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking');
289 * Helper function to provide data for contact import for Individuals.
291 function _individualCSVData() {
293 'first_name' => 'First Name',
294 'middle_name' => 'Middle Name',
295 'last_name' => 'Last Name',
298 'address_1' => 'Additional Address 1',
299 'address_2' => 'Additional Address 2',
302 'country' => 'Country',
306 array('first_name' => substr(sha1(rand()), 0, 7),
307 'middle_name' => substr(sha1(rand()), 0, 7),
308 'last_name' => 'Anderson',
309 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
310 'phone' => '6949912154',
311 'address_1' => 'Add 1',
312 'address_2' => 'Add 2',
315 'country' => 'United States',
317 array('first_name' => substr(sha1(rand()), 0, 7),
318 'middle_name' => substr(sha1(rand()), 0, 7),
319 'last_name' => 'Summerson',
320 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
321 'phone' => '6944412154',
322 'address_1' => 'Add 1',
323 'address_2' => 'Add 2',
326 'country' => 'United States',
330 return array($headers, $rows);
334 * Helper function to provide data for contact import for Organizations.
336 function _organizationCSVData() {
338 'organization_name' => 'Organization Name',
341 'address_1' => 'Additional Address 1',
342 'address_2' => 'Additional Address 2',
345 'country' => 'Country',
349 array('organization_name' => 'org_' . substr(sha1(rand()), 0, 7),
350 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
351 'phone' => '9949912154',
352 'address_1' => 'Add 1',
353 'address_2' => 'Add 2',
356 'country' => 'United States',
358 array('organization_name' => 'org_' . substr(sha1(rand()), 0, 7),
359 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
360 'phone' => '6949412154',
361 'address_1' => 'Add 1',
362 'address_2' => 'Add 2',
365 'country' => 'United States',
369 return array($headers, $rows);
373 * Helper function to provide data for contact import for Household.
375 function _householdCSVData() {
377 'household_name' => 'Household Name',
380 'address_1' => 'Additional Address 1',
381 'address_2' => 'Additional Address 2',
384 'country' => 'Country',
388 array('household_name' => 'household_' . substr(sha1(rand()), 0, 7),
389 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
390 'phone' => '3949912154',
391 'address_1' => 'Add 1',
392 'address_2' => 'Add 2',
395 'country' => 'United States',
397 array('household_name' => 'household_' . substr(sha1(rand()), 0, 7),
398 'email' => substr(sha1(rand()), 0, 7) . '@example.org',
399 'phone' => '5949412154',
400 'address_1' => 'Add 1',
401 'address_2' => 'Add 2',
404 'country' => 'United States',
408 return array($headers, $rows);