Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2014-10-07-19-33-29
[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 $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", "Advisory", TRUE);
235 $this->clickAjaxLink("location", 'country');
236 $this->select2("country", "United States", False);
237 $this->clickLink("_qf_Advanced_refresh");
238
239 $stateBeforeSort = $this->getText("xpath=//div[@class='crm-search-results']//table/tbody/tr[2]/td[6]");
240 $this->click("xpath=//div[@class='crm-search-results']//table/thead/tr//th/a[contains(text(),'State')]");
241 $this->waitForElementPresent("xpath=//div[@class='crm-search-results']//table/thead/tr//th/a[contains(text(),'State')]");
242 $this->assertElementNotContainsText("xpath=//div[@class='crm-search-results']//table/tbody/tr[2]/td[6]", $stateBeforeSort);
243 $this->clickAjaxLink("xpath=//form[@id='Advanced']//div//div[contains(text(),'Edit Search Criteria')]/../div", 'group');
244 $this->select2("group", "Summer", TRUE);
245 $this->waitForElementPresent('state_province');
246 $this->select2("state_province", "Ohio", TRUE);
247 $this->select2("state_province", "New York", TRUE);
248 $this->select2("state_province", "New Mexico", TRUE);
249 $this->select2("state_province", "Mississippi", TRUE);
250 $this->select2("state_province", "Connecticut", TRUE);
251 $this->select2("state_province", "Georgia", TRUE);
252 $this->select2("state_province", "New Jersey", TRUE);
253 $this->select2("state_province", "Texas", TRUE);
254 $this->clickLink("_qf_Advanced_refresh");
255
256 $stateBeforeSort = $this->getText("xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[6]");
257 $this->click("xpath=//div[@class='crm-search-results']//table/thead/tr//th/a[contains(text(),'State')]");
258 $this->waitForElementPresent("xpath=//div[@class='crm-search-results']//table/thead/tr//th/a[contains(text(),'State')]");
259 $this->assertElementNotContainsText("xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[6]", $stateBeforeSort);
260 }
261
262 // function to fill basic search detail
263 /**
264 * @param $firstName
265 * @param $groupName
266 * @param $tagName
267 */
268 function addBasicSearchDetail($firstName, $groupName, $tagName) {
269 // fill partial sort name
270 $this->type("sort_name", "$firstName");
271 // select subtype
272 $this->select("contact_type", "value=Individual\ 1Student");
273 // select group
274 $this->select("group", "label=$groupName");
275 // select tag
276 $this->select("contact_tags", "label=$tagName");
277 // select prefered language
278 $this->select("preferred_language", "value=en_US");
279 // select privacy
280 $this->select("privacy_options", "value=do_not_email");
281
282 // select preferred communication method
283 // phone
284 $this->check("preferred_communication_method[1]");
285 // email
286 $this->check("preferred_communication_method[2]");
287 }
288
289 // function to fill address search block values in advance search
290 /**
291 * @param $firstName
292 */
293 function addAddressSearchDetail($firstName) {
294 // select location type (home and main)
295 $this->multiselect2('location_type', array('Home', 'Main'));
296 // fill street address
297 $this->type("street_address", "street 1 $firstName");
298 // fill city
299 $this->type("city", "city$firstName");
300 // fill postal code range
301 $this->type("postal_code_low", "100010");
302 $this->type("postal_code_high", "101000");
303 // select country
304 $this->select("country", "United States");
305 // select state-province
306 $this->waitForElementPresent('state_province');
307 $this->select2("state_province", "Alaska", TRUE);
308 }
309
310 // function to fill activity search block in advance search
311 /**
312 * @param $firstName
313 */
314 function addActivitySearchDetail($firstName) {
315 // check activity types
316 $checkActivityTypes = array("Contribution", "Event Registration", "Membership Signup");
317 foreach ($checkActivityTypes as $labels) {
318 $this->click("xpath=//div[@id='activity']/table/tbody/tr[2]/td[1]/div[1]//div/label[text()=\"$labels\"]");
319 }
320 // fill date range
321 $this->select("activity_date_relative","value=0");
322 $this->webtestFillDate("activity_date_low", "-1 day");
323 $this->webtestFillDate("activity_date_high", "+1 day");
324 $this->type("activity_subject", "Student - membership source$firstName - Status: New");
325 // fill activity status
326
327 $this->click("xpath=//div[@id='activity']/table/tbody//tr/td[2]/label[text()='Activity Status']/../label[text()='Scheduled']");
328 $this->click("xpath=//div[@id='activity']/table/tbody//tr/td[2]/label[text()='Activity Status']/../label[text()='Completed']");
329 }
330
331 // function to fill demographic search details
332 function addDemographicSearchDetail() {
333 // fill birth date range
334 $this->select("birth_date_relative","value=0");
335 $this->webtestFillDate("birth_date_low", "-3 year");
336 $this->webtestFillDate("birth_date_high", "now");
337 // fill deceased date range
338 $this->click("xpath=//div[@id='demographics']/table/tbody//tr/td/label[text()='Deceased']/../label[text()='Yes']");
339 $this->select("deceased_date_relative","value=0");
340 $this->webtestFillDate("deceased_date_low", "-1 month");
341 $this->webtestFillDate("deceased_date_high", "+1 month");
342 // fill gender (male)
343 $this->check("civicrm_gender_Male_2");
344 }
345
346 //function to fill contribution search details
347 /**
348 * @param $firstName
349 */
350 function addContributionSearchDetail($firstName) {
351 // fill contribution date range
352 $this->select("contribution_date_relative","value=0");
353 $this->webtestFillDate("contribution_date_low", "-1 day");
354 $this->webtestFillDate("contribution_date_high", "+1 day");
355 // fill amount range
356 $this->type("contribution_amount_low", "1");
357 $this->type("contribution_amount_high", "200");
358 // check for completed
359 $this->check("contribution_status_id[1]");
360 // enter check number
361 $this->select("contribution_payment_instrument_id", "Check");
362 $this->type("contribution_check_number", "chqNo$firstName");
363 // fill transaction id
364 $this->type("contribution_transaction_id", "trid$firstName");
365 // fill financial type
366 $this->select("financial_type_id", "Event Fee");
367 // fill currency type
368 $this->select("contribution_currency_type", "USD");
369 }
370
371 // function to fill participant search details
372 function addParticipantSearchDetail() {
373 // fill event name
374 $this->select2("event_id", "Fall Fundraiser Dinner");
375 // fill event type
376 $this->select2("event_type_id", "Fundraiser");
377 // check participant status (registered)
378 $this->click("xpath=//div[@id='participantForm']/table/tbody//tr/td/label[text()='Participant Status']/../div//div/label[text()='Registered']");
379 // check participant role (Volunteer)
380 $this->click("xpath=//div[@id='participantForm']/table/tbody//tr/td/label[text()='Participant Role']/../div//div/label[text()='Volunteer']");
381 // fill participant fee level (couple)
382 $this->select2("participant_fee_id", "Couple");
383 // fill amount range
384 $this->type("participant_fee_amount_low", "1");
385 $this->type("participant_fee_amount_high", "150");
386 }
387
388 // function to fill member search details
389 /**
390 * @param $firstName
391 */
392 function addMemberSearchDetail($firstName) {
393 // check membership type (Student)
394 $this->click("xpath=//div[@id='memberForm']/table/tbody/tr[1]/td[1]/div[1]//div/label[text()='Student']");
395 // check membership status (completed)
396 $this->click("xpath=//div[@id='memberForm']/table/tbody/tr[1]/td[2]/div[1]//div/label[text()='New']");
397 // fill member source
398 $this->type("member_source", "membership source$firstName");
399 // check to search primary member
400 $this->click("xpath=//div[@id='memberForm']/table/tbody/tr[2]/td[2]/p/input");
401 // add join date range
402 $this->select("member_join_date_relative","value=0");
403 $this->webtestFillDate("member_join_date_low", "-1 day");
404 $this->webtestFillDate("member_join_date_high", "+1 day");
405 // add start date range
406 $this->select("member_start_date_relative","value=0");
407 $this->webtestFillDate("member_start_date_low", "-1 day");
408 $this->webtestFillDate("member_start_date_high", "+1 day");
409 // add end date range
410 $this->select("member_end_date_relative","value=0");
411 $this->webtestFillDate("member_end_date_low", "-1 year");
412 $this->webtestFillDate("member_end_date_high", "+2 year");
413 }
414
415 // function to fill member search details
416 /**
417 * @param $firstName
418 */
419 function addPledgeSearchDetail($firstName) {
420 // fill pledge schedule date range
421 $this->select("pledge_payment_date_relative","value=0");
422 $this->webtestFillDate("pledge_payment_date_low", "-1 day");
423 $this->webtestFillDate("pledge_payment_date_high", "+1 day");
424 // fill Pledge payment status
425 $this->click("xpath=//div[@id='pledgeForm']/table/tbody/tr[3]/td//label[text()='Completed']");
426 $this->click("xpath=//div[@id='pledgeForm']/table/tbody/tr[3]/td//label[text()='Pending']");
427 // fill pledge amount range
428 $this->type("pledge_amount_low", "100");
429 $this->type("pledge_amount_high", "300");
430 // fill plegde status
431 $this->click("xpath=//div[@id='pledgeForm']/table/tbody/tr[4]/td[2]//label[text()='Completed']");
432 $this->click("xpath=//div[@id='pledgeForm']/table/tbody/tr[4]/td[2]//label[text()='Pending']");
433 // fill pledge created date range
434 $this->webtestFillDate("pledge_create_date_low", "-5 day");
435 $this->webtestFillDate("pledge_create_date_high", "+5 day");
436 // fill plegde start date
437 $this->webtestFillDate("pledge_start_date_low", "-2 day");
438 $this->webtestFillDate("pledge_start_date_high", "+2 day");
439 // fill financial type
440 $this->select("pledge_financial_type_id", "Donation");
441 }
442
443 // function to create contact with details (contact details, address, Constituent information ...)
444 /**
445 * @param null $firstName
446 */
447 function createDetailContact($firstName = NULL) {
448 if (!$firstName) {
449 $firstName = substr(sha1(rand()), 0, 7);
450 }
451
452 // create contact type Individual with subtype
453 // with most of values to required to search
454 $Subtype = "Student";
455 $this->openCiviPage('contact/add', 'reset=1&ct=Individual', '_qf_Contact_cancel');
456
457 // --- fill few values in Contact Detail block
458 $this->type("first_name", "$firstName");
459 $this->type("middle_name", "mid$firstName");
460 $this->type("last_name", "adv$firstName");
461 $this->select("contact_sub_type", "label=$Subtype");
462 $this->type("email_1_email", "$firstName@advsearch.co.in");
463 $this->type("phone_1_phone", "123456789");
464 $this->type("external_identifier", "extid$firstName");
465
466 // --- fill few value in Constituent information
467 $this->click("customData1");
468 $this->waitForElementPresent("custom_3_-1");
469
470 $this->click("CIVICRM_QFID_Edu_2");
471 $this->select("custom_2_-1", "label=Single");
472
473 // --- fill few values in address
474
475 $this->click("//form[@id='Contact']/div[2]/div[4]/div[1]");
476 $this->waitForElementPresent("address_1_geo_code_2");
477 $this->type("address_1_street_address", "street 1 $firstName");
478 $this->type("address_1_supplemental_address_1", "street supplement 1 $firstName");
479 $this->type("address_1_supplemental_address_2", "street supplement 2 $firstName");
480 $this->type("address_1_city", "city$firstName");
481 $this->type("address_1_postal_code", "100100");
482 $this->select("address_1_country_id", "United States");
483 $this->select("address_1_state_province_id", "Alaska");
484
485 // --- fill few values in communication preferences
486 $this->click("//form[@id='Contact']/div[2]/div[5]/div[1]");
487 $this->waitForElementPresent("preferred_mail_format");
488 $this->check("privacy[do_not_phone]");
489 $this->check("privacy[do_not_mail]");
490 // phone
491 $this->check("preferred_communication_method[1]");
492 // email
493 $this->check("preferred_communication_method[2]");
494 $this->select("preferred_language", "value=en_US");
495
496 // --- fill few value in notes
497 $this->click("//form[@id='Contact']/div[2]/div[6]/div[1]");
498 $this->waitForElementPresent("note");
499 $this->type("subject", "this is subject by $firstName");
500 $this->type("note", "this is notes by $firstName");
501
502 // --- fill few values in demographics
503 $this->click("//form[@id='Contact']/div[2]/div[7]/div[1]");
504 $this->waitForElementPresent("is_deceased");
505 $this->click("civicrm_gender_Male_2");
506
507 $this->webtestFillDate("birth_date", "-1 year");
508 $this->click("is_deceased");
509 $this->waitForElementPresent("deceased_date");
510 $this->webtestFillDate("deceased_date", "now");
511
512 // save contact
513 $this->clickLink("_qf_Contact_upload_view", 'css=.crm-summary-display_name');
514 $this->assertElementContainsText('css=.crm-summary-display_name', "$firstName adv$firstName");
515 }
516 }
517