Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
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 | 27 | require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Import_ContactTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Import_ContactTest extends ImportCiviSeleniumTestCase { |
33 | ||
6a488035 TO |
34 | protected function setUp() { |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | /* | |
39 | * Test contact import for Individuals. | |
40 | */ | |
00be9182 | 41 | public function testIndividualImport() { |
6a488035 TO |
42 | $this->webtestLogin(); |
43 | ||
44 | // Get sample import data. | |
45 | list($headers, $rows) = $this->_individualCSVData(); | |
46 | ||
47 | // Import and check Individual contacts in Skip mode. | |
48 | $other = array( | |
49 | 'saveMapping' => TRUE, | |
50 | 'createGroup' => TRUE, | |
51 | 'createTag' => TRUE, | |
52 | ); | |
53 | ||
54 | $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other); | |
55 | ||
56 | // Get imported contact Ids | |
57 | $importedContactIds = $this->_getImportedContactIds($rows); | |
58 | ||
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', | |
64 | ); | |
65 | ||
66 | // Create update mode import rows | |
67 | $updateRows = array(); | |
68 | foreach ($importedContactIds as $cid) { | |
69 | $updateRows[$cid] = array( | |
70 | 'contact_id' => $cid, | |
71 | 'first_name' => substr(sha1(rand()), 0, 7), | |
72 | 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7), | |
73 | ); | |
74 | } | |
75 | ||
76 | // Import and check Individual contacts in Update mode. | |
77 | $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update'); | |
78 | ||
79 | // Visit contacts to check updated data. | |
80 | foreach ($updateRows as $updatedRow) { | |
071a6d2e | 81 | $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}"); |
6a488035 TO |
82 | |
83 | $displayName = "{$updatedRow['first_name']} {$updatedRow['last_name']}"; | |
84 | $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not update!"); | |
85 | } | |
86 | ||
87 | // Headers that should not updated. | |
88 | $fillHeaders = $updateHeaders; | |
89 | ||
90 | // Headers that should fill. | |
91 | $fillHeaders['gender'] = 'Gender'; | |
92 | $fillHeaders['dob'] = 'Birth Date'; | |
93 | ||
94 | $fillRows = array(); | |
95 | foreach ($importedContactIds as $cid) { | |
96 | $fillRows[$cid] = array( | |
97 | 'contact_id' => $cid, | |
98 | // should not update | |
99 | 'first_name' => substr(sha1(rand()), 0, 7), | |
100 | // should not update | |
101 | 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7), | |
102 | 'gender' => 'Male', | |
103 | 'dob' => '1986-04-16', | |
104 | ); | |
105 | } | |
106 | ||
107 | // Import and check Individual contacts in Update mode. | |
108 | $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill'); | |
109 | ||
110 | // Visit contacts to check filled data. | |
111 | foreach ($fillRows as $cid => $fillRow) { | |
071a6d2e | 112 | $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}"); |
6a488035 TO |
113 | |
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!"); | |
117 | ||
118 | $this->verifyText("css=div#contact-summary div.crm-contact-gender_display", preg_quote($fillRow['gender'])); | |
119 | } | |
120 | ||
121 | // Recreate same conacts using 'No Duplicate Checking' | |
122 | $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking'); | |
123 | } | |
124 | ||
125 | /* | |
126 | * Test contact import for Organization. | |
127 | */ | |
00be9182 | 128 | public function testOrganizationImport() { |
6a488035 TO |
129 | |
130 | $this->webtestLogin(); | |
131 | ||
132 | // Get sample import data. | |
133 | list($headers, $rows) = $this->_organizationCSVData(); | |
134 | ||
135 | // Import and check Organization contacts | |
136 | $other = array( | |
137 | 'saveMapping' => TRUE, | |
138 | 'createGroup' => TRUE, | |
139 | 'createTag' => TRUE, | |
140 | ); | |
141 | ||
142 | $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other); | |
143 | ||
144 | // Get imported contact Ids | |
145 | $importedContactIds = $this->_getImportedContactIds($rows, 'Organization'); | |
146 | ||
147 | // Build update mode import headers | |
148 | $updateHeaders = array( | |
149 | 'contact_id' => 'Internal Contact ID', | |
150 | 'organization_name' => 'Organization Name', | |
151 | ); | |
152 | ||
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), | |
159 | ); | |
160 | } | |
161 | ||
162 | // Import and check Individual contacts in Update mode. | |
163 | $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update'); | |
164 | ||
165 | // Visit contacts to check updated data. | |
166 | foreach ($updateRows as $updatedRow) { | |
167 | $organizationName = $updatedRow['organization_name']; | |
071a6d2e | 168 | $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}"); |
6a488035 TO |
169 | |
170 | $this->assertTrue($this->isTextPresent("$organizationName"), "Contact did not update!"); | |
171 | } | |
172 | ||
173 | // Headers that should not updated. | |
174 | $fillHeaders = $updateHeaders; | |
175 | ||
176 | // Headers that should fill. | |
177 | $fillHeaders['legal_name'] = 'Legal Name'; | |
178 | ||
179 | $fillRows = array(); | |
180 | foreach ($importedContactIds as $cid) { | |
181 | $fillRows[$cid] = array( | |
182 | 'contact_id' => $cid, | |
183 | // should not update | |
184 | 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7), | |
185 | 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7), | |
186 | ); | |
187 | } | |
188 | ||
189 | // Import and check Individual contacts in Update mode. | |
190 | $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill'); | |
191 | ||
192 | // Visit contacts to check filled data. | |
193 | foreach ($fillRows as $cid => $fillRow) { | |
071a6d2e | 194 | $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}"); |
6a488035 TO |
195 | |
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'])); | |
200 | } | |
201 | ||
202 | // Recreate same conacts using 'No Duplicate Checking' | |
203 | $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking'); | |
204 | } | |
205 | ||
206 | /* | |
207 | * Test contact import for Household. | |
208 | */ | |
00be9182 | 209 | public function testHouseholdImport() { |
6a488035 TO |
210 | |
211 | $this->webtestLogin(); | |
212 | ||
213 | // Get sample import data. | |
214 | list($headers, $rows) = $this->_householdCSVData(); | |
215 | ||
216 | // Import and check Household contacts | |
217 | $other = array( | |
218 | 'saveMapping' => TRUE, | |
219 | 'createGroup' => TRUE, | |
220 | 'createTag' => TRUE, | |
221 | ); | |
222 | ||
223 | $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other); | |
224 | ||
225 | // Get imported contact Ids | |
226 | $importedContactIds = $this->_getImportedContactIds($rows, 'Household'); | |
227 | ||
228 | // Build update mode import headers | |
229 | $updateHeaders = array( | |
230 | 'contact_id' => 'Internal Contact ID', | |
231 | 'household_name' => 'Household Name', | |
232 | ); | |
233 | ||
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), | |
240 | ); | |
241 | } | |
242 | ||
243 | // Import and check Individual contacts in Update mode. | |
244 | $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update'); | |
245 | ||
246 | // Visit contacts to check updated data. | |
247 | foreach ($updateRows as $updatedRow) { | |
248 | $householdName = $updatedRow['household_name']; | |
071a6d2e | 249 | $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}"); |
6a488035 TO |
250 | |
251 | $this->assertTrue($this->isTextPresent("$householdName"), "Contact did not update!"); | |
252 | } | |
253 | ||
254 | // Headers that should not updated. | |
255 | $fillHeaders = $updateHeaders; | |
256 | ||
257 | // Headers that should fill. | |
258 | $fillHeaders['nick_name'] = 'Nick Name'; | |
259 | ||
260 | $fillRows = array(); | |
261 | foreach ($importedContactIds as $cid) { | |
262 | $fillRows[$cid] = array( | |
263 | 'contact_id' => $cid, | |
264 | // should not update | |
265 | 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7), | |
266 | 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7), | |
267 | ); | |
268 | } | |
269 | ||
270 | // Import and check Individual contacts in Update mode. | |
271 | $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill'); | |
272 | ||
273 | // Visit contacts to check filled data. | |
274 | foreach ($fillRows as $cid => $fillRow) { | |
071a6d2e | 275 | $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}"); |
6a488035 TO |
276 | |
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'])); | |
281 | } | |
282 | ||
283 | // Recreate same conacts using 'No Duplicate Checking' | |
284 | $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking'); | |
285 | } | |
286 | ||
287 | /* | |
288 | * Helper function to provide data for contact import for Individuals. | |
289 | */ | |
4cbe18b8 EM |
290 | /** |
291 | * @return array | |
292 | */ | |
00be9182 | 293 | public function _individualCSVData() { |
6a488035 TO |
294 | $headers = array( |
295 | 'first_name' => 'First Name', | |
296 | 'middle_name' => 'Middle Name', | |
297 | 'last_name' => 'Last Name', | |
298 | 'email' => 'Email', | |
299 | 'phone' => 'Phone', | |
300 | 'address_1' => 'Additional Address 1', | |
301 | 'address_2' => 'Additional Address 2', | |
302 | 'city' => 'City', | |
303 | 'state' => 'State', | |
304 | 'country' => 'Country', | |
305 | ); | |
306 | ||
307 | $rows = array( | |
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', | |
315 | 'city' => 'Watson', | |
316 | 'state' => 'NY', | |
317 | 'country' => 'United States', | |
318 | ), | |
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', | |
326 | 'city' => 'Watson', | |
327 | 'state' => 'NY', | |
328 | 'country' => 'United States', | |
329 | ), | |
330 | ); | |
331 | ||
332 | return array($headers, $rows); | |
333 | } | |
334 | ||
335 | /* | |
336 | * Helper function to provide data for contact import for Organizations. | |
337 | */ | |
4cbe18b8 EM |
338 | /** |
339 | * @return array | |
340 | */ | |
00be9182 | 341 | public function _organizationCSVData() { |
6a488035 TO |
342 | $headers = array( |
343 | 'organization_name' => 'Organization Name', | |
344 | 'email' => 'Email', | |
345 | 'phone' => 'Phone', | |
346 | 'address_1' => 'Additional Address 1', | |
347 | 'address_2' => 'Additional Address 2', | |
348 | 'city' => 'City', | |
349 | 'state' => 'State', | |
350 | 'country' => 'Country', | |
351 | ); | |
352 | ||
353 | $rows = array( | |
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', | |
359 | 'city' => 'Watson', | |
360 | 'state' => 'NY', | |
361 | 'country' => 'United States', | |
362 | ), | |
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', | |
368 | 'city' => 'Watson', | |
369 | 'state' => 'NY', | |
370 | 'country' => 'United States', | |
371 | ), | |
372 | ); | |
373 | ||
374 | return array($headers, $rows); | |
375 | } | |
376 | ||
377 | /* | |
378 | * Helper function to provide data for contact import for Household. | |
379 | */ | |
4cbe18b8 EM |
380 | /** |
381 | * @return array | |
382 | */ | |
00be9182 | 383 | public function _householdCSVData() { |
6a488035 TO |
384 | $headers = array( |
385 | 'household_name' => 'Household Name', | |
386 | 'email' => 'Email', | |
387 | 'phone' => 'Phone', | |
388 | 'address_1' => 'Additional Address 1', | |
389 | 'address_2' => 'Additional Address 2', | |
390 | 'city' => 'City', | |
391 | 'state' => 'State', | |
392 | 'country' => 'Country', | |
393 | ); | |
394 | ||
395 | $rows = array( | |
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', | |
401 | 'city' => 'Watson', | |
402 | 'state' => 'NY', | |
403 | 'country' => 'United States', | |
404 | ), | |
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', | |
410 | 'city' => 'Watson', | |
411 | 'state' => 'NY', | |
412 | 'country' => 'United States', | |
413 | ), | |
414 | ); | |
415 | ||
416 | return array($headers, $rows); | |
417 | } | |
418 | } | |
419 |