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 | ||
6a488035 TO |
27 | require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php'; |
28 | class WebTest_Import_ContactSubtypeTest extends ImportCiviSeleniumTestCase { | |
29 | ||
6a488035 TO |
30 | protected function setUp() { |
31 | parent::setUp(); | |
32 | } | |
33 | ||
34 | /* | |
35 | * Test contact import for Individuals Subtype. | |
36 | */ | |
37 | function testIndividualSubtypeImport() { | |
6a488035 TO |
38 | $this->webtestLogin(); |
39 | ||
40 | // Get sample import data. | |
41 | list($headers, $rows) = $this->_individualSubtypeCSVData(); | |
42 | ||
43 | // Import and check Individual contacts in Skip mode with contact type Parent. | |
44 | $other = array('contactSubtype' => 'Parent'); | |
45 | ||
46 | $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other); | |
47 | ||
48 | // Get imported contact Ids | |
49 | $importedContactIds = $this->_getImportedContactIds($rows); | |
50 | ||
51 | // Build update mode import headers | |
52 | $updateHeaders = array( | |
53 | 'contact_id' => 'Internal Contact ID', | |
54 | 'first_name' => 'First Name', | |
55 | 'last_name' => 'Last Name', | |
56 | ); | |
57 | ||
58 | // Create update mode import rows | |
59 | $updateRows = array(); | |
60 | foreach ($importedContactIds as $cid) { | |
61 | $updateRows[$cid] = array( | |
62 | 'contact_id' => $cid, | |
63 | 'first_name' => substr(sha1(rand()), 0, 7), | |
64 | 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7), | |
65 | ); | |
66 | } | |
67 | ||
68 | // Import and check Individual contacts in Update mode with contact type Parent. | |
69 | $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update', array(), $other); | |
70 | ||
71 | // Visit contacts to check updated data. | |
72 | foreach ($updateRows as $updatedRow) { | |
071a6d2e | 73 | $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}"); |
6a488035 TO |
74 | $displayName = "{$updatedRow['first_name']} {$updatedRow['last_name']}"; |
75 | $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not update!"); | |
76 | } | |
77 | ||
78 | // Headers that should not updated. | |
79 | $fillHeaders = $updateHeaders; | |
80 | ||
81 | // Headers that should fill. | |
82 | $fillHeaders['gender'] = 'Gender'; | |
83 | $fillHeaders['dob'] = 'Birth Date'; | |
84 | ||
85 | $fillRows = array(); | |
86 | foreach ($importedContactIds as $cid) { | |
87 | $fillRows[$cid] = array( | |
88 | 'contact_id' => $cid, | |
89 | // should not update | |
90 | 'first_name' => substr(sha1(rand()), 0, 7), | |
91 | // should not update | |
92 | 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7), | |
93 | 'gender' => 'Male', | |
94 | 'dob' => '1986-04-16', | |
95 | ); | |
96 | } | |
97 | ||
98 | // Import and check Individual contacts in Update mode with contact type Parent. | |
99 | $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill', array(), $other); | |
100 | ||
101 | // Visit contacts to check filled data. | |
102 | foreach ($fillRows as $cid => $fillRow) { | |
071a6d2e | 103 | $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}"); |
6a488035 TO |
104 | |
105 | // Check old display name. | |
106 | $displayName = "{$updateRows[$cid]['first_name']} {$updateRows[$cid]['last_name']}"; | |
107 | $this->assertTrue($this->isTextPresent("$displayName"), "Contact should not update in fill mode!"); | |
108 | ||
109 | $this->verifyText("css=div#contact-summary div.crm-contact-gender_display", preg_quote($fillRow['gender'])); | |
110 | } | |
111 | ||
112 | // Recreate same conacts using 'No Duplicate Checking' with contact type Parent. | |
113 | $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking', array(), $other); | |
114 | } | |
115 | ||
6a488035 TO |
116 | /* |
117 | * Test contact import for Organization Subtype. | |
118 | */ | |
119 | function testOrganizationSubtypeImport() { | |
6a488035 TO |
120 | $this->webtestLogin(); |
121 | ||
122 | // Get sample import data. | |
123 | list($headers, $rows) = $this->_organizationSubtypeCSVData(); | |
124 | ||
125 | // Import and check Organization contacts | |
126 | $other = array('contactSubtype' => 'Team'); | |
127 | ||
128 | $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other); | |
129 | ||
130 | // Get imported contact Ids | |
131 | $importedContactIds = $this->_getImportedContactIds($rows, 'Organization'); | |
132 | ||
133 | // Build update mode import headers | |
134 | $updateHeaders = array( | |
135 | 'contact_id' => 'Internal Contact ID', | |
136 | 'organization_name' => 'Organization Name', | |
137 | ); | |
138 | ||
139 | // Create update mode import rows | |
140 | $updateRows = array(); | |
141 | foreach ($importedContactIds as $cid) { | |
142 | $updateRows[$cid] = array( | |
143 | 'contact_id' => $cid, | |
144 | 'organization_name' => 'UpdatedOrg ' . substr(sha1(rand()), 0, 7), | |
145 | ); | |
146 | } | |
147 | ||
148 | // Import and check Individual contacts in Update mode with contact type Team. | |
149 | $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update', array(), $other); | |
150 | ||
151 | // Visit contacts to check updated data. | |
152 | foreach ($updateRows as $updatedRow) { | |
153 | $organizationName = $updatedRow['organization_name']; | |
071a6d2e | 154 | $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}"); |
6a488035 TO |
155 | |
156 | $this->assertTrue($this->isTextPresent("$organizationName"), "Contact did not update!"); | |
157 | } | |
158 | ||
159 | // Headers that should not updated. | |
160 | $fillHeaders = $updateHeaders; | |
161 | ||
162 | // Headers that should fill. | |
163 | $fillHeaders['legal_name'] = 'Legal Name'; | |
164 | ||
165 | $fillRows = array(); | |
166 | foreach ($importedContactIds as $cid) { | |
167 | $fillRows[$cid] = array( | |
168 | 'contact_id' => $cid, | |
169 | // should not update | |
170 | 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7), | |
171 | 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7), | |
172 | ); | |
173 | } | |
174 | ||
175 | // Import and check Individual contacts in Update mode with contact type Team. | |
176 | $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill', array(), $other); | |
177 | ||
178 | // Visit contacts to check filled data. | |
179 | foreach ($fillRows as $cid => $fillRow) { | |
071a6d2e | 180 | $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}"); |
6a488035 TO |
181 | |
182 | // Check old Organization name. | |
183 | $organizationName = $updateRows[$cid]['organization_name']; | |
184 | $this->assertTrue($this->isTextPresent("$organizationName"), "Contact should not update in fill mode!"); | |
185 | $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[3]/div[2]", preg_quote($fillRow['legal_name'])); | |
186 | } | |
187 | ||
188 | // Recreate same conacts using 'No Duplicate Checking' with contact type Team. | |
189 | $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking', array(), $other); | |
190 | } | |
191 | ||
6a488035 TO |
192 | /* |
193 | * Test contact import for Household Subtype. | |
194 | */ | |
195 | function testHouseholdSubtypeImport() { | |
6a488035 TO |
196 | $this->webtestLogin(); |
197 | ||
198 | // Create Household Subtype | |
199 | $householdSubtype = $this->_createHouseholdSubtype(); | |
200 | ||
201 | // Get sample import data. | |
202 | list($headers, $rows) = $this->_householdSubtypeCSVData(); | |
203 | ||
204 | // Import and check Organization contacts | |
205 | $other = array('contactSubtype' => $householdSubtype); | |
206 | ||
207 | $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other); | |
208 | ||
209 | // Get imported contact Ids | |
210 | $importedContactIds = $this->_getImportedContactIds($rows, 'Household'); | |
211 | ||
212 | // Build update mode import headers | |
213 | $updateHeaders = array( | |
214 | 'contact_id' => 'Internal Contact ID', | |
215 | 'household_name' => 'Household Name', | |
216 | ); | |
217 | ||
218 | // Create update mode import rows | |
219 | $updateRows = array(); | |
220 | foreach ($importedContactIds as $cid) { | |
221 | $updateRows[$cid] = array( | |
222 | 'contact_id' => $cid, | |
223 | 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7), | |
224 | ); | |
225 | } | |
226 | ||
227 | // Import and check Individual contacts in Update mode. | |
228 | $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update', array(), $other); | |
229 | ||
230 | // Visit contacts to check updated data. | |
231 | foreach ($updateRows as $updatedRow) { | |
232 | $householdName = $updatedRow['household_name']; | |
071a6d2e | 233 | $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}"); |
6a488035 TO |
234 | |
235 | $this->assertTrue($this->isTextPresent("$householdName"), "Contact did not update!"); | |
236 | } | |
237 | ||
238 | // Headers that should not updated. | |
239 | $fillHeaders = $updateHeaders; | |
240 | ||
241 | // Headers that should fill. | |
242 | $fillHeaders['nick_name'] = 'Nick Name'; | |
243 | ||
244 | $fillRows = array(); | |
245 | foreach ($importedContactIds as $cid) { | |
246 | $fillRows[$cid] = array( | |
247 | 'contact_id' => $cid, | |
248 | // should not update | |
249 | 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7), | |
250 | 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7), | |
251 | ); | |
252 | } | |
253 | ||
254 | // Import and check Individual contacts in Update mode. | |
255 | $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill', array(), $other); | |
256 | ||
257 | // Visit contacts to check filled data. | |
258 | foreach ($fillRows as $cid => $fillRow) { | |
071a6d2e | 259 | $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}"); |
6a488035 TO |
260 | |
261 | // Check old Household name. | |
262 | $householdName = $updateRows[$cid]['household_name']; | |
263 | $this->assertTrue($this->isTextPresent("$householdName"), "Contact should not update in fill mode!"); | |
264 | $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[2]/div[2]", preg_quote($fillRow['nick_name'])); | |
265 | } | |
266 | ||
267 | // Recreate same conacts using 'No Duplicate Checking' | |
268 | $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking', array(), $other); | |
269 | } | |
270 | ||
271 | /* | |
272 | * Helper function to create Household Subtype. | |
273 | */ | |
274 | function _createHouseholdSubtype() { | |
275 | ||
276 | // Visit to create contact subtype | |
071a6d2e | 277 | $this->openCiviPage("admin/options/subtype", "action=add&reset=1"); |
6a488035 TO |
278 | |
279 | // Create Household subtype | |
280 | $householdSubtype = substr(sha1(rand()), 0, 7); | |
281 | $this->type("label", $householdSubtype); | |
282 | $this->select("parent_id", "label=Household"); | |
283 | $this->click("_qf_ContactType_next-bottom"); | |
284 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
285 | return $householdSubtype; | |
286 | } | |
287 | ||
288 | /* | |
289 | * Helper function to provide data for contact import for Individuals Subtype. | |
290 | */ | |
291 | function _individualSubtypeCSVData() { | |
292 | $headers = array( | |
293 | 'first_name' => 'First Name', | |
294 | 'middle_name' => 'Middle Name', | |
295 | 'last_name' => 'Last Name', | |
296 | 'email' => 'Email', | |
297 | 'phone' => 'Phone', | |
298 | 'address_1' => 'Additional Address 1', | |
299 | 'address_2' => 'Additional Address 2', | |
300 | 'city' => 'City', | |
301 | 'state' => 'State', | |
302 | 'country' => 'Country', | |
303 | ); | |
304 | ||
305 | $rows = array( | |
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', | |
313 | 'city' => 'Watson', | |
314 | 'state' => 'NY', | |
315 | 'country' => 'United States', | |
316 | ), | |
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', | |
324 | 'city' => 'Watson', | |
325 | 'state' => 'NY', | |
326 | 'country' => 'United States', | |
327 | ), | |
328 | ); | |
329 | ||
330 | return array($headers, $rows); | |
331 | } | |
332 | ||
333 | /* | |
334 | * Helper function to provide data for contact import for Organizations Subtype. | |
335 | */ | |
336 | function _organizationSubtypeCSVData() { | |
337 | $headers = array( | |
338 | 'organization_name' => 'Organization Name', | |
339 | 'email' => 'Email', | |
340 | 'phone' => 'Phone', | |
341 | 'address_1' => 'Additional Address 1', | |
342 | 'address_2' => 'Additional Address 2', | |
343 | 'city' => 'City', | |
344 | 'state' => 'State', | |
345 | 'country' => 'Country', | |
346 | ); | |
347 | ||
348 | $rows = array( | |
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', | |
354 | 'city' => 'Watson', | |
355 | 'state' => 'NY', | |
356 | 'country' => 'United States', | |
357 | ), | |
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', | |
363 | 'city' => 'Watson', | |
364 | 'state' => 'NY', | |
365 | 'country' => 'United States', | |
366 | ), | |
367 | ); | |
368 | ||
369 | return array($headers, $rows); | |
370 | } | |
371 | ||
372 | /* | |
373 | * Helper function to provide data for contact import for Household Subtype. | |
374 | */ | |
375 | function _householdSubtypeCSVData() { | |
376 | $headers = array( | |
377 | 'household_name' => 'Household Name', | |
378 | 'email' => 'Email', | |
379 | 'phone' => 'Phone', | |
380 | 'address_1' => 'Additional Address 1', | |
381 | 'address_2' => 'Additional Address 2', | |
382 | 'city' => 'City', | |
383 | 'state' => 'State', | |
384 | 'country' => 'Country', | |
385 | ); | |
386 | ||
387 | $rows = array( | |
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', | |
393 | 'city' => 'Watson', | |
394 | 'state' => 'NY', | |
395 | 'country' => 'United States', | |
396 | ), | |
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', | |
402 | 'city' => 'Watson', | |
403 | 'state' => 'NY', | |
404 | 'country' => 'United States', | |
405 | ), | |
406 | ); | |
407 | ||
408 | return array($headers, $rows); | |
409 | } | |
410 | } | |
411 |