Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
15a4309a | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
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_ContactSubtypeTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Import_ContactSubtypeTest extends ImportCiviSeleniumTestCase { |
33 | ||
6a488035 TO |
34 | protected function setUp() { |
35 | parent::setUp(); | |
36 | } | |
37 | ||
28a04ea9 | 38 | /** |
6a488035 TO |
39 | * Test contact import for Individuals Subtype. |
40 | */ | |
00be9182 | 41 | public function testIndividualSubtypeImport() { |
6a488035 TO |
42 | $this->webtestLogin(); |
43 | ||
44 | // Get sample import data. | |
45 | list($headers, $rows) = $this->_individualSubtypeCSVData(); | |
46 | ||
47 | // Import and check Individual contacts in Skip mode with contact type Parent. | |
48 | $other = array('contactSubtype' => 'Parent'); | |
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 with contact type Parent. | |
73 | $this->importContacts($updateHeaders, $updateRows, 'Individual', 'Update', array(), $other); | |
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 | $displayName = "{$updatedRow['first_name']} {$updatedRow['last_name']}"; |
79 | $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not update!"); | |
80 | } | |
81 | ||
82 | // Headers that should not updated. | |
83 | $fillHeaders = $updateHeaders; | |
84 | ||
85 | // Headers that should fill. | |
86 | $fillHeaders['gender'] = 'Gender'; | |
87 | $fillHeaders['dob'] = 'Birth Date'; | |
88 | ||
89 | $fillRows = array(); | |
90 | foreach ($importedContactIds as $cid) { | |
91 | $fillRows[$cid] = array( | |
92 | 'contact_id' => $cid, | |
93 | // should not update | |
94 | 'first_name' => substr(sha1(rand()), 0, 7), | |
95 | // should not update | |
96 | 'last_name' => 'Anderson' . substr(sha1(rand()), 0, 7), | |
97 | 'gender' => 'Male', | |
98 | 'dob' => '1986-04-16', | |
99 | ); | |
100 | } | |
101 | ||
102 | // Import and check Individual contacts in Update mode with contact type Parent. | |
103 | $this->importContacts($fillHeaders, $fillRows, 'Individual', 'Fill', array(), $other); | |
104 | ||
105 | // Visit contacts to check filled data. | |
106 | foreach ($fillRows as $cid => $fillRow) { | |
071a6d2e | 107 | $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}"); |
6a488035 TO |
108 | |
109 | // Check old display name. | |
110 | $displayName = "{$updateRows[$cid]['first_name']} {$updateRows[$cid]['last_name']}"; | |
111 | $this->assertTrue($this->isTextPresent("$displayName"), "Contact should not update in fill mode!"); | |
112 | ||
113 | $this->verifyText("css=div#contact-summary div.crm-contact-gender_display", preg_quote($fillRow['gender'])); | |
114 | } | |
115 | ||
116 | // Recreate same conacts using 'No Duplicate Checking' with contact type Parent. | |
117 | $this->importContacts($headers, $rows, 'Individual', 'No Duplicate Checking', array(), $other); | |
118 | } | |
119 | ||
28a04ea9 | 120 | /** |
6a488035 TO |
121 | * Test contact import for Organization Subtype. |
122 | */ | |
00be9182 | 123 | public function testOrganizationSubtypeImport() { |
6a488035 TO |
124 | $this->webtestLogin(); |
125 | ||
126 | // Get sample import data. | |
127 | list($headers, $rows) = $this->_organizationSubtypeCSVData(); | |
128 | ||
129 | // Import and check Organization contacts | |
130 | $other = array('contactSubtype' => 'Team'); | |
131 | ||
132 | $this->importContacts($headers, $rows, 'Organization', 'Skip', array(), $other); | |
133 | ||
134 | // Get imported contact Ids | |
135 | $importedContactIds = $this->_getImportedContactIds($rows, 'Organization'); | |
136 | ||
137 | // Build update mode import headers | |
138 | $updateHeaders = array( | |
139 | 'contact_id' => 'Internal Contact ID', | |
140 | 'organization_name' => 'Organization Name', | |
141 | ); | |
142 | ||
143 | // Create update mode import rows | |
144 | $updateRows = array(); | |
145 | foreach ($importedContactIds as $cid) { | |
146 | $updateRows[$cid] = array( | |
147 | 'contact_id' => $cid, | |
148 | 'organization_name' => 'UpdatedOrg ' . substr(sha1(rand()), 0, 7), | |
149 | ); | |
150 | } | |
151 | ||
152 | // Import and check Individual contacts in Update mode with contact type Team. | |
153 | $this->importContacts($updateHeaders, $updateRows, 'Organization', 'Update', array(), $other); | |
154 | ||
155 | // Visit contacts to check updated data. | |
156 | foreach ($updateRows as $updatedRow) { | |
157 | $organizationName = $updatedRow['organization_name']; | |
071a6d2e | 158 | $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}"); |
6a488035 TO |
159 | |
160 | $this->assertTrue($this->isTextPresent("$organizationName"), "Contact did not update!"); | |
161 | } | |
162 | ||
163 | // Headers that should not updated. | |
164 | $fillHeaders = $updateHeaders; | |
165 | ||
166 | // Headers that should fill. | |
167 | $fillHeaders['legal_name'] = 'Legal Name'; | |
168 | ||
169 | $fillRows = array(); | |
170 | foreach ($importedContactIds as $cid) { | |
171 | $fillRows[$cid] = array( | |
172 | 'contact_id' => $cid, | |
173 | // should not update | |
174 | 'organization_name' => 'UpdateOrg ' . substr(sha1(rand()), 0, 7), | |
175 | 'legal_name' => 'org ' . substr(sha1(rand()), 0, 7), | |
176 | ); | |
177 | } | |
178 | ||
179 | // Import and check Individual contacts in Update mode with contact type Team. | |
180 | $this->importContacts($fillHeaders, $fillRows, 'Organization', 'Fill', array(), $other); | |
181 | ||
182 | // Visit contacts to check filled data. | |
183 | foreach ($fillRows as $cid => $fillRow) { | |
071a6d2e | 184 | $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}"); |
6a488035 TO |
185 | |
186 | // Check old Organization name. | |
187 | $organizationName = $updateRows[$cid]['organization_name']; | |
188 | $this->assertTrue($this->isTextPresent("$organizationName"), "Contact should not update in fill mode!"); | |
189 | $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[3]/div[2]", preg_quote($fillRow['legal_name'])); | |
190 | } | |
191 | ||
192 | // Recreate same conacts using 'No Duplicate Checking' with contact type Team. | |
193 | $this->importContacts($headers, $rows, 'Organization', 'No Duplicate Checking', array(), $other); | |
194 | } | |
195 | ||
28a04ea9 | 196 | /** |
6a488035 TO |
197 | * Test contact import for Household Subtype. |
198 | */ | |
00be9182 | 199 | public function testHouseholdSubtypeImport() { |
6a488035 TO |
200 | $this->webtestLogin(); |
201 | ||
202 | // Create Household Subtype | |
203 | $householdSubtype = $this->_createHouseholdSubtype(); | |
204 | ||
205 | // Get sample import data. | |
206 | list($headers, $rows) = $this->_householdSubtypeCSVData(); | |
207 | ||
208 | // Import and check Organization contacts | |
209 | $other = array('contactSubtype' => $householdSubtype); | |
210 | ||
211 | $this->importContacts($headers, $rows, 'Household', 'Skip', array(), $other); | |
212 | ||
213 | // Get imported contact Ids | |
214 | $importedContactIds = $this->_getImportedContactIds($rows, 'Household'); | |
215 | ||
216 | // Build update mode import headers | |
217 | $updateHeaders = array( | |
218 | 'contact_id' => 'Internal Contact ID', | |
219 | 'household_name' => 'Household Name', | |
220 | ); | |
221 | ||
222 | // Create update mode import rows | |
223 | $updateRows = array(); | |
224 | foreach ($importedContactIds as $cid) { | |
225 | $updateRows[$cid] = array( | |
226 | 'contact_id' => $cid, | |
227 | 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7), | |
228 | ); | |
229 | } | |
230 | ||
231 | // Import and check Individual contacts in Update mode. | |
232 | $this->importContacts($updateHeaders, $updateRows, 'Household', 'Update', array(), $other); | |
233 | ||
234 | // Visit contacts to check updated data. | |
235 | foreach ($updateRows as $updatedRow) { | |
236 | $householdName = $updatedRow['household_name']; | |
071a6d2e | 237 | $this->openCiviPage("contact/view", "reset=1&cid={$updatedRow['contact_id']}"); |
6a488035 TO |
238 | |
239 | $this->assertTrue($this->isTextPresent("$householdName"), "Contact did not update!"); | |
240 | } | |
241 | ||
242 | // Headers that should not updated. | |
243 | $fillHeaders = $updateHeaders; | |
244 | ||
245 | // Headers that should fill. | |
246 | $fillHeaders['nick_name'] = 'Nick Name'; | |
247 | ||
248 | $fillRows = array(); | |
249 | foreach ($importedContactIds as $cid) { | |
250 | $fillRows[$cid] = array( | |
251 | 'contact_id' => $cid, | |
252 | // should not update | |
253 | 'household_name' => 'UpdatedHousehold ' . substr(sha1(rand()), 0, 7), | |
254 | 'nick_name' => 'Household ' . substr(sha1(rand()), 0, 7), | |
255 | ); | |
256 | } | |
257 | ||
258 | // Import and check Individual contacts in Update mode. | |
259 | $this->importContacts($fillHeaders, $fillRows, 'Household', 'Fill', array(), $other); | |
260 | ||
261 | // Visit contacts to check filled data. | |
262 | foreach ($fillRows as $cid => $fillRow) { | |
071a6d2e | 263 | $this->openCiviPage("contact/view", "reset=1&cid={$fillRow['contact_id']}"); |
6a488035 TO |
264 | |
265 | // Check old Household name. | |
266 | $householdName = $updateRows[$cid]['household_name']; | |
267 | $this->assertTrue($this->isTextPresent("$householdName"), "Contact should not update in fill mode!"); | |
268 | $this->verifyText("xpath=//div[@id='crm-contactinfo-content']/div/div[2]/div[2]", preg_quote($fillRow['nick_name'])); | |
269 | } | |
270 | ||
271 | // Recreate same conacts using 'No Duplicate Checking' | |
272 | $this->importContacts($headers, $rows, 'Household', 'No Duplicate Checking', array(), $other); | |
273 | } | |
274 | ||
275 | /* | |
276 | * Helper function to create Household Subtype. | |
277 | */ | |
4cbe18b8 EM |
278 | /** |
279 | * @return string | |
280 | */ | |
00be9182 | 281 | public function _createHouseholdSubtype() { |
6a488035 TO |
282 | |
283 | // Visit to create contact subtype | |
071a6d2e | 284 | $this->openCiviPage("admin/options/subtype", "action=add&reset=1"); |
6a488035 TO |
285 | |
286 | // Create Household subtype | |
287 | $householdSubtype = substr(sha1(rand()), 0, 7); | |
288 | $this->type("label", $householdSubtype); | |
289 | $this->select("parent_id", "label=Household"); | |
290 | $this->click("_qf_ContactType_next-bottom"); | |
291 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
292 | return $householdSubtype; | |
293 | } | |
294 | ||
295 | /* | |
296 | * Helper function to provide data for contact import for Individuals Subtype. | |
297 | */ | |
4cbe18b8 EM |
298 | /** |
299 | * @return array | |
300 | */ | |
00be9182 | 301 | public function _individualSubtypeCSVData() { |
6a488035 TO |
302 | $headers = array( |
303 | 'first_name' => 'First Name', | |
304 | 'middle_name' => 'Middle Name', | |
305 | 'last_name' => 'Last Name', | |
306 | 'email' => 'Email', | |
307 | 'phone' => 'Phone', | |
308 | 'address_1' => 'Additional Address 1', | |
309 | 'address_2' => 'Additional Address 2', | |
310 | 'city' => 'City', | |
311 | 'state' => 'State', | |
312 | 'country' => 'Country', | |
313 | ); | |
314 | ||
315 | $rows = array( | |
6c6e6187 | 316 | array( |
92915c55 | 317 | 'first_name' => substr(sha1(rand()), 0, 7), |
6a488035 TO |
318 | 'middle_name' => substr(sha1(rand()), 0, 7), |
319 | 'last_name' => 'Anderson', | |
320 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', | |
321 | 'phone' => '6949912154', | |
322 | 'address_1' => 'Add 1', | |
323 | 'address_2' => 'Add 2', | |
324 | 'city' => 'Watson', | |
325 | 'state' => 'NY', | |
86797006 | 326 | 'country' => 'UNITED STATES', |
6a488035 | 327 | ), |
6c6e6187 | 328 | array( |
92915c55 | 329 | 'first_name' => substr(sha1(rand()), 0, 7), |
6a488035 TO |
330 | 'middle_name' => substr(sha1(rand()), 0, 7), |
331 | 'last_name' => 'Summerson', | |
332 | 'email' => substr(sha1(rand()), 0, 7) . '@example.com', | |
333 | 'phone' => '6944412154', | |
334 | 'address_1' => 'Add 1', | |
335 | 'address_2' => 'Add 2', | |
336 | 'city' => 'Watson', | |
337 | 'state' => 'NY', | |
86797006 | 338 | 'country' => 'UNITED STATES', |
6a488035 TO |
339 | ), |
340 | ); | |
341 | ||
342 | return array($headers, $rows); | |
343 | } | |
344 | ||
345 | /* | |
346 | * Helper function to provide data for contact import for Organizations Subtype. | |
347 | */ | |
4cbe18b8 EM |
348 | /** |
349 | * @return array | |
350 | */ | |
00be9182 | 351 | public function _organizationSubtypeCSVData() { |
6a488035 TO |
352 | $headers = array( |
353 | 'organization_name' => 'Organization Name', | |
354 | 'email' => 'Email', | |
355 | 'phone' => 'Phone', | |
356 | 'address_1' => 'Additional Address 1', | |
357 | 'address_2' => 'Additional Address 2', | |
358 | 'city' => 'City', | |
359 | 'state' => 'State', | |
360 | 'country' => 'Country', | |
361 | ); | |
362 | ||
363 | $rows = array( | |
6c6e6187 | 364 | array( |
92915c55 | 365 | 'organization_name' => 'org_' . substr(sha1(rand()), 0, 7), |
6a488035 TO |
366 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', |
367 | 'phone' => '9949912154', | |
368 | 'address_1' => 'Add 1', | |
369 | 'address_2' => 'Add 2', | |
370 | 'city' => 'Watson', | |
371 | 'state' => 'NY', | |
86797006 | 372 | 'country' => 'UNITED STATES', |
6a488035 | 373 | ), |
6c6e6187 | 374 | array( |
92915c55 | 375 | 'organization_name' => 'org_' . substr(sha1(rand()), 0, 7), |
6a488035 TO |
376 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', |
377 | 'phone' => '6949412154', | |
378 | 'address_1' => 'Add 1', | |
379 | 'address_2' => 'Add 2', | |
380 | 'city' => 'Watson', | |
381 | 'state' => 'NY', | |
86797006 | 382 | 'country' => 'UNITED STATES', |
6a488035 TO |
383 | ), |
384 | ); | |
385 | ||
386 | return array($headers, $rows); | |
387 | } | |
388 | ||
389 | /* | |
390 | * Helper function to provide data for contact import for Household Subtype. | |
391 | */ | |
4cbe18b8 EM |
392 | /** |
393 | * @return array | |
394 | */ | |
00be9182 | 395 | public function _householdSubtypeCSVData() { |
6a488035 TO |
396 | $headers = array( |
397 | 'household_name' => 'Household Name', | |
398 | 'email' => 'Email', | |
399 | 'phone' => 'Phone', | |
400 | 'address_1' => 'Additional Address 1', | |
401 | 'address_2' => 'Additional Address 2', | |
402 | 'city' => 'City', | |
403 | 'state' => 'State', | |
404 | 'country' => 'Country', | |
405 | ); | |
406 | ||
407 | $rows = array( | |
6c6e6187 | 408 | array( |
92915c55 | 409 | 'household_name' => 'household_' . substr(sha1(rand()), 0, 7), |
6a488035 TO |
410 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', |
411 | 'phone' => '3949912154', | |
412 | 'address_1' => 'Add 1', | |
413 | 'address_2' => 'Add 2', | |
414 | 'city' => 'Watson', | |
415 | 'state' => 'NY', | |
86797006 | 416 | 'country' => 'UNITED STATES', |
6a488035 | 417 | ), |
6c6e6187 | 418 | array( |
92915c55 | 419 | 'household_name' => 'household_' . substr(sha1(rand()), 0, 7), |
6a488035 TO |
420 | 'email' => substr(sha1(rand()), 0, 7) . '@example.org', |
421 | 'phone' => '5949412154', | |
422 | 'address_1' => 'Add 1', | |
423 | 'address_2' => 'Add 2', | |
424 | 'city' => 'Watson', | |
425 | 'state' => 'NY', | |
86797006 | 426 | 'country' => 'UNITED STATES', |
6a488035 TO |
427 | ), |
428 | ); | |
429 | ||
430 | return array($headers, $rows); | |
431 | } | |
96025800 | 432 | |
6a488035 | 433 | } |