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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 25 | */ |
6a488035 | 26 | |
6a488035 | 27 | require_once 'WebTest/Export/ExportCiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Export_ContactTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
9b873358 | 38 | public function testPrefixGenderSuffix() { |
e0bbb596 AS |
39 | $this->webtestLogin(); |
40 | ||
41 | // Create new group | |
42 | $parentGroupName = 'TestSuffixPrefixGender_' . substr(sha1(rand()), 0, 7); | |
beea38fc | 43 | $this->WebtestAddGroup($parentGroupName); |
e0bbb596 AS |
44 | |
45 | // Adding Parent group contact | |
46 | // We're using Quick Add block on the main page for this. | |
47 | $firstContactName = 'TestExport' . substr(sha1(rand()), 0, 7); | |
542e6ea1 | 48 | |
6c6e6187 | 49 | list($emailContactFirst, $prefixLabelContactFrst, $suffixLabelContactFrst, $genderLabelContactFrst) = WebTest_Export_ContactTest::webtestAddContactWithGenderPrefixSuffix($firstContactName, "Smith", "$firstContactName.smith@example.org", NULL); |
e0bbb596 AS |
50 | |
51 | $sortFirstName = "Smith, $firstContactName"; | |
52 | $displayFirstName = "$firstContactName Smith"; | |
53 | ||
54 | // Add contact to parent group | |
55 | // visit group tab. | |
56 | $this->click("css=li#tab_group a"); | |
57 | $this->waitForElementPresent("group_id"); | |
58 | ||
59 | // Add to group. | |
60 | $this->select("group_id", "label=$parentGroupName"); | |
61 | $this->click("_qf_GroupContact_next"); | |
beea38fc | 62 | $this->waitForAjaxContent(); |
e0bbb596 | 63 | |
e0bbb596 | 64 | $secondContactName = 'TestExport2' . substr(sha1(rand()), 0, 7); |
6c6e6187 | 65 | list($emailContactSecond, $prefixLabelContactScnd, $suffixLabelContactScnd, $genderLabelContactScnd) = WebTest_Export_ContactTest::webtestAddContactWithGenderPrefixSuffix($secondContactName, "John", "$secondContactName.john@example.org", NULL); |
e0bbb596 AS |
66 | |
67 | $sortSecondName = "John, $secondContactName"; | |
68 | $displaySecondName = "$secondContactName John"; | |
69 | ||
70 | // Add contact to parent group | |
71 | // visit group tab. | |
72 | $this->click("css=li#tab_group a"); | |
73 | $this->waitForElementPresent("group_id"); | |
74 | ||
75 | // Add to group. | |
76 | $this->select("group_id", "label=$parentGroupName"); | |
77 | $this->click("_qf_GroupContact_next"); | |
beea38fc | 78 | $this->waitForAjaxContent(); |
e0bbb596 AS |
79 | |
80 | $this->openCiviPage("contact/search", "reset=1"); | |
81 | ||
82 | // Select contact type as Indiividual. | |
83 | $this->select("contact_type", "value=Individual"); | |
84 | ||
85 | // Select group. | |
86 | $this->select("group", "label=$parentGroupName"); | |
87 | ||
88 | // Click to search. | |
beea38fc | 89 | $this->clickLink("_qf_Basic_refresh"); |
e0bbb596 AS |
90 | |
91 | // Is contact present in search result? | |
92 | $this->assertElementContainsText('css=div.crm-search-results', $sortFirstName, "Contact did not found in search result!"); | |
93 | ||
94 | // Is contact present in search result? | |
95 | $this->assertElementContainsText('css=div.crm-search-results', $sortSecondName, "Contact did not found in search result!"); | |
96 | ||
97 | // select to export all the contasct from search result. | |
98 | $this->click("CIVICRM_QFID_ts_all_4"); | |
99 | ||
100 | // Select the task action to export. | |
101 | $this->click("task"); | |
102 | $this->select("task", "label=Export Contacts"); | |
e0bbb596 AS |
103 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
104 | ||
105 | $csvFile = $this->downloadCSV("_qf_Select_next-bottom"); | |
106 | ||
107 | // Build header row for assertion. | |
108 | require_once 'CRM/Contact/BAO/Contact.php'; | |
109 | $expotableFields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE); | |
110 | ||
111 | $checkHeaders = array(); | |
112 | foreach ($expotableFields as $key => $field) { | |
113 | // Exclude custom fields. | |
114 | if ($key && (substr($key, 0, 6) == 'custom')) { | |
115 | continue; | |
116 | } | |
117 | $checkHeaders[] = $field['title']; | |
118 | } | |
119 | ||
120 | // All other rows to be check. | |
121 | $checkRows = array( | |
122 | 1 => array( | |
e0bbb596 AS |
123 | 'First Name' => $secondContactName, |
124 | 'Last Name' => 'John', | |
92fcb95f | 125 | 'Email' => '' . strtolower($emailContactSecond) . '', |
542e6ea1 AS |
126 | 'Individual Suffix' => $suffixLabelContactScnd, |
127 | 'Gender' => $genderLabelContactScnd, | |
e0bbb596 | 128 | ), |
fc0a5af6 | 129 | 2 => array( |
130 | 'First Name' => $firstContactName, | |
131 | 'Last Name' => 'Smith', | |
132 | 'Email' => '' . strtolower($emailContactFirst) . '', | |
133 | 'Sort Name' => $sortFirstName, | |
134 | 'Display Name' => $prefixLabelContactFrst . ' ' . $displayFirstName . ' ' . $suffixLabelContactFrst, | |
135 | 'Individual Prefix' => $prefixLabelContactFrst, | |
136 | 'Individual Suffix' => $suffixLabelContactFrst, | |
137 | 'Gender' => $genderLabelContactFrst, | |
138 | ), | |
e0bbb596 AS |
139 | ); |
140 | ||
141 | // Read CSV and fire assertions. | |
142 | $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2); | |
143 | } | |
144 | ||
6a488035 TO |
145 | /** |
146 | * Test Contact Export. | |
147 | */ | |
00be9182 | 148 | public function testContactExport() { |
6a488035 TO |
149 | $this->webtestLogin(); |
150 | ||
151 | // Create new group | |
152 | $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7); | |
beea38fc | 153 | $this->WebtestAddGroup($parentGroupName); |
6a488035 TO |
154 | |
155 | // Create new group and select the previously selected group as parent group for this new group. | |
156 | $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7); | |
beea38fc | 157 | $this->WebtestAddGroup($childGroupName, $parentGroupName); |
6a488035 TO |
158 | |
159 | // Adding Parent group contact | |
160 | // We're using Quick Add block on the main page for this. | |
161 | $firstName = 'a' . substr(sha1(rand()), 0, 7); | |
162 | $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org"); | |
163 | ||
164 | $sortName = "Smith, $firstName"; | |
165 | $displayName = "$firstName Smith"; | |
166 | ||
167 | // Add contact to parent group | |
168 | // visit group tab. | |
169 | $this->click("css=li#tab_group a"); | |
170 | $this->waitForElementPresent("group_id"); | |
171 | ||
172 | // Add to group. | |
173 | $this->select("group_id", "label=$parentGroupName"); | |
174 | $this->click("_qf_GroupContact_next"); | |
beea38fc | 175 | $this->waitForAjaxContent(); |
6a488035 TO |
176 | |
177 | // Adding child group contact | |
178 | // We're using Quick Add block on the main page for this. | |
179 | $childName = 'b' . substr(sha1(rand()), 0, 7); | |
180 | $this->webtestAddContact($childName, "John", "$childName.john@example.org"); | |
181 | ||
182 | $childSortName = "John, $childName"; | |
183 | $childDisplayName = "$childName John"; | |
184 | ||
185 | // Add contact to child group | |
186 | // visit group tab. | |
187 | $this->click("css=li#tab_group a"); | |
188 | $this->waitForElementPresent("group_id"); | |
189 | ||
190 | // Add to child group. | |
191 | $this->select("group_id", "label=regexp:$childGroupName"); | |
192 | $this->click("_qf_GroupContact_next"); | |
beea38fc | 193 | $this->waitForAjaxContent(); |
6a488035 TO |
194 | |
195 | // Visit contact search page. | |
cb5b38f1 | 196 | $this->openCiviPage("contact/search", "reset=1"); |
6a488035 TO |
197 | |
198 | // Select contact type as Indiividual. | |
199 | $this->select("contact_type", "value=Individual"); | |
200 | ||
201 | // Select group. | |
202 | $this->select("group", "label=$parentGroupName"); | |
203 | ||
204 | // Click to search. | |
beea38fc | 205 | $this->clickLink("_qf_Basic_refresh"); |
6a488035 TO |
206 | |
207 | // Is contact present in search result? | |
a5a7f3f2 | 208 | $this->assertElementContainsText('css=div.crm-search-results', $sortName, "Contact did not found in search result!"); |
76e86fd8 | 209 | |
6a488035 | 210 | // Is contact present in search result? |
a5a7f3f2 | 211 | $this->assertElementContainsText('css=div.crm-search-results', $childSortName, "Contact did not found in search result!"); |
76e86fd8 | 212 | |
6a488035 TO |
213 | // select to export all the contasct from search result. |
214 | $this->click("CIVICRM_QFID_ts_all_4"); | |
215 | ||
216 | // Select the task action to export. | |
217 | $this->click("task"); | |
218 | $this->select("task", "label=Export Contacts"); | |
6a488035 TO |
219 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
220 | ||
221 | $csvFile = $this->downloadCSV("_qf_Select_next-bottom"); | |
222 | ||
223 | // Build header row for assertion. | |
224 | require_once 'CRM/Contact/BAO/Contact.php'; | |
225 | $expotableFields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE); | |
226 | ||
227 | $checkHeaders = array(); | |
228 | foreach ($expotableFields as $key => $field) { | |
229 | // Exclude custom fields. | |
230 | if ($key && (substr($key, 0, 6) == 'custom')) { | |
231 | continue; | |
232 | } | |
233 | $checkHeaders[] = $field['title']; | |
234 | } | |
235 | ||
236 | // All other rows to be check. | |
237 | $checkRows = array( | |
238 | 1 => array( | |
6a488035 TO |
239 | 'First Name' => $childName, |
240 | 'Last Name' => 'John', | |
241 | 'Email' => "$childName.john@example.org", | |
242 | 'Sort Name' => $childSortName, | |
243 | 'Display Name' => $childDisplayName, | |
244 | ), | |
fc0a5af6 | 245 | 2 => array( |
246 | 'First Name' => $firstName, | |
247 | 'Last Name' => 'Smith', | |
248 | 'Email' => "$firstName.smith@example.org", | |
249 | 'Sort Name' => $sortName, | |
250 | 'Display Name' => $displayName, | |
251 | ), | |
6a488035 TO |
252 | ); |
253 | ||
254 | // Read CSV and fire assertions. | |
255 | $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2); | |
256 | } | |
257 | ||
00be9182 | 258 | public function testMergeHousehold() { |
6a488035 TO |
259 | $this->webtestLogin(); |
260 | ||
261 | // Create new group | |
262 | $groupName = 'TestGroup_' . substr(sha1(rand()), 0, 7); | |
beea38fc | 263 | $this->WebtestAddGroup($groupName); |
6a488035 TO |
264 | |
265 | // Adding Parent group contact | |
266 | // We're using Quick Add block on the main page for this. | |
267 | $houseHold = 'H' . substr(sha1(rand()), 0, 5) . ' House'; | |
268 | ||
cb5b38f1 | 269 | $this->openCiviPage("contact/add", "reset=1&ct=Household"); |
6a488035 TO |
270 | $this->click('household_name'); |
271 | $this->type('household_name', $houseHold); | |
272 | ||
273 | //address section | |
274 | $this->click("addressBlock"); | |
275 | $this->waitForElementPresent("address_1_street_address"); | |
276 | ||
277 | // fill in address | |
278 | $this->click("//div[@id='addressBlockId']/div[1]"); | |
279 | $this->type("address_1_street_address", "121A Sherman St. Apt. 12"); | |
280 | $this->type("address_1_city", "Dumfries"); | |
281 | $this->type("address_1_postal_code", "1234"); | |
fc0a5af6 | 282 | $this->select("address_1_country_id", "United States"); |
6a488035 TO |
283 | $this->select("address_1_state_province_id", "value=1019"); |
284 | ||
285 | $this->click('_qf_Contact_upload_view'); | |
286 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
287 | ||
288 | // Add contact to group | |
289 | // visit group tab. | |
290 | $this->click("css=li#tab_group a"); | |
291 | $this->waitForElementPresent("group_id"); | |
292 | ||
293 | // Add to group. | |
294 | $this->select("group_id", "label=$groupName"); | |
295 | $this->click("_qf_GroupContact_next"); | |
beea38fc | 296 | $this->waitForAjaxContent(); |
6a488035 | 297 | |
6a488035 TO |
298 | $firstName1 = 'aa' . substr(sha1(rand()), 0, 5); |
299 | $this->webtestAddContact($firstName1, "Smith", "{$firstName1}.smith@example.org"); | |
300 | ||
301 | $sortName1 = "Smith, {$firstName1}"; | |
302 | $displayName1 = "{$firstName1} Smith"; | |
303 | ||
304 | // Add contact to parent group | |
305 | // visit group tab. | |
306 | $this->click("css=li#tab_group a"); | |
307 | $this->waitForElementPresent("group_id"); | |
308 | ||
309 | // Add to group. | |
310 | $this->select("group_id", "label=$groupName"); | |
311 | $this->click("_qf_GroupContact_next"); | |
beea38fc | 312 | $this->waitForAjaxContent(); |
6a488035 TO |
313 | |
314 | $firstName2 = 'bb' . substr(sha1(rand()), 0, 5); | |
315 | ||
cb5b38f1 | 316 | $this->openCiviPage("contact/add", "reset=1&ct=Individual", "_qf_Contact_upload_view-bottom"); |
6a488035 TO |
317 | $this->type('first_name', $firstName2); |
318 | $this->type('last_name', "Smith"); | |
319 | $this->type('email_1_email', "{$firstName2}.smith@example.org"); | |
320 | ||
321 | //address section | |
322 | $this->click("addressBlock"); | |
323 | $this->waitForElementPresent("address_1_street_address"); | |
324 | ||
325 | $this->click("//div[@id='addressBlockId']/div[1]"); | |
326 | ||
327 | $this->click("address[1][use_shared_address]"); | |
45fabf8e | 328 | $this->waitForElementPresent("address_1_master_contact_id"); |
329 | $this->select2('address_1_master_contact_id', $houseHold); | |
6a488035 TO |
330 | $this->waitForTextPresent("121A Sherman"); |
331 | ||
332 | $this->click('_qf_Contact_upload_view-bottom'); | |
333 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
334 | ||
335 | $sortName2 = "Smith, {$firstName2}"; | |
336 | $displayName2 = "{$firstName2} Smith"; | |
337 | ||
338 | // Add contact to parent group | |
339 | // visit group tab. | |
340 | $this->click("css=li#tab_group a"); | |
341 | $this->waitForElementPresent("group_id"); | |
342 | ||
343 | // Add to group. | |
344 | $this->select("group_id", "label=$groupName"); | |
345 | $this->click("_qf_GroupContact_next"); | |
beea38fc | 346 | $this->waitForAjaxContent(); |
6a488035 | 347 | |
60879f50 | 348 | $this->openCiviPage("contact/search", "reset=1", NULL); |
6a488035 TO |
349 | |
350 | // Select group. | |
351 | $this->select("group", "label=$groupName"); | |
352 | ||
353 | // Click to search. | |
beea38fc | 354 | $this->clickLink("_qf_Basic_refresh"); |
6a488035 TO |
355 | |
356 | // Is contact present in search result? | |
a5a7f3f2 | 357 | $this->assertElementContainsText('css=div.crm-search-results', $sortName1, "Contact did not found in search result!"); |
76e86fd8 | 358 | |
6a488035 | 359 | // Is contact present in search result? |
a5a7f3f2 | 360 | $this->assertElementContainsText('css=div.crm-search-results', $sortName2, "Contact did not found in search result!"); |
76e86fd8 | 361 | |
6a488035 | 362 | // Is contact present in search result? |
a5a7f3f2 | 363 | $this->assertElementContainsText('css=div.crm-search-results', $houseHold, "Contact did not found in search result!"); |
76e86fd8 | 364 | |
6a488035 TO |
365 | // select to export all the contasct from search result. |
366 | $this->click("CIVICRM_QFID_ts_all_4"); | |
367 | ||
368 | // Select the task action to export. | |
369 | $this->click("task"); | |
370 | $this->select("task", "label=Export Contacts"); | |
6a488035 TO |
371 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
372 | ||
373 | $this->click("CIVICRM_QFID_2_10"); | |
374 | ||
375 | $csvFile = $this->downloadCSV("_qf_Select_next-bottom"); | |
376 | ||
377 | // Build header row for assertion. | |
378 | require_once 'CRM/Contact/BAO/Contact.php'; | |
379 | $expotableFields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE); | |
380 | ||
381 | $checkHeaders = array(); | |
382 | foreach ($expotableFields as $key => $field) { | |
383 | // Exclude custom fields. | |
384 | if ($key && (substr($key, 0, 6) == 'custom')) { | |
385 | continue; | |
386 | } | |
387 | $checkHeaders[] = $field['title']; | |
388 | } | |
389 | ||
390 | // All other rows to be check. | |
391 | $checkRows = array( | |
392 | 1 => array( | |
393 | 'Contact Type' => 'Household', | |
394 | 'Household Name' => $houseHold, | |
395 | ), | |
396 | 2 => array( | |
397 | 'Contact Type' => 'Individual', | |
398 | 'First Name' => $firstName1, | |
399 | 'Email' => "{$firstName1}.smith@example.org", | |
400 | 'Sort Name' => $sortName1, | |
401 | 'Display Name' => $displayName1, | |
402 | ), | |
403 | ); | |
404 | ||
405 | // Read CSV and fire assertions. | |
406 | $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2); | |
407 | } | |
408 | ||
4cbe18b8 EM |
409 | /** |
410 | * @param string $fname | |
411 | * @param string $lname | |
412 | * @param null $email | |
413 | * @param null $contactSubtype | |
414 | * | |
415 | * @return array | |
416 | */ | |
00be9182 | 417 | public function webtestAddContactWithGenderPrefixSuffix($fname = 'Anthony', $lname = 'Anderson', $email = NULL, $contactSubtype = NULL) { |
e0bbb596 AS |
418 | $url = $this->sboxPath . 'civicrm/contact/add?reset=1&ct=Individual'; |
419 | if ($contactSubtype) { | |
420 | $url = $url . "&cst={$contactSubtype}"; | |
421 | } | |
422 | $this->open($url); | |
423 | $this->waitForElementPresent('_qf_Contact_upload_view-bottom'); | |
424 | ||
425 | $this->type('first_name', $fname); | |
426 | $this->type('last_name', $lname); | |
427 | if ($email === TRUE) { | |
428 | $email = substr(sha1(rand()), 0, 7) . '@example.org'; | |
429 | } | |
430 | if ($email) { | |
431 | $this->type('email_1_email', $email); | |
432 | } | |
433 | $genderLabelArray = array( | |
434 | 1 => 'Female', | |
435 | 2 => 'Male', | |
21dfd5f5 | 436 | 3 => 'Transgender', |
e0bbb596 | 437 | ); |
542e6ea1 AS |
438 | $prefix = rand(1, 4); |
439 | $suffix = rand(1, 8); | |
440 | $gender = rand(1, 3); | |
92fcb95f | 441 | $genderLabel = "civicrm_gender_" . $genderLabelArray[$gender] . "_$gender"; |
e0bbb596 AS |
442 | $this->select("prefix_id", "value=$prefix"); |
443 | $this->select("suffix_id", "value=$suffix"); | |
444 | $this->click("demographics"); | |
445 | $this->waitForElementPresent("civicrm_gender_Female_1"); | |
6c6e6187 | 446 | $this->click($genderLabel, "value=$gender"); |
e0bbb596 AS |
447 | $this->waitForElementPresent('_qf_Contact_upload_view-bottom'); |
448 | $this->click('_qf_Contact_upload_view-bottom'); | |
449 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
6c6e6187 TO |
450 | $prefixLabel = WebTest_Export_ContactTest::getOptionLabel('individual_prefix', $prefix); |
451 | $suffixLabel = WebTest_Export_ContactTest::getOptionLabel('individual_suffix', $suffix); | |
452 | $genderLabel = WebTest_Export_ContactTest::getOptionLabel('gender', $gender); | |
453 | return array($email, $prefixLabel, $suffixLabel, $genderLabel); | |
542e6ea1 AS |
454 | } |
455 | ||
4cbe18b8 | 456 | /** |
100fef9d | 457 | * @param string $optionGroupName |
4cbe18b8 EM |
458 | * @param $optionValue |
459 | * | |
460 | * @return array|int | |
461 | */ | |
9b873358 | 462 | public function getOptionLabel($optionGroupName, $optionValue) { |
542e6ea1 AS |
463 | $params = array( |
464 | 'version' => 3, | |
465 | 'sequential' => 1, | |
466 | 'option_group_name' => $optionGroupName, | |
467 | 'value' => $optionValue, | |
21dfd5f5 | 468 | 'return' => 'label', |
542e6ea1 | 469 | ); |
6c6e6187 | 470 | $optionLabel = $this->webtest_civicrm_api("OptionValue", "getvalue", $params); |
542e6ea1 | 471 | return $optionLabel; |
e0bbb596 | 472 | } |
96025800 | 473 | |
42daf119 | 474 | } |