Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 25 | */ |
6a488035 | 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 | ||
28a04ea9 | 38 | /** |
6a488035 TO |
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 | ||
28a04ea9 | 125 | /** |
6a488035 TO |
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 | ||
28a04ea9 | 206 | /** |
6a488035 TO |
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( | |
6c6e6187 | 308 | array( |
92915c55 | 309 | 'first_name' => substr(sha1(rand()), 0, 7), |
6a488035 TO |
310 | 'middle_name' => substr(sha1(rand()), 0, 7), |
311 | 'last_name' => 'Anderson', | |
312 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', | |
313 | 'phone' => '6949912154', | |
314 | 'address_1' => 'Add 1', | |
315 | 'address_2' => 'Add 2', | |
316 | 'city' => 'Watson', | |
317 | 'state' => 'NY', | |
86797006 | 318 | 'country' => 'UNITED STATES', |
6a488035 | 319 | ), |
6c6e6187 | 320 | array( |
92915c55 | 321 | 'first_name' => substr(sha1(rand()), 0, 7), |
6a488035 TO |
322 | 'middle_name' => substr(sha1(rand()), 0, 7), |
323 | 'last_name' => 'Summerson', | |
324 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', | |
325 | 'phone' => '6944412154', | |
326 | 'address_1' => 'Add 1', | |
327 | 'address_2' => 'Add 2', | |
328 | 'city' => 'Watson', | |
329 | 'state' => 'NY', | |
86797006 | 330 | 'country' => 'UNITED STATES', |
6a488035 TO |
331 | ), |
332 | ); | |
333 | ||
334 | return array($headers, $rows); | |
335 | } | |
336 | ||
337 | /* | |
338 | * Helper function to provide data for contact import for Organizations. | |
339 | */ | |
4cbe18b8 EM |
340 | /** |
341 | * @return array | |
342 | */ | |
00be9182 | 343 | public function _organizationCSVData() { |
6a488035 TO |
344 | $headers = array( |
345 | 'organization_name' => 'Organization Name', | |
346 | 'email' => 'Email', | |
347 | 'phone' => 'Phone', | |
348 | 'address_1' => 'Additional Address 1', | |
349 | 'address_2' => 'Additional Address 2', | |
350 | 'city' => 'City', | |
351 | 'state' => 'State', | |
352 | 'country' => 'Country', | |
353 | ); | |
354 | ||
355 | $rows = array( | |
6c6e6187 | 356 | array( |
92915c55 | 357 | 'organization_name' => 'org_' . substr(sha1(rand()), 0, 7), |
6a488035 TO |
358 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', |
359 | 'phone' => '9949912154', | |
360 | 'address_1' => 'Add 1', | |
361 | 'address_2' => 'Add 2', | |
362 | 'city' => 'Watson', | |
363 | 'state' => 'NY', | |
86797006 | 364 | 'country' => 'UNITED STATES', |
6a488035 | 365 | ), |
6c6e6187 | 366 | array( |
92915c55 | 367 | 'organization_name' => 'org_' . substr(sha1(rand()), 0, 7), |
6a488035 TO |
368 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', |
369 | 'phone' => '6949412154', | |
370 | 'address_1' => 'Add 1', | |
371 | 'address_2' => 'Add 2', | |
372 | 'city' => 'Watson', | |
373 | 'state' => 'NY', | |
86797006 | 374 | 'country' => 'UNITED STATES', |
6a488035 TO |
375 | ), |
376 | ); | |
377 | ||
378 | return array($headers, $rows); | |
379 | } | |
380 | ||
381 | /* | |
382 | * Helper function to provide data for contact import for Household. | |
383 | */ | |
4cbe18b8 EM |
384 | /** |
385 | * @return array | |
386 | */ | |
00be9182 | 387 | public function _householdCSVData() { |
6a488035 TO |
388 | $headers = array( |
389 | 'household_name' => 'Household Name', | |
390 | 'email' => 'Email', | |
391 | 'phone' => 'Phone', | |
392 | 'address_1' => 'Additional Address 1', | |
393 | 'address_2' => 'Additional Address 2', | |
394 | 'city' => 'City', | |
395 | 'state' => 'State', | |
396 | 'country' => 'Country', | |
397 | ); | |
398 | ||
399 | $rows = array( | |
6c6e6187 | 400 | array( |
92915c55 | 401 | 'household_name' => 'household_' . substr(sha1(rand()), 0, 7), |
6a488035 TO |
402 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', |
403 | 'phone' => '3949912154', | |
404 | 'address_1' => 'Add 1', | |
405 | 'address_2' => 'Add 2', | |
406 | 'city' => 'Watson', | |
407 | 'state' => 'NY', | |
86797006 | 408 | 'country' => 'UNITED STATES', |
6a488035 | 409 | ), |
6c6e6187 | 410 | array( |
92915c55 | 411 | 'household_name' => 'household_' . substr(sha1(rand()), 0, 7), |
6a488035 TO |
412 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', |
413 | 'phone' => '5949412154', | |
414 | 'address_1' => 'Add 1', | |
415 | 'address_2' => 'Add 2', | |
416 | 'city' => 'Watson', | |
417 | 'state' => 'NY', | |
86797006 | 418 | 'country' => 'UNITED STATES', |
6a488035 TO |
419 | ), |
420 | ); | |
421 | ||
422 | return array($headers, $rows); | |
423 | } | |
96025800 | 424 | |
6a488035 | 425 | } |