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