Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | ||
27 | ||
28 | require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php'; | |
29 | class WebTest_Import_ContactTest extends ImportCiviSeleniumTestCase { | |
30 | ||
31 | protected $captureScreenshotOnFailure = TRUE; | |
32 | protected $screenshotPath = '/var/www/api.dev.civicrm.org/public/sc'; | |
33 | protected $screenshotUrl = 'http://api.dev.civicrm.org/sc/'; | |
34 | ||
35 | protected function setUp() { | |
36 | parent::setUp(); | |
37 | } | |
38 | ||
39 | /* | |
40 | * Test contact import for Individuals. | |
41 | */ | |
42 | function testIndividualImport() { | |
43 | ||
44 | // This is the path where our testing install resides. | |
45 | // The rest of URL is defined in CiviSeleniumTestCase base class, in | |
46 | // class attributes. | |
47 | $this->open($this->sboxPath); | |
48 | ||
49 | // Logging in. Remember to wait for page to load. In most cases, | |
50 | // you can rely on 30000 as the value that allows your test to pass, however, | |
51 | // sometimes your test might fail because of this. In such cases, it's better to pick one element | |
52 | // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole | |
53 | // page contents loaded and you can continue your test execution. | |
54 | $this->webtestLogin(); | |
55 | ||
56 | // Get sample import data. | |
57 | list($headers, $rows) = $this->_individualCSVData(); | |
58 | ||
59 | // Import and check Individual contacts in Skip mode. | |
60 | $other = array( | |
61 | 'saveMapping' => TRUE, | |
62 | 'createGroup' => TRUE, | |
63 | 'createTag' => TRUE, | |
64 | ); | |
65 | ||
66 | $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other); | |
67 | ||
68 | // Get imported contact Ids | |
69 | $importedContactIds = $this->_getImportedContactIds($rows); | |
70 | ||
71 | // Build update mode import headers | |
72 | $updateHeaders = array( | |
73 | 'contact_id' => 'Internal Contact ID', | |
74 | 'first_name' => 'First Name', | |
75 | 'last_name' => 'Last Name', | |
76 | ); | |
77 | ||
78 | // Create update mode import rows | |
79 | $updateRows = array(); | |
80 | foreach ($importedContactIds as $cid) { | |
81 | $updateRows[$cid] = array( | |
82 | 'contact_id' => $cid, | |
83 | 'first_name' => substr(sha1(rand()), 0, 7), | |
84 | 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7), | |
85 | ); | |
86 | } | |
87 | ||
88 | // Import and check Individual contacts in Update mode. | |
89 | $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update'); | |
90 | ||
91 | // Visit contacts to check updated data. | |
92 | foreach ($updateRows as $updatedRow) { | |
93 | $this->open($this->sboxPath . "civicrm/contact/view?reset=1&cid={$updatedRow['contact_id']}"); | |
94 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
95 | ||
96 | $displayName = "{$updatedRow['first_name']} {$updatedRow['last_name']}"; | |
97 | $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not update!"); | |
98 | } | |
99 | ||
100 | // Headers that should not updated. | |
101 | $fillHeaders = $updateHeaders; | |
102 | ||
103 | // Headers that should fill. | |
104 | $fillHeaders['gender'] = 'Gender'; | |
105 | $fillHeaders['dob'] = 'Birth Date'; | |
106 | ||
107 | $fillRows = array(); | |
108 | foreach ($importedContactIds as $cid) { | |
109 | $fillRows[$cid] = array( | |
110 | 'contact_id' => $cid, | |
111 | // should not update | |
112 | 'first_name' => substr(sha1(rand()), 0, 7), | |
113 | // should not update | |
114 | 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7), | |
115 | 'gender' => 'Male', | |
116 | 'dob' => '1986-04-16', | |
117 | ); | |
118 | } | |
119 | ||
120 | // Import and check Individual contacts in Update mode. | |
121 | $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill'); | |
122 | ||
123 | // Visit contacts to check filled data. | |
124 | foreach ($fillRows as $cid => $fillRow) { | |
125 | $this->open($this->sboxPath . "civicrm/contact/view?reset=1&cid={$fillRow['contact_id']}"); | |
126 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
127 | ||
128 | // Check old display name. | |
129 | $displayName = "{$updateRows[$cid]['first_name']} {$updateRows[$cid]['last_name']}"; | |
130 | $this->assertTrue($this->isTextPresent("$displayName"), "Contact display name should not update in fill mode!"); | |
131 | ||
132 | $this->verifyText("css=div#contact-summary div.crm-contact-gender_display", preg_quote($fillRow['gender'])); | |
133 | } | |
134 | ||
135 | // Recreate same conacts using 'No Duplicate Checking' | |
136 | $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking'); | |
137 | } | |
138 | ||
139 | /* | |
140 | * Test contact import for Organization. | |
141 | */ | |
142 | function testOrganizationImport() { | |
143 | $this->open($this->sboxPath); | |
144 | ||
145 | $this->webtestLogin(); | |
146 | ||
147 | // Get sample import data. | |
148 | list($headers, $rows) = $this->_organizationCSVData(); | |
149 | ||
150 | // Import and check Organization contacts | |
151 | $other = array( | |
152 | 'saveMapping' => TRUE, | |
153 | 'createGroup' => TRUE, | |
154 | 'createTag' => TRUE, | |
155 | ); | |
156 | ||
157 | $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other); | |
158 | ||
159 | // Get imported contact Ids | |
160 | $importedContactIds = $this->_getImportedContactIds($rows, 'Organization'); | |
161 | ||
162 | // Build update mode import headers | |
163 | $updateHeaders = array( | |
164 | 'contact_id' => 'Internal Contact ID', | |
165 | 'organization_name' => 'Organization Name', | |
166 | ); | |
167 | ||
168 | // Create update mode import rows | |
169 | $updateRows = array(); | |
170 | foreach ($importedContactIds as $cid) { | |
171 | $updateRows[$cid] = array( | |
172 | 'contact_id' => $cid, | |
173 | 'organization_name' => 'UpdatedOrg ' . substr(sha1(rand()), 0, 7), | |
174 | ); | |
175 | } | |
176 | ||
177 | // Import and check Individual contacts in Update mode. | |
178 | $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update'); | |
179 | ||
180 | // Visit contacts to check updated data. | |
181 | foreach ($updateRows as $updatedRow) { | |
182 | $organizationName = $updatedRow['organization_name']; | |
183 | $this->open($this->sboxPath . "civicrm/contact/view?reset=1&cid={$updatedRow['contact_id']}"); | |
184 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
185 | ||
186 | $this->assertTrue($this->isTextPresent("$organizationName"), "Contact did not update!"); | |
187 | } | |
188 | ||
189 | // Headers that should not updated. | |
190 | $fillHeaders = $updateHeaders; | |
191 | ||
192 | // Headers that should fill. | |
193 | $fillHeaders['legal_name'] = 'Legal Name'; | |
194 | ||
195 | $fillRows = array(); | |
196 | foreach ($importedContactIds as $cid) { | |
197 | $fillRows[$cid] = array( | |
198 | 'contact_id' => $cid, | |
199 | // should not update | |
200 | 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7), | |
201 | 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7), | |
202 | ); | |
203 | } | |
204 | ||
205 | // Import and check Individual contacts in Update mode. | |
206 | $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill'); | |
207 | ||
208 | // Visit contacts to check filled data. | |
209 | foreach ($fillRows as $cid => $fillRow) { | |
210 | $this->open($this->sboxPath . "civicrm/contact/view?reset=1&cid={$fillRow['contact_id']}"); | |
211 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
212 | ||
213 | // Check old Organization name. | |
214 | $organizationName = $updateRows[$cid]['organization_name']; | |
215 | $this->assertTrue($this->isTextPresent("$organizationName"), "Contact should not update in fill mode!"); | |
216 | $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[3]/div[2]", preg_quote($fillRow['legal_name'])); | |
217 | } | |
218 | ||
219 | // Recreate same conacts using 'No Duplicate Checking' | |
220 | $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking'); | |
221 | } | |
222 | ||
223 | /* | |
224 | * Test contact import for Household. | |
225 | */ | |
226 | function testHouseholdImport() { | |
227 | $this->open($this->sboxPath); | |
228 | ||
229 | $this->webtestLogin(); | |
230 | ||
231 | // Get sample import data. | |
232 | list($headers, $rows) = $this->_householdCSVData(); | |
233 | ||
234 | // Import and check Household contacts | |
235 | $other = array( | |
236 | 'saveMapping' => TRUE, | |
237 | 'createGroup' => TRUE, | |
238 | 'createTag' => TRUE, | |
239 | ); | |
240 | ||
241 | $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other); | |
242 | ||
243 | // Get imported contact Ids | |
244 | $importedContactIds = $this->_getImportedContactIds($rows, 'Household'); | |
245 | ||
246 | // Build update mode import headers | |
247 | $updateHeaders = array( | |
248 | 'contact_id' => 'Internal Contact ID', | |
249 | 'household_name' => 'Household Name', | |
250 | ); | |
251 | ||
252 | // Create update mode import rows | |
253 | $updateRows = array(); | |
254 | foreach ($importedContactIds as $cid) { | |
255 | $updateRows[$cid] = array( | |
256 | 'contact_id' => $cid, | |
257 | 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7), | |
258 | ); | |
259 | } | |
260 | ||
261 | // Import and check Individual contacts in Update mode. | |
262 | $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update'); | |
263 | ||
264 | // Visit contacts to check updated data. | |
265 | foreach ($updateRows as $updatedRow) { | |
266 | $householdName = $updatedRow['household_name']; | |
267 | $this->open($this->sboxPath . "civicrm/contact/view?reset=1&cid={$updatedRow['contact_id']}"); | |
268 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
269 | ||
270 | $this->assertTrue($this->isTextPresent("$householdName"), "Contact did not update!"); | |
271 | } | |
272 | ||
273 | // Headers that should not updated. | |
274 | $fillHeaders = $updateHeaders; | |
275 | ||
276 | // Headers that should fill. | |
277 | $fillHeaders['nick_name'] = 'Nick Name'; | |
278 | ||
279 | $fillRows = array(); | |
280 | foreach ($importedContactIds as $cid) { | |
281 | $fillRows[$cid] = array( | |
282 | 'contact_id' => $cid, | |
283 | // should not update | |
284 | 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7), | |
285 | 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7), | |
286 | ); | |
287 | } | |
288 | ||
289 | // Import and check Individual contacts in Update mode. | |
290 | $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill'); | |
291 | ||
292 | // Visit contacts to check filled data. | |
293 | foreach ($fillRows as $cid => $fillRow) { | |
294 | $this->open($this->sboxPath . "civicrm/contact/view?reset=1&cid={$fillRow['contact_id']}"); | |
295 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
296 | ||
297 | // Check old Household name. | |
298 | $householdName = $updateRows[$cid]['household_name']; | |
299 | $this->assertTrue($this->isTextPresent("$householdName"), "Contact should not update in fill mode!"); | |
300 | $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[2]/div[2]", preg_quote($fillRow['nick_name'])); | |
301 | } | |
302 | ||
303 | // Recreate same conacts using 'No Duplicate Checking' | |
304 | $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking'); | |
305 | } | |
306 | ||
307 | /* | |
308 | * Helper function to provide data for contact import for Individuals. | |
309 | */ | |
310 | function _individualCSVData() { | |
311 | $headers = array( | |
312 | 'first_name' => 'First Name', | |
313 | 'middle_name' => 'Middle Name', | |
314 | 'last_name' => 'Last Name', | |
315 | 'email' => 'Email', | |
316 | 'phone' => 'Phone', | |
317 | 'address_1' => 'Additional Address 1', | |
318 | 'address_2' => 'Additional Address 2', | |
319 | 'city' => 'City', | |
320 | 'state' => 'State', | |
321 | 'country' => 'Country', | |
322 | ); | |
323 | ||
324 | $rows = array( | |
325 | array('first_name' => substr(sha1(rand()), 0, 7), | |
326 | 'middle_name' => substr(sha1(rand()), 0, 7), | |
327 | 'last_name' => 'Anderson', | |
328 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', | |
329 | 'phone' => '6949912154', | |
330 | 'address_1' => 'Add 1', | |
331 | 'address_2' => 'Add 2', | |
332 | 'city' => 'Watson', | |
333 | 'state' => 'NY', | |
334 | 'country' => 'United States', | |
335 | ), | |
336 | array('first_name' => substr(sha1(rand()), 0, 7), | |
337 | 'middle_name' => substr(sha1(rand()), 0, 7), | |
338 | 'last_name' => 'Summerson', | |
339 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', | |
340 | 'phone' => '6944412154', | |
341 | 'address_1' => 'Add 1', | |
342 | 'address_2' => 'Add 2', | |
343 | 'city' => 'Watson', | |
344 | 'state' => 'NY', | |
345 | 'country' => 'United States', | |
346 | ), | |
347 | ); | |
348 | ||
349 | return array($headers, $rows); | |
350 | } | |
351 | ||
352 | /* | |
353 | * Helper function to provide data for contact import for Organizations. | |
354 | */ | |
355 | function _organizationCSVData() { | |
356 | $headers = array( | |
357 | 'organization_name' => 'Organization Name', | |
358 | 'email' => 'Email', | |
359 | 'phone' => 'Phone', | |
360 | 'address_1' => 'Additional Address 1', | |
361 | 'address_2' => 'Additional Address 2', | |
362 | 'city' => 'City', | |
363 | 'state' => 'State', | |
364 | 'country' => 'Country', | |
365 | ); | |
366 | ||
367 | $rows = array( | |
368 | array('organization_name' => 'org_' . substr(sha1(rand()), 0, 7), | |
369 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', | |
370 | 'phone' => '9949912154', | |
371 | 'address_1' => 'Add 1', | |
372 | 'address_2' => 'Add 2', | |
373 | 'city' => 'Watson', | |
374 | 'state' => 'NY', | |
375 | 'country' => 'United States', | |
376 | ), | |
377 | array('organization_name' => 'org_' . substr(sha1(rand()), 0, 7), | |
378 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', | |
379 | 'phone' => '6949412154', | |
380 | 'address_1' => 'Add 1', | |
381 | 'address_2' => 'Add 2', | |
382 | 'city' => 'Watson', | |
383 | 'state' => 'NY', | |
384 | 'country' => 'United States', | |
385 | ), | |
386 | ); | |
387 | ||
388 | return array($headers, $rows); | |
389 | } | |
390 | ||
391 | /* | |
392 | * Helper function to provide data for contact import for Household. | |
393 | */ | |
394 | function _householdCSVData() { | |
395 | $headers = array( | |
396 | 'household_name' => 'Household Name', | |
397 | 'email' => 'Email', | |
398 | 'phone' => 'Phone', | |
399 | 'address_1' => 'Additional Address 1', | |
400 | 'address_2' => 'Additional Address 2', | |
401 | 'city' => 'City', | |
402 | 'state' => 'State', | |
403 | 'country' => 'Country', | |
404 | ); | |
405 | ||
406 | $rows = array( | |
407 | array('household_name' => 'household_' . substr(sha1(rand()), 0, 7), | |
408 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', | |
409 | 'phone' => '3949912154', | |
410 | 'address_1' => 'Add 1', | |
411 | 'address_2' => 'Add 2', | |
412 | 'city' => 'Watson', | |
413 | 'state' => 'NY', | |
414 | 'country' => 'United States', | |
415 | ), | |
416 | array('household_name' => 'household_' . substr(sha1(rand()), 0, 7), | |
417 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', | |
418 | 'phone' => '5949412154', | |
419 | 'address_1' => 'Add 1', | |
420 | 'address_2' => 'Add 2', | |
421 | 'city' => 'Watson', | |
422 | 'state' => 'NY', | |
423 | 'country' => 'United States', | |
424 | ), | |
425 | ); | |
426 | ||
427 | return array($headers, $rows); | |
428 | } | |
429 | } | |
430 |