3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Contact_AdvancedSearchTest
32 class WebTest_Contact_AdvancedSearchTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testAdvanceSearch() {
39 $this->markTestSkipped('Skipping for now as it works fine locally.');
40 $this->webtestLogin();
41 $this->waitForPageToLoad($this->getTimeoutMsec());
43 //------- first create new group and tag -----
45 // take group name and create group
46 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
47 $this->WebtestAddGroup($groupName);
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);
54 //---------- create detailed contact ---------
56 $firstName = substr(sha1(rand()), 0, 7);
57 $this->createDetailContact($firstName);
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'");
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();
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'));
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");
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.");
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");
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.");
117 //-------------- advance search --------------
119 $this->openCiviPage('contact/search/advanced', 'reset=1');
121 //also create a dummy name to test false
122 $dummyName = substr(sha1(rand()), 0, 7);
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_Transgender_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']",
141 foreach ($searchBlockValues as $block => $blockValues) {
144 $this->$blockValues[1]($firstName, $groupName, $tagName);
148 $this->click("$block");
149 $this->waitForElementPresent("$blockValues[0]");
150 $this->type("note", "this is notes by $firstName");
154 $this->click("$block");
155 $this->waitForElementPresent("$blockValues[0]");
156 $this->select("relation_type_id", "Employee of");
157 $this->type("relation_target_name", "Default");
161 $this->click("$block");
162 $this->waitForElementPresent("$blockValues[0]");
163 $this->$blockValues[1]($firstName);
166 $this->submitSearch($firstName);
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");
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")));
186 $this->assertTrue(is_numeric($count), "The total count of search results not found");
188 //pagination calculation
190 if ($count > $perPageRow) {
191 $cal = $count / $perPageRow;
192 $mod = $count %
$perPageRow;
194 for ($i = 1; $i <= $cal; $i++
) {
195 $subTotal = $i * $perPageRow;
196 $lastPageSub = $subTotal +
1;
198 //pagination and row count assertion
199 $pagerCount = "Contact {$j} - {$subTotal} of {$count}";
200 $this->verifyText("xpath=//div[@class='crm-search-results']/div[@class='crm-pager']/span[@class='crm-pager-nav']", preg_quote($pagerCount));
201 $this->assertEquals($perPageRow, $this->getXpathCount("//div[@class='crm-search-results']/table/tbody/tr"));
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']");
209 //pagination and row count assertion for the remaining last page
211 $pagerCount = "Contact {$lastPageSub} - {$count} of {$count}";
212 $this->verifyText("xpath=//div[@class='crm-search-results']/div[@class='crm-pager']/span[@class='crm-pager-nav']", preg_quote($pagerCount));
213 $this->assertEquals($mod, $this->getXpathCount("//div[@class='crm-search-results']/table/tbody/tr"));
219 * function to check match for sumbit Advance Search.
220 * @param string $firstName
222 public function submitSearch($firstName) {
223 $this->clickLink("_qf_Advanced_refresh");
224 // verify unique name
225 $this->waitForAjaxContent();
226 $this->waitForElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr//td/a[text()='adv$firstName, $firstName']");
227 // should give 1 result only as we are searching with unique name
228 $this->waitForText("xpath=//div[@id='search-status']/table/tbody/tr/td", preg_quote("1 Contact"));
229 // click to edit search
230 $this->click("xpath=//form[@id='Advanced']//div[2]/div/div[1]");
234 * Check for CRM-14952
236 public function testStateSorting() {
237 $this->markTestSkipped('Skipping for now as it works fine locally.');
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(
255 $this->clickLink("_qf_Advanced_refresh", "xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[6]");
257 $stateBeforeSort = $this->getText("xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[6]");
258 $this->clickAjaxLink("xpath=//div[@class='crm-search-results']//table/thead/tr//th/a[contains(text(),'State')]");
259 $this->waitForElementPresent("xpath=//div[@class='crm-search-results']//table/thead/tr//th/a[contains(text(),'State')]");
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);
266 * function to fill basic search detail.
267 * @param string $firstName
268 * @param string $groupName
271 public function addBasicSearchDetail($firstName, $groupName, $tagName) {
272 // fill partial sort name
273 $this->type("sort_name", "$firstName");
275 $this->select("contact_type", "value=Individual\ 1Student");
277 $this->select("group", "label=$groupName");
279 $this->select("contact_tags", "label=$tagName");
280 // select preferred language
281 $this->select("preferred_language", "value=en_US");
283 $this->select("privacy_options", "value=do_not_email");
285 // select preferred communication method
287 $this->check("preferred_communication_method[1]");
289 $this->check("preferred_communication_method[2]");
293 * function to fill address search block values in advance search.
296 public function addAddressSearchDetail($firstName) {
297 // select location type (home and main)
298 $this->multiselect2('location_type', array('Home', 'Main'));
299 // fill street address
300 $this->type("street_address", "street 1 $firstName");
302 $this->type("city", "city$firstName");
303 // fill postal code range
304 $this->type("postal_code_low", "100010");
305 $this->type("postal_code_high", "101000");
307 $this->select("country", "UNITED STATES");
308 // select state-province
309 $this->waitForElementPresent('state_province');
310 $this->select2("state_province", "Alaska", TRUE);
314 * function to fill activity search block in advance search.
317 public function addActivitySearchDetail($firstName) {
318 // select activity types
319 $activityTypes = array("Contribution", "Event Registration", "Membership Signup");
320 $this->multiselect2('activity_type_id', $activityTypes);
322 $this->select("activity_date_relative", "value=0");
323 $this->webtestFillDate("activity_date_low", "-1 day");
324 $this->webtestFillDate("activity_date_high", "+1 day");
325 $this->type("activity_subject", "Student - membership source$firstName - Status: New");
326 // fill activity status
327 $this->multiselect2('status_id', array('Scheduled', 'Completed'));
331 * function to fill demographic search details.
333 public function addDemographicSearchDetail() {
334 // fill birth date range
335 $this->select("birth_date_relative", "value=0");
336 $this->webtestFillDate("birth_date_low", "-3 year");
337 $this->webtestFillDate("birth_date_high", "now");
338 // fill deceased date range
339 $this->click("xpath=//div[@id='demographics']/table/tbody//tr/td/label[text()='Deceased']/../label[text()='Yes']");
340 $this->select("deceased_date_relative", "value=0");
341 $this->webtestFillDate("deceased_date_low", "-1 month");
342 $this->webtestFillDate("deceased_date_high", "+1 month");
343 // fill gender (male)
344 $this->check("civicrm_gender_Male_2");
348 * function to fill contribution search details.
351 public function addContributionSearchDetail($firstName) {
352 // fill contribution date range
353 $this->select("contribution_date_relative", "value=0");
354 $this->webtestFillDate("contribution_date_low", "-1 day");
355 $this->webtestFillDate("contribution_date_high", "+1 day");
357 $this->type("contribution_amount_low", "1");
358 $this->type("contribution_amount_high", "200");
359 // check for completed
360 $this->multiselect2("contribution_status_id", array('Completed'));
361 // enter check number
362 $this->select("payment_instrument_id", "Check");
363 $this->type("contribution_check_number", "chqNo$firstName");
364 // fill transaction id
365 $this->type("contribution_trxn_id", "trid$firstName");
366 // fill financial type
367 $this->select("financial_type_id", "Event Fee");
368 // fill currency type
369 $this->select2("contribution_currency_type", "USD");
373 * function to fill participant search details.
375 public function addParticipantSearchDetail() {
377 $this->select2("event_id", "Fall Fundraiser Dinner");
379 $this->select2("event_type_id", "Fundraiser");
380 // select participant status (registered)
381 $this->multiselect2('participant_status_id', array('Registered'));
382 // select participant role (Volunteer)
383 $this->multiselect2('participant_role_id', array('Volunteer'));
384 // fill participant fee level (couple)
385 $this->select2("participant_fee_id", "Couple");
387 $this->type("participant_fee_amount_low", "1");
388 $this->type("participant_fee_amount_high", "150");
392 * function to fill member search details.
395 public function addMemberSearchDetail($firstName) {
396 // check membership type (Student)
397 $this->click("xpath=//div[@id='memberForm']/table/tbody/tr[1]/td[1]/div[1]//div/label[text()='Student']");
398 // check membership status (completed)
399 $this->click("xpath=//div[@id='memberForm']/table/tbody/tr[1]/td[2]/div[1]//div/label[text()='New']");
400 // fill member source
401 $this->type("member_source", "membership source$firstName");
402 // check to search primary member
403 $this->click("xpath=//div[@id='memberForm']/table/tbody/tr[2]/td[2]/p/input");
404 // add join date range
405 $this->select("member_join_date_relative", "value=0");
406 $this->webtestFillDate("member_join_date_low", "-1 day");
407 $this->webtestFillDate("member_join_date_high", "+1 day");
408 // add start date range
409 $this->select("member_start_date_relative", "value=0");
410 $this->webtestFillDate("member_start_date_low", "-1 day");
411 $this->webtestFillDate("member_start_date_high", "+1 day");
412 // add end date range
413 $this->select("member_end_date_relative", "value=0");
414 $this->webtestFillDate("member_end_date_low", "-1 year");
415 $this->webtestFillDate("member_end_date_high", "+2 year");
419 * function to fill member search details.
422 public function addPledgeSearchDetail($firstName) {
423 // fill pledge schedule date range
424 $this->select("pledge_payment_date_relative", "value=0");
425 $this->webtestFillDate("pledge_payment_date_low", "-1 day");
426 $this->webtestFillDate("pledge_payment_date_high", "+1 day");
427 // fill Pledge payment status
428 $this->click("xpath=//div[@id='pledgeForm']/table/tbody/tr[3]/td//label[text()='Completed']");
429 $this->click("xpath=//div[@id='pledgeForm']/table/tbody/tr[3]/td//label[text()='Pending']");
430 // fill pledge amount range
431 $this->type("pledge_amount_low", "100");
432 $this->type("pledge_amount_high", "300");
433 // fill plegde status
434 $this->click("xpath=//div[@id='pledgeForm']/table/tbody/tr[4]/td[2]//label[text()='Completed']");
435 $this->click("xpath=//div[@id='pledgeForm']/table/tbody/tr[4]/td[2]//label[text()='Pending']");
436 // fill pledge created date range
437 $this->webtestFillDate("pledge_create_date_low", "-5 day");
438 $this->webtestFillDate("pledge_create_date_high", "+5 day");
439 // fill plegde start date
440 $this->webtestFillDate("pledge_start_date_low", "-2 day");
441 $this->webtestFillDate("pledge_start_date_high", "+2 day");
442 // fill financial type
443 $this->select("pledge_financial_type_id", "Donation");
447 * function to create contact with details (contact details, address, Constituent information ...)
448 * @param null $firstName
450 public function createDetailContact($firstName = NULL) {
452 $firstName = substr(sha1(rand()), 0, 7);
455 // create contact type Individual with subtype
456 // with most of values to required to search
457 $Subtype = "Student";
458 $this->openCiviPage('contact/add', 'reset=1&ct=Individual', '_qf_Contact_cancel');
460 // --- fill few values in Contact Detail block
461 $this->type("first_name", "$firstName");
462 $this->type("middle_name", "mid$firstName");
463 $this->type("last_name", "adv$firstName");
464 $this->select("contact_sub_type", "label=$Subtype");
465 $this->type("email_1_email", "$firstName@advsearch.co.in");
466 $this->type("phone_1_phone", "123456789");
467 $this->type("external_identifier", "extid$firstName");
469 // --- fill few value in Constituent information
470 $this->click("customData1");
471 $this->waitForElementPresent("custom_3_-1");
473 $this->click("CIVICRM_QFID_Edu_2");
474 $this->select("custom_2_-1", "label=Single");
476 // --- fill few values in address
478 $this->click("//form[@id='Contact']/div[2]/div[4]/div[1]");
479 $this->waitForElementPresent("address_1_geo_code_2");
480 $this->type("address_1_street_address", "street 1 $firstName");
481 $this->type("address_1_supplemental_address_1", "street supplement 1 $firstName");
482 $this->type("address_1_supplemental_address_2", "street supplement 2 $firstName");
483 $this->type("address_1_city", "city$firstName");
484 $this->type("address_1_postal_code", "100100");
485 $this->select("address_1_country_id", "UNITED STATES");
486 $this->select("address_1_state_province_id", "Alaska");
488 // --- fill few values in communication preferences
489 $this->click("//form[@id='Contact']/div[2]/div[5]/div[1]");
490 $this->waitForElementPresent("preferred_mail_format");
491 $this->check("privacy[do_not_phone]");
492 $this->check("privacy[do_not_mail]");
494 $this->check("preferred_communication_method[1]");
496 $this->check("preferred_communication_method[2]");
497 $this->select("preferred_language", "value=en_US");
499 // --- fill few value in notes
500 $this->click("//form[@id='Contact']/div[2]/div[6]/div[1]");
501 $this->waitForElementPresent("note");
502 $this->type("subject", "this is subject by $firstName");
503 $this->type("note", "this is notes by $firstName");
505 // --- fill few values in demographics
506 $this->click("//form[@id='Contact']/div[2]/div[7]/div[1]");
507 $this->waitForElementPresent("is_deceased");
508 $this->click("civicrm_gender_Male_2");
510 $this->webtestFillDate("birth_date", "-1 year");
511 $this->click("is_deceased");
512 $this->waitForElementPresent("deceased_date");
513 $this->webtestFillDate("deceased_date", "now");
516 $this->clickLink("_qf_Contact_upload_view", 'css=.crm-summary-display_name');
517 $this->assertElementContainsText('css=.crm-summary-display_name', "$firstName adv$firstName");