3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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->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"));
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->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"));
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->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]");
235 * Check for CRM-14952
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(
255 $this->clickLink("_qf_Advanced_refresh", "xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[6]");
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);
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__Student");
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->select2("preferred_communication_method", array('Phone', 'Email'), TRUE);
291 * function to fill address search block values in advance search.
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");
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");
305 $this->select("country", "UNITED STATES");
306 // select state-province
307 $this->waitForElementPresent('state_province');
308 $this->select2("state_province", "Alaska", TRUE);
312 * function to fill activity search block in advance search.
315 public function addActivitySearchDetail($firstName) {
316 // select activity types
317 $activityTypes = array("Contribution", "Event Registration", "Membership Signup");
318 $this->multiselect2('activity_type_id', $activityTypes);
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'));
329 * function to fill demographic search details.
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");
346 * function to fill contribution search details.
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");
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");
371 * function to fill participant search details.
373 public function addParticipantSearchDetail() {
375 $this->select2("event_id", "Fall Fundraiser Dinner");
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");
385 $this->type("participant_fee_amount_low", "1");
386 $this->type("participant_fee_amount_high", "150");
390 * function to fill member search details.
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");
417 * function to fill member search details.
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");
442 * function to create contact with details (contact details, address, Constituent information ...)
443 * @param null $firstName
445 public function createDetailContact($firstName = NULL) {
447 $firstName = substr(sha1(rand()), 0, 7);
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');
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");
464 // --- fill few value in Constituent information
465 $this->click("customData");
466 $this->waitForElementPresent("custom_3_-1");
468 $this->click("CIVICRM_QFID_Edu_2");
469 $this->select("custom_2_-1", "label=Single");
471 // --- fill few values in address
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_city", "city$firstName");
479 $this->type("address_1_postal_code", "100100");
480 $this->select("address_1_country_id", "UNITED STATES");
481 $this->select("address_1_state_province_id", "Alaska");
483 // --- fill few values in communication preferences
484 $this->click("//form[@id='Contact']/div[2]/div[5]/div[1]");
485 $this->waitForElementPresent("preferred_mail_format");
486 $this->check("privacy[do_not_phone]");
487 $this->check("privacy[do_not_mail]");
489 $this->check("preferred_communication_method[1]");
491 $this->check("preferred_communication_method[2]");
492 $this->select("preferred_language", "value=en_US");
494 // --- fill few value in notes
495 $this->click("//form[@id='Contact']/div[2]/div[6]/div[1]");
496 $this->waitForElementPresent("note");
497 $this->type("subject", "this is subject by $firstName");
498 $this->type("note", "this is notes by $firstName");
500 // --- fill few values in demographics
501 $this->click("//form[@id='Contact']/div[2]/div[7]/div[1]");
502 $this->waitForElementPresent("is_deceased");
503 $this->click("CIVICRM_QFID_2_gender_id");
505 $this->webtestFillDate("birth_date", "-1 year");
506 $this->click("is_deceased");
507 $this->waitForElementPresent("deceased_date");
508 $this->webtestFillDate("deceased_date", "now");
511 $this->clickLink("_qf_Contact_upload_view", 'css=.crm-summary-display_name');
512 $this->assertElementContainsText('css=.crm-summary-display_name', "$firstName adv$firstName");