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