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