Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
25 | */ | |
26 | ||
6a488035 TO |
27 | require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php'; |
28 | class WebTest_Import_ContactTest extends ImportCiviSeleniumTestCase { | |
29 | ||
6a488035 TO |
30 | protected function setUp() { |
31 | parent::setUp(); | |
32 | } | |
33 | ||
34 | /* | |
35 | * Test contact import for Individuals. | |
36 | */ | |
37 | function testIndividualImport() { | |
6a488035 TO |
38 | $this->webtestLogin(); |
39 | ||
40 | // Get sample import data. | |
41 | list($headers, $rows) = $this->_individualCSVData(); | |
42 | ||
43 | // Import and check Individual contacts in Skip mode. | |
44 | $other = array( | |
45 | 'saveMapping' => TRUE, | |
46 | 'createGroup' => TRUE, | |
47 | 'createTag' => TRUE, | |
48 | ); | |
49 | ||
50 | $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other); | |
51 | ||
52 | // Get imported contact Ids | |
53 | $importedContactIds = $this->_getImportedContactIds($rows); | |
54 | ||
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', | |
60 | ); | |
61 | ||
62 | // Create update mode import rows | |
63 | $updateRows = array(); | |
64 | foreach ($importedContactIds as $cid) { | |
65 | $updateRows[$cid] = array( | |
66 | 'contact_id' => $cid, | |
67 | 'first_name' => substr(sha1(rand()), 0, 7), | |
68 | 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7), | |
69 | ); | |
70 | } | |
71 | ||
72 | // Import and check Individual contacts in Update mode. | |
73 | $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update'); | |
74 | ||
75 | // Visit contacts to check updated data. | |
76 | foreach ($updateRows as $updatedRow) { | |
071a6d2e | 77 | $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}"); |
6a488035 TO |
78 | |
79 | $displayName = "{$updatedRow['first_name']} {$updatedRow['last_name']}"; | |
80 | $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not update!"); | |
81 | } | |
82 | ||
83 | // Headers that should not updated. | |
84 | $fillHeaders = $updateHeaders; | |
85 | ||
86 | // Headers that should fill. | |
87 | $fillHeaders['gender'] = 'Gender'; | |
88 | $fillHeaders['dob'] = 'Birth Date'; | |
89 | ||
90 | $fillRows = array(); | |
91 | foreach ($importedContactIds as $cid) { | |
92 | $fillRows[$cid] = array( | |
93 | 'contact_id' => $cid, | |
94 | // should not update | |
95 | 'first_name' => substr(sha1(rand()), 0, 7), | |
96 | // should not update | |
97 | 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7), | |
98 | 'gender' => 'Male', | |
99 | 'dob' => '1986-04-16', | |
100 | ); | |
101 | } | |
102 | ||
103 | // Import and check Individual contacts in Update mode. | |
104 | $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill'); | |
105 | ||
106 | // Visit contacts to check filled data. | |
107 | foreach ($fillRows as $cid => $fillRow) { | |
071a6d2e | 108 | $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}"); |
6a488035 TO |
109 | |
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!"); | |
113 | ||
114 | $this->verifyText("css=div#contact-summary div.crm-contact-gender_display", preg_quote($fillRow['gender'])); | |
115 | } | |
116 | ||
117 | // Recreate same conacts using 'No Duplicate Checking' | |
118 | $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking'); | |
119 | } | |
120 | ||
121 | /* | |
122 | * Test contact import for Organization. | |
123 | */ | |
124 | function testOrganizationImport() { | |
6a488035 TO |
125 | |
126 | $this->webtestLogin(); | |
127 | ||
128 | // Get sample import data. | |
129 | list($headers, $rows) = $this->_organizationCSVData(); | |
130 | ||
131 | // Import and check Organization contacts | |
132 | $other = array( | |
133 | 'saveMapping' => TRUE, | |
134 | 'createGroup' => TRUE, | |
135 | 'createTag' => TRUE, | |
136 | ); | |
137 | ||
138 | $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other); | |
139 | ||
140 | // Get imported contact Ids | |
141 | $importedContactIds = $this->_getImportedContactIds($rows, 'Organization'); | |
142 | ||
143 | // Build update mode import headers | |
144 | $updateHeaders = array( | |
145 | 'contact_id' => 'Internal Contact ID', | |
146 | 'organization_name' => 'Organization Name', | |
147 | ); | |
148 | ||
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), | |
155 | ); | |
156 | } | |
157 | ||
158 | // Import and check Individual contacts in Update mode. | |
159 | $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update'); | |
160 | ||
161 | // Visit contacts to check updated data. | |
162 | foreach ($updateRows as $updatedRow) { | |
163 | $organizationName = $updatedRow['organization_name']; | |
071a6d2e | 164 | $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}"); |
6a488035 TO |
165 | |
166 | $this->assertTrue($this->isTextPresent("$organizationName"), "Contact did not update!"); | |
167 | } | |
168 | ||
169 | // Headers that should not updated. | |
170 | $fillHeaders = $updateHeaders; | |
171 | ||
172 | // Headers that should fill. | |
173 | $fillHeaders['legal_name'] = 'Legal Name'; | |
174 | ||
175 | $fillRows = array(); | |
176 | foreach ($importedContactIds as $cid) { | |
177 | $fillRows[$cid] = array( | |
178 | 'contact_id' => $cid, | |
179 | // should not update | |
180 | 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7), | |
181 | 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7), | |
182 | ); | |
183 | } | |
184 | ||
185 | // Import and check Individual contacts in Update mode. | |
186 | $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill'); | |
187 | ||
188 | // Visit contacts to check filled data. | |
189 | foreach ($fillRows as $cid => $fillRow) { | |
071a6d2e | 190 | $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}"); |
6a488035 TO |
191 | |
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'])); | |
196 | } | |
197 | ||
198 | // Recreate same conacts using 'No Duplicate Checking' | |
199 | $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking'); | |
200 | } | |
201 | ||
202 | /* | |
203 | * Test contact import for Household. | |
204 | */ | |
205 | function testHouseholdImport() { | |
6a488035 TO |
206 | |
207 | $this->webtestLogin(); | |
208 | ||
209 | // Get sample import data. | |
210 | list($headers, $rows) = $this->_householdCSVData(); | |
211 | ||
212 | // Import and check Household contacts | |
213 | $other = array( | |
214 | 'saveMapping' => TRUE, | |
215 | 'createGroup' => TRUE, | |
216 | 'createTag' => TRUE, | |
217 | ); | |
218 | ||
219 | $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other); | |
220 | ||
221 | // Get imported contact Ids | |
222 | $importedContactIds = $this->_getImportedContactIds($rows, 'Household'); | |
223 | ||
224 | // Build update mode import headers | |
225 | $updateHeaders = array( | |
226 | 'contact_id' => 'Internal Contact ID', | |
227 | 'household_name' => 'Household Name', | |
228 | ); | |
229 | ||
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), | |
236 | ); | |
237 | } | |
238 | ||
239 | // Import and check Individual contacts in Update mode. | |
240 | $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update'); | |
241 | ||
242 | // Visit contacts to check updated data. | |
243 | foreach ($updateRows as $updatedRow) { | |
244 | $householdName = $updatedRow['household_name']; | |
071a6d2e | 245 | $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}"); |
6a488035 TO |
246 | |
247 | $this->assertTrue($this->isTextPresent("$householdName"), "Contact did not update!"); | |
248 | } | |
249 | ||
250 | // Headers that should not updated. | |
251 | $fillHeaders = $updateHeaders; | |
252 | ||
253 | // Headers that should fill. | |
254 | $fillHeaders['nick_name'] = 'Nick Name'; | |
255 | ||
256 | $fillRows = array(); | |
257 | foreach ($importedContactIds as $cid) { | |
258 | $fillRows[$cid] = array( | |
259 | 'contact_id' => $cid, | |
260 | // should not update | |
261 | 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7), | |
262 | 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7), | |
263 | ); | |
264 | } | |
265 | ||
266 | // Import and check Individual contacts in Update mode. | |
267 | $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill'); | |
268 | ||
269 | // Visit contacts to check filled data. | |
270 | foreach ($fillRows as $cid => $fillRow) { | |
071a6d2e | 271 | $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}"); |
6a488035 TO |
272 | |
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'])); | |
277 | } | |
278 | ||
279 | // Recreate same conacts using 'No Duplicate Checking' | |
280 | $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking'); | |
281 | } | |
282 | ||
283 | /* | |
284 | * Helper function to provide data for contact import for Individuals. | |
285 | */ | |
286 | function _individualCSVData() { | |
287 | $headers = array( | |
288 | 'first_name' => 'First Name', | |
289 | 'middle_name' => 'Middle Name', | |
290 | 'last_name' => 'Last Name', | |
291 | 'email' => 'Email', | |
292 | 'phone' => 'Phone', | |
293 | 'address_1' => 'Additional Address 1', | |
294 | 'address_2' => 'Additional Address 2', | |
295 | 'city' => 'City', | |
296 | 'state' => 'State', | |
297 | 'country' => 'Country', | |
298 | ); | |
299 | ||
300 | $rows = array( | |
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', | |
308 | 'city' => 'Watson', | |
309 | 'state' => 'NY', | |
310 | 'country' => 'United States', | |
311 | ), | |
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', | |
319 | 'city' => 'Watson', | |
320 | 'state' => 'NY', | |
321 | 'country' => 'United States', | |
322 | ), | |
323 | ); | |
324 | ||
325 | return array($headers, $rows); | |
326 | } | |
327 | ||
328 | /* | |
329 | * Helper function to provide data for contact import for Organizations. | |
330 | */ | |
331 | function _organizationCSVData() { | |
332 | $headers = array( | |
333 | 'organization_name' => 'Organization Name', | |
334 | 'email' => 'Email', | |
335 | 'phone' => 'Phone', | |
336 | 'address_1' => 'Additional Address 1', | |
337 | 'address_2' => 'Additional Address 2', | |
338 | 'city' => 'City', | |
339 | 'state' => 'State', | |
340 | 'country' => 'Country', | |
341 | ); | |
342 | ||
343 | $rows = array( | |
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', | |
349 | 'city' => 'Watson', | |
350 | 'state' => 'NY', | |
351 | 'country' => 'United States', | |
352 | ), | |
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', | |
358 | 'city' => 'Watson', | |
359 | 'state' => 'NY', | |
360 | 'country' => 'United States', | |
361 | ), | |
362 | ); | |
363 | ||
364 | return array($headers, $rows); | |
365 | } | |
366 | ||
367 | /* | |
368 | * Helper function to provide data for contact import for Household. | |
369 | */ | |
370 | function _householdCSVData() { | |
371 | $headers = array( | |
372 | 'household_name' => 'Household Name', | |
373 | 'email' => 'Email', | |
374 | 'phone' => 'Phone', | |
375 | 'address_1' => 'Additional Address 1', | |
376 | 'address_2' => 'Additional Address 2', | |
377 | 'city' => 'City', | |
378 | 'state' => 'State', | |
379 | 'country' => 'Country', | |
380 | ); | |
381 | ||
382 | $rows = array( | |
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', | |
388 | 'city' => 'Watson', | |
389 | 'state' => 'NY', | |
390 | 'country' => 'United States', | |
391 | ), | |
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', | |
397 | 'city' => 'Watson', | |
398 | 'state' => 'NY', | |
399 | 'country' => 'United States', | |
400 | ), | |
401 | ); | |
402 | ||
403 | return array($headers, $rows); | |
404 | } | |
405 | } | |
406 |