From 3c53f77e7eafc590c03f8c464a263e11555b2ce1 Mon Sep 17 00:00:00 2001 From: "Donald A. Lobo" Date: Wed, 29 May 2013 08:23:51 -0700 Subject: [PATCH] CRM-12588 ---------------------------------------- * CRM-12588: Query by Memership Type using Search Builder does not work http://issues.civicrm.org/jira/browse/CRM-12588 --- CRM/Contact/BAO/Query.php | 3 +- CRM/Member/BAO/Query.php | 43 +++++-- .../WebTest/Contact/SearchBuilderTest.php | 110 ++++++++++++++++++ 3 files changed, 145 insertions(+), 11 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index b02f972a88..6e7aeb1fd4 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1368,7 +1368,8 @@ class CRM_Contact_BAO_Query { (substr($values[0], 0, 6) == 'grant_') || (substr($values[0], 0, 7) == 'pledge_') || (substr($values[0], 0, 5) == 'case_') || - (substr($values[0], 0, 10) == 'financial_') + (substr($values[0], 0, 10) == 'financial_') || + (substr($values[0], 0, 11) == 'membership_') ) { return; } diff --git a/CRM/Member/BAO/Query.php b/CRM/Member/BAO/Query.php index 1cf550668b..da2bcb39b2 100644 --- a/CRM/Member/BAO/Query.php +++ b/CRM/Member/BAO/Query.php @@ -132,7 +132,7 @@ class CRM_Member_BAO_Query { if (!CRM_Utils_Array::value(0, $query->_params[$id])) { continue; } - if (substr($query->_params[$id][0], 0, 7) == 'member_') { + if (substr($query->_params[$id][0], 0, 7) == 'member_' || substr($query->_params[$id][0], 0, 11) == 'membership_') { if ($query->_mode == CRM_Contact_BAO_QUERY::MODE_CONTACTS) { $query->_useDistinct = TRUE; } @@ -190,12 +190,23 @@ class CRM_Member_BAO_Query { $query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1; return; + case 'membership_status': case 'member_status_id': - $status = implode(',', array_keys($value)); - - if (count($value) > 1) { - $op = 'IN'; - $status = "({$status})"; + if (!is_array($value)) { + $status = $value; + if (!empty($value)) { + $value = array_flip(explode(",", str_replace(array( '(', ')' ), '', $value))); + } + else { + $value = array(); + } + } + else { + $status = implode(',', array_keys($value)); + if (count($value) > 1) { + $op = 'IN'; + $status = "({$status})"; + } } $names = array(); @@ -261,11 +272,23 @@ class CRM_Member_BAO_Query { $query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1; return; + case 'membership_type': case 'member_membership_type_id': - $mType = implode(',', array_keys($value)); - if (count($value) > 1) { - $op = 'IN'; - $mType = "({$mType})"; + if (!is_array($value)) { + $mType = $value; + if (!empty($value)) { + $value = array_flip(explode(",", str_replace(array( '(', ')' ), '', $value))); + } + else { + $value = array(); + } + } + else { + $mType = implode(',', array_keys($value)); + if (count($value) > 1) { + $op = 'IN'; + $mType = "({$mType})"; + } } $names = array(); diff --git a/tests/phpunit/WebTest/Contact/SearchBuilderTest.php b/tests/phpunit/WebTest/Contact/SearchBuilderTest.php index 1f8bea8a0b..4fc54c29a5 100644 --- a/tests/phpunit/WebTest/Contact/SearchBuilderTest.php +++ b/tests/phpunit/WebTest/Contact/SearchBuilderTest.php @@ -400,4 +400,114 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); $this->assertTrue($this->isTextPresent('6 Contacts'), 'Missing text: ' . '6 Contacts'); } + + /* + * Webtest for CRM-12588 + * + */ + function testSearchBuilderMembershipType() { + $this->webtestLogin(); + + // create first contact + $firstName1 = substr(sha1(rand()), 0, 7); + $this->webtestAddContact($firstName1, "Memberson", "Memberson{$firstName1}@memberson.name"); + $contactName1 = "Memberson, $firstName1"; + + // create Second contact + $firstName2 = substr(sha1(rand()), 0, 7); + $this->webtestAddContact($firstName2, "Memberson", "Memberson{$firstName2}@memberson.name"); + $contactName2 = "Memberson, $firstName2"; + + // add membership type + $membershipTypes = $this->webtestAddMembershipType(); + + // now add membership + $this->openCiviPage("member/add", "reset=1&action=add&context=standalone", "_qf_Membership_upload"); + + // select contact + $this->webtestFillAutocomplete($firstName1); + + // fill in Membership Organization + $this->select("membership_type_id[0]", "label={$membershipTypes['member_of_contact']}"); + + // select membership type + $this->select("membership_type_id[1]", "label={$membershipTypes['membership_type']}"); + + // fill in Source + $this->type("source", "Membership StandaloneAddTest Webtest"); + + // fill in Start Date + $this->webtestFillDate('start_date'); + + // Clicking save. + $this->clickLink("_qf_Membership_upload"); + + // page was loaded + $this->waitForTextPresent("Membership StandaloneAddTest Webtest"); + + // now add membership for second contact + $this->openCiviPage("member/add", "reset=1&action=add&context=standalone", "_qf_Membership_upload"); + $this->webtestFillAutocomplete($firstName2); + $this->select("membership_type_id[0]", "label={$membershipTypes['member_of_contact']}"); + $this->select("membership_type_id[1]", "label={$membershipTypes['membership_type']}"); + $this->type("source", "Membership StandaloneAddTest Webtest"); + $this->webtestFillDate('start_date'); + + // fill in Status Override? + $this->click("is_override"); + $this->waitForElementPresent("status_id"); + $this->select("status_id", "label=Grace"); + + // Clicking save. + $this->clickLink("_qf_Membership_upload"); + $this->waitForTextPresent("Membership StandaloneAddTest Webtest"); + + // Open the search builder + $this->openCiviPage('contact/search/builder', 'reset=1'); + $this->enterValues(1, 1, 'Membership', 'Membership Type', NULL, '=', array($membershipTypes['membership_type'])); + + $this->clickLink('_qf_Builder_refresh'); + $this->waitForText('search-status', "2 Contacts"); + + $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']"); + $this->enterValues(1, 2, 'Membership', 'Membership Status', NULL, '=', array('New')); + $this->clickLink('_qf_Builder_refresh'); + $this->waitForText('search-status', "1 Contact"); + + $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']"); + $this->waitForElementPresent("xpath=//span[@id='crm_search_value_1_1']/select"); + $this->select("xpath=//span[@id='crm_search_value_1_1']/select", "label=Grace"); + $this->clickLink('_qf_Builder_refresh'); + $this->waitForText('search-status', "1 Contact"); + + $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']"); + $this->click("xpath=//div[@id='map-field']/div[1]/table/tbody/tr[2]/td/a"); + $this->enterValues(1, 2, 'Membership', 'Membership Status', NULL, 'IN', array('New','Grace')); + $this->clickLink('_qf_Builder_refresh'); + $this->waitForText('search-status', "2 Contacts"); + + $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']"); + $this->click("xpath=//div[@id='map-field']/div[1]/table/tbody/tr[2]/td/a"); + $this->enterValues(1, 2, 'Membership', 'Membership Status', NULL, 'IN', array('Current','Expired')); + $this->clickLink('_qf_Builder_refresh'); + $this->waitForText("xpath=//form[@id='Builder']/div[3]/div/div", "No matches found for"); + + // Find Membership + $this->openCiviPage("member/search", "reset=1", "_qf_Search_refresh"); + $this->click("xpath=//label[text()='{$membershipTypes['membership_type']}']"); + $this->clickLink('_qf_Search_refresh'); + $this->waitForText('search-status', "2 Results"); + + $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']"); + $this->click("xpath=//label[text()='New']"); + $this->click("xpath=//label[text()='Grace']"); + $this->clickLink('_qf_Search_refresh'); + $this->waitForText('search-status', "2 Results"); + + $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']"); + $this->click("xpath=//label[text()='New']"); + $this->clickLink('_qf_Search_refresh'); + $this->waitForText('search-status', "1 Result"); + } + } -- 2.25.1