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