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