CRM-12588
authorDonald A. Lobo <lobo@civicrm.org>
Wed, 29 May 2013 15:23:51 +0000 (08:23 -0700)
committerDonald A. Lobo <lobo@civicrm.org>
Wed, 29 May 2013 15:23:51 +0000 (08:23 -0700)
----------------------------------------
* 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
CRM/Member/BAO/Query.php
tests/phpunit/WebTest/Contact/SearchBuilderTest.php

index b02f972a88f7d759891e79f0a2f889aa42e8fda0..6e7aeb1fd4552ec6f0b5216f1c05502a9cfae43e 100644 (file)
@@ -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;
     }
index 1cf550668b3ec785db65f61ec8e4532e8fbd0310..da2bcb39b2f18fdd0925f99c30d994c850273d82 100644 (file)
@@ -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();
index 1f8bea8a0bd2220286143afbac4b04291cfd77f9..4fc54c29a5fe6693cc75a76e9f9c1fd7021ecebb 100644 (file)
@@ -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");
+  }
+
 }