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