Merge pull request #3317 from eileenmcnaughton/CRM-14197-postprocesfn
[civicrm-core.git] / tests / phpunit / WebTest / Contact / AdvancedSearchTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Contact_AdvancedSearchTest
31 */
32 class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testAdvanceSearch() {
39 $this->webtestLogin();
40 $this->waitForPageToLoad($this->getTimeoutMsec());
41
42 //------- first create new group and tag -----
43
44 // take group name and create group
45 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
46 $this->WebtestAddGroup($groupName);
47
48 // take a tag name and create tag
49 include_once 'WebTest/Contact/SearchTest.php';
50 $tagName = 'tag_' . substr(sha1(rand()), 0, 7);
51 WebTest_Contact_SearchTest::addTag($tagName, $this);
52
53 //---------- create detailed contact ---------
54
55 $firstName = substr(sha1(rand()), 0, 7);
56 $this->createDetailContact($firstName);
57
58 // go to group tab and add to new group
59 $this->click("css=li#tab_group a");
60 $this->waitForElementPresent("_qf_GroupContact_next");
61 $this->select("group_id", "$groupName");
62 $this->click("_qf_GroupContact_next");
63
64 // go to tag tab and add to new tag
65 $this->click("css=li#tab_tag a");
66 $this->waitForElementPresent("css=div#tagtree");
67 $this->click("xpath=//ul/li/label[text()=\"$tagName\"]");
68 $this->waitForElementPresent("css=.success");
69
70 // is status message correct?
71 $this->waitForTextPresent("Saved");
72 $this->waitForText('crm-notification-container', "Saved");
73
74 // go to event tab and register for event ( auto add activity and contribution )
75 $this->click("css=li#tab_participant a");
76 $this->waitForElementPresent("link=Add Event Registration");
77 $this->click("link=Add Event Registration");
78 $this->waitForText('s2id_event_id', "- select event -");
79 // fall fundraiser dinner event label is variable
80 $this->select2("event_id", "Fall Fundraiser Dinner");
81 $this->waitForElementPresent("receipt_text");
82 $this->multiselect2("role_id", array('Volunteer'));
83 $this->click("CIVICRM_QFID_17_4");
84 $this->check("record_contribution");
85 $this->waitForElementPresent("contribution_status_id");
86 $this->select("payment_instrument_id", "Check");
87 $this->type("check_number", "chqNo$firstName");
88 $this->type("trxn_id", "trid$firstName");
89 $this->click("_qf_Participant_upload-bottom");
90 $this->waitForElementPresent("link=Add Event Registration");
91 $this->waitForText('crm-notification-container', "Event registration for $firstName adv$firstName has been added");
92
93 // go to pledge tab and add pledge
94 $this->click("css=li#tab_pledge a");
95 $this->waitForElementPresent("link=Add Pledge");
96 $this->click("link=Add Pledge");
97 $this->waitForElementPresent("contribution_page_id");
98 $this->type("amount", "200");
99 $this->type("installments", "5");
100 $this->type("frequency_interval", "1");
101 $this->select("frequency_unit", "month(s)");
102 $this->click("_qf_Pledge_upload-bottom");
103 $this->waitForElementPresent("link=Add Pledge");
104
105 $this->waitForText('crm-notification-container', "Pledge has been recorded and the payment schedule has been created.");
106
107 // go to Membership tab and add membership
108 $this->click("css=li#tab_member a");
109 $this->waitForElementPresent("link=Add Membership");
110 $this->clickLink("link=Add Membership", "_qf_Membership_cancel-bottom", FALSE);
111 //let the organisation be default (Default Organization)
112 $this->select("membership_type_id[0]", "value=1");
113 $this->click("membership_type_id[1]");
114 $this->select("membership_type_id[1]", "Student");
115 $this->type("source", "membership source$firstName");
116 $this->clickLink("_qf_Membership_upload-bottom", "link=Add Membership", FALSE);
117
118 $this->waitForText('crm-notification-container', "Student membership for $firstName adv$firstName has been added");
119
120 // go to relationship tab and add relationship
121 $this->click("css=li#tab_rel a");
122 $this->waitForElementPresent("link=Add Relationship");
123 $this->click("link=Add Relationship");
124 $this->waitForElementPresent("_qf_Relationship_cancel");
125 $this->select2("relationship_type_id", "Employee of");
126 $this->waitForElementPresent("xpath=//input[@id='related_contact_id'][@placeholder='- select organization -']");
127 $this->select2("related_contact_id", "Default", TRUE);
128 $this->webtestFillDate("start_date", "-1 day");
129 $this->webtestFillDate("end_date", "+1 day");
130 $this->click('_qf_Relationship_upload-bottom');
131 $this->waitForText('crm-notification-container', "Relationship created.");
132
133 //-------------- advance search --------------
134
135 $this->openCiviPage('contact/search/advanced', 'reset=1');
136
137 //also create a dummy name to test false
138 $dummyName = substr(sha1(rand()), 0, 7);
139
140 // search block array for adv search
141 $searchBlockValues = array(
142 'basic' => array('', 'addBasicSearchDetail'),
143 'location' => array('state_province', 'addAddressSearchDetail'),
144 'demographics' => array('civicrm_gender_Transgender_3', 'addDemographicSearchDetail'),
145 'notes' => array('note', ''),
146 'activity' => array('activity_status[5]', 'addActivitySearchDetail'),
147 'CiviContribute' => array('contribution_currency_type', 'addContributionSearchDetail'),
148 'CiviEvent' => array('participant_fee_amount_high', 'addParticipantSearchDetail'),
149 'CiviMember' => array('member_end_date_high', 'addMemberSearchDetail'),
150 'CiviPledge' => array('pledge_frequency_interval', 'addPledgeSearchDetail'),
151 'relationship' => array("xpath=//div[@id='relationship']/table/tbody/tr//td/label[text()='Relationship Status']/../label[text()='All']", ''),
152 );
153
154 foreach ($searchBlockValues as $block => $blockValues) {
155 switch ($block) {
156 case 'basic':
157 $this->$blockValues[1]($firstName, $groupName, $tagName);
158 break;
159
160 case 'notes':
161 $this->click("$block");
162 $this->waitForElementPresent("$blockValues[0]");
163 $this->type("note", "this is notes by $firstName");
164 break;
165
166 case 'relationship':
167 $this->click("$block");
168 $this->waitForElementPresent("$blockValues[0]");
169 $this->select("relation_type_id", "Employee of");
170 $this->type("relation_target_name", "Default");
171 break;
172
173 default:
174 $this->click("$block");
175 $this->waitForElementPresent("$blockValues[0]");
176 $this->$blockValues[1]($firstName);
177 break;
178 }
179 $this->submitSearch($firstName);
180 }
181
182 //-- search with non existing value ( sort name )
183 $this->type("sort_name", "$dummyName");
184 $this->clickLink("_qf_Advanced_refresh");
185 $this->waitForText("xpath=//form[@id='Advanced']/div[3]/div/div", "No matches found for");
186 }
187
188 /*
189 * Check for CRM-9873
190 */
191 function testActivitySearchByTypeTest() {
192 $this->webtestLogin();
193 $this->openCiviPage('contact/search/advanced', 'reset=1');
194 $this->click("activity");
195 $this->waitForElementPresent('activity_subject');
196 $this->check("xpath=//div[@id='Activity']//div/label[text()='Tell a Friend']/../input");
197 $this->click("_qf_Advanced_refresh");
198 $this->waitForPageToLoad($this->getTimeoutMsec());
199 $count = explode(" ", trim($this->getText("xpath=//div[@id='search-status']/table/tbody/tr/td")));
200 $count = $count[0];
201 $this->assertTrue(is_numeric($count), "The total count of search results not found");
202
203 //pagination calculation
204 $perPageRow = 50;
205 if ($count > $perPageRow) {
206 $cal = $count / $perPageRow;
207 $mod = $count % $perPageRow;
208 $j = 1;
209 for ($i=1; $i<=$cal; $i++) {
210 $subTotal = $i * $perPageRow;
211 $lastPageSub = $subTotal + 1;
212
213 //pagination and row count assertion
214 $pagerCount = "Contact {$j} - {$subTotal} of {$count}";
215 $this->verifyText("xpath=//div[@class='crm-search-results']/div[@class='crm-pager']/span[@class='crm-pager-nav']", preg_quote($pagerCount));
216 $this->assertEquals($perPageRow, $this->getXpathCount("//div[@class='crm-search-results']/table/tbody/tr"));
217
218 //go to next page
219 $this->click("xpath=//div[@class='crm-search-results']/div[@class='crm-pager']/span[@class='crm-pager-nav']/a[@title='next page']");
220 $this->waitForElementPresent("Go");
221 $j = $j + $subTotal;
222 }
223
224 //pagination and row count assertion for the remaining last page
225 if ($mod) {
226 $pagerCount = "Contact {$lastPageSub} - {$count} of {$count}";
227 $this->verifyText("xpath=//div[@class='crm-search-results']/div[@class='crm-pager']/span[@class='crm-pager-nav']", preg_quote($pagerCount));
228 $this->assertEquals($mod, $this->getXpathCount("//div[@class='crm-search-results']/table/tbody/tr"));
229 }
230 }
231 }
232
233 //function to check match for sumbit Advance Search
234 /**
235 * @param $firstName
236 */
237 function submitSearch($firstName) {
238 $this->clickLink("_qf_Advanced_refresh");
239 // verify unique name
240 $this->waitForText("xpath=//div[@class='crm-search-results']/table/tbody", preg_quote("adv$firstName, $firstName"));
241 // should give 1 result only as we are searching with unique name
242 $this->waitForText("xpath=//div[@id='search-status']/table/tbody/tr/td", preg_quote("1 Contact"));
243 // click to edit search
244 $this->click("xpath=//form[@id='Advanced']//div[2]/div/div[1]");
245 }
246
247 // function to fill auto complete
248 /**
249 * @param $text
250 * @param $elementId
251 */
252 function fillAutoComplete($text, $elementId) {
253 $this->click("$elementId");
254 $this->type("$elementId", "$text");
255 $this->typeKeys("$elementId", "$text");
256 $this->waitForElementPresent("css=div.ac_results li");
257 $this->click("css=div.ac_results li");
258 $this->assertContains($text, $this->getValue("$elementId"),
259 "autocomplete expected $text but didn’t find it in " . $this->getValue("$elementId")
260 );
261 }
262
263 // function to fill basic search detail
264 /**
265 * @param $firstName
266 * @param $groupName
267 * @param $tagName
268 */
269 function addBasicSearchDetail($firstName, $groupName, $tagName) {
270 // fill partial sort name
271 $this->type("sort_name", "$firstName");
272 // select subtype
273 $this->select("contact_type", "value=Individual\ 1Student");
274 // select group
275 $this->select("group", "label=$groupName");
276 // select tag
277 $this->select("contact_tags", "label=$tagName");
278 // select prefered language
279 $this->select("preferred_language", "value=en_US");
280 // select privacy
281 $this->select("privacy_options", "value=do_not_email");
282
283 // select preferred communication method
284 // phone
285 $this->check("preferred_communication_method[1]");
286 // email
287 $this->check("preferred_communication_method[2]");
288 }
289
290 // function to fill address search block values in advance search
291 /**
292 * @param $firstName
293 */
294 function addAddressSearchDetail($firstName) {
295 // select location type (home and main)
296 $this->click("xpath=//div[@id='location']/table/tbody/tr[1]/td[1]//label[text()='Home']");
297 $this->click("xpath=//div[@id='location']/table/tbody/tr[1]/td[1]//label[text()='Main']");
298 // fill street address
299 $this->type("street_address", "street 1 $firstName");
300 // fill city
301 $this->type("city", "city$firstName");
302 // fill postal code range
303 $this->type("postal_code_low", "100010");
304 $this->type("postal_code_high", "101000");
305 // select country
306 $this->select("country", "United States");
307 // select state-province
308 $this->select("state_province", "Alaska");
309 }
310
311 // function to fill activity search block in advance search
312 /**
313 * @param $firstName
314 */
315 function addActivitySearchDetail($firstName) {
316 // check activity types
317 $checkActivityTypes = array("Contribution", "Event Registration", "Membership Signup");
318 foreach ($checkActivityTypes as $labels) {
319 $this->click("xpath=//div[@id='activity']/table/tbody/tr[2]/td[1]/div[1]//div/label[text()=\"$labels\"]");
320 }
321 // fill date range
322 $this->select("activity_date_relative","value=0");
323 $this->webtestFillDate("activity_date_low", "-1 day");
324 $this->webtestFillDate("activity_date_high", "+1 day");
325 $this->type("activity_subject", "Student - membership source$firstName - Status: New");
326 // fill activity status
327
328 $this->click("xpath=//div[@id='activity']/table/tbody//tr/td[2]/label[text()='Activity Status']/../label[text()='Scheduled']");
329 $this->click("xpath=//div[@id='activity']/table/tbody//tr/td[2]/label[text()='Activity Status']/../label[text()='Completed']");
330 }
331
332 // function to fill demographic search details
333 function addDemographicSearchDetail() {
334 // fill birth date range
335 $this->select("birth_date_relative","value=0");
336 $this->webtestFillDate("birth_date_low", "-3 year");
337 $this->webtestFillDate("birth_date_high", "now");
338 // fill deceased date range
339 $this->click("xpath=//div[@id='demographics']/table/tbody//tr/td/label[text()='Deceased']/../label[text()='Yes']");
340 $this->select("deceased_date_relative","value=0");
341 $this->webtestFillDate("deceased_date_low", "-1 month");
342 $this->webtestFillDate("deceased_date_high", "+1 month");
343 // fill gender (male)
344 $this->check("civicrm_gender_Male_2");
345 }
346
347 //function to fill contribution search details
348 /**
349 * @param $firstName
350 */
351 function addContributionSearchDetail($firstName) {
352 // fill contribution date range
353 $this->select("contribution_date_relative","value=0");
354 $this->webtestFillDate("contribution_date_low", "-1 day");
355 $this->webtestFillDate("contribution_date_high", "+1 day");
356 // fill amount range
357 $this->type("contribution_amount_low", "1");
358 $this->type("contribution_amount_high", "200");
359 // check for completed
360 $this->check("contribution_status_id[1]");
361 // enter check number
362 $this->select("contribution_payment_instrument_id", "Check");
363 $this->type("contribution_check_number", "chqNo$firstName");
364 // fill transaction id
365 $this->type("contribution_transaction_id", "trid$firstName");
366 // fill financial type
367 $this->select("financial_type_id", "Event Fee");
368 // fill currency type
369 $this->select("contribution_currency_type", "USD");
370 }
371
372 // function to fill participant search details
373 function addParticipantSearchDetail() {
374 // fill event name
375 $this->select2("event_id", "Fall Fundraiser Dinner");
376 // fill event type
377 $this->select2("event_type_id", "Fundraiser");
378 // check participant status (registered)
379 $this->click("xpath=//div[@id='participantForm']/table/tbody//tr/td/label[text()='Participant Status']/../div//div/label[text()='Registered']");
380 // check participant role (Volunteer)
381 $this->click("xpath=//div[@id='participantForm']/table/tbody//tr/td/label[text()='Participant Role']/../div//div/label[text()='Volunteer']");
382 // fill participant fee level (couple)
383 $this->select2("participant_fee_id", "Couple");
384 // fill amount range
385 $this->type("participant_fee_amount_low", "1");
386 $this->type("participant_fee_amount_high", "150");
387 }
388
389 // function to fill member search details
390 /**
391 * @param $firstName
392 */
393 function addMemberSearchDetail($firstName) {
394 // check membership type (Student)
395 $this->click("xpath=//div[@id='memberForm']/table/tbody/tr[1]/td[1]/div[1]//div/label[text()='Student']");
396 // check membership status (completed)
397 $this->click("xpath=//div[@id='memberForm']/table/tbody/tr[1]/td[2]/div[1]//div/label[text()='New']");
398 // fill member source
399 $this->type("member_source", "membership source$firstName");
400 // check to search primary member
401 $this->click("xpath=//div[@id='memberForm']/table/tbody/tr[2]/td[2]/p/input");
402 // add join date range
403 $this->select("member_join_date_relative","value=0");
404 $this->webtestFillDate("member_join_date_low", "-1 day");
405 $this->webtestFillDate("member_join_date_high", "+1 day");
406 // add start date range
407 $this->select("member_start_date_relative","value=0");
408 $this->webtestFillDate("member_start_date_low", "-1 day");
409 $this->webtestFillDate("member_start_date_high", "+1 day");
410 // add end date range
411 $this->select("member_end_date_relative","value=0");
412 $this->webtestFillDate("member_end_date_low", "-1 year");
413 $this->webtestFillDate("member_end_date_high", "+2 year");
414 }
415
416 // function to fill member search details
417 /**
418 * @param $firstName
419 */
420 function addPledgeSearchDetail($firstName) {
421 // fill pledge schedule date range
422 $this->select("pledge_payment_date_relative","value=0");
423 $this->webtestFillDate("pledge_payment_date_low", "-1 day");
424 $this->webtestFillDate("pledge_payment_date_high", "+1 day");
425 // fill Pledge payment status
426 $this->click("xpath=//div[@id='pledgeForm']/table/tbody/tr[3]/td//label[text()='Completed']");
427 $this->click("xpath=//div[@id='pledgeForm']/table/tbody/tr[3]/td//label[text()='Pending']");
428 // fill pledge amount range
429 $this->type("pledge_amount_low", "100");
430 $this->type("pledge_amount_high", "300");
431 // fill plegde status
432 $this->click("xpath=//div[@id='pledgeForm']/table/tbody/tr[4]/td[2]//label[text()='Completed']");
433 $this->click("xpath=//div[@id='pledgeForm']/table/tbody/tr[4]/td[2]//label[text()='Pending']");
434 // fill pledge created date range
435 $this->webtestFillDate("pledge_create_date_low", "-5 day");
436 $this->webtestFillDate("pledge_create_date_high", "+5 day");
437 // fill plegde start date
438 $this->webtestFillDate("pledge_start_date_low", "-2 day");
439 $this->webtestFillDate("pledge_start_date_high", "+2 day");
440 // fill financial type
441 $this->select("pledge_financial_type_id", "Donation");
442 }
443
444 // function to create contact with details (contact details, address, Constituent information ...)
445 /**
446 * @param null $firstName
447 */
448 function createDetailContact($firstName = NULL) {
449 if (!$firstName) {
450 $firstName = substr(sha1(rand()), 0, 7);
451 }
452
453 // create contact type Individual with subtype
454 // with most of values to required to search
455 $Subtype = "Student";
456 $this->openCiviPage('contact/add', 'reset=1&ct=Individual', '_qf_Contact_cancel');
457
458 // --- fill few values in Contact Detail block
459 $this->type("first_name", "$firstName");
460 $this->type("middle_name", "mid$firstName");
461 $this->type("last_name", "adv$firstName");
462 $this->select("contact_sub_type", "label=$Subtype");
463 $this->type("email_1_email", "$firstName@advsearch.co.in");
464 $this->type("phone_1_phone", "123456789");
465 $this->type("external_identifier", "extid$firstName");
466
467 // --- fill few value in Constituent information
468 $this->click("customData1");
469 $this->waitForElementPresent("custom_3_-1");
470
471 $this->click("CIVICRM_QFID_Edu_2");
472 $this->select("custom_2_-1", "label=Single");
473
474 // --- fill few values in address
475
476 $this->click("//form[@id='Contact']/div[2]/div[4]/div[1]");
477 $this->waitForElementPresent("address_1_geo_code_2");
478 $this->type("address_1_street_address", "street 1 $firstName");
479 $this->type("address_1_supplemental_address_1", "street supplement 1 $firstName");
480 $this->type("address_1_supplemental_address_2", "street supplement 2 $firstName");
481 $this->type("address_1_city", "city$firstName");
482 $this->type("address_1_postal_code", "100100");
483 $this->select("address_1_country_id", "United States");
484 $this->select("address_1_state_province_id", "Alaska");
485
486 // --- fill few values in communication preferences
487 $this->click("//form[@id='Contact']/div[2]/div[5]/div[1]");
488 $this->waitForElementPresent("preferred_mail_format");
489 $this->check("privacy[do_not_phone]");
490 $this->check("privacy[do_not_mail]");
491 // phone
492 $this->check("preferred_communication_method[1]");
493 // email
494 $this->check("preferred_communication_method[2]");
495 $this->select("preferred_language", "value=en_US");
496
497 // --- fill few value in notes
498 $this->click("//form[@id='Contact']/div[2]/div[6]/div[1]");
499 $this->waitForElementPresent("note");
500 $this->type("subject", "this is subject by $firstName");
501 $this->type("note", "this is notes by $firstName");
502
503 // --- fill few values in demographics
504 $this->click("//form[@id='Contact']/div[2]/div[7]/div[1]");
505 $this->waitForElementPresent("is_deceased");
506 $this->click("civicrm_gender_Male_2");
507
508 $this->webtestFillDate("birth_date", "-1 year");
509 $this->click("is_deceased");
510 $this->waitForElementPresent("deceased_date");
511 $this->webtestFillDate("deceased_date", "now");
512
513 // save contact
514 $this->click("_qf_Contact_upload_view");
515 $this->waitForPageToLoad($this->getTimeoutMsec());
516 $this->assertElementContainsText('css=.crm-summary-display_name', "$firstName adv$firstName");
517 }
518 }
519