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