--fixed for CRM-12148 and fixed formatting
authorPradeep Nayak <pradeep@pradeep.(none)>
Mon, 18 Mar 2013 20:43:57 +0000 (02:13 +0530)
committerPradeep Nayak <pradeep@pradeep.(none)>
Mon, 18 Mar 2013 20:43:57 +0000 (02:13 +0530)
CRM/Contact/BAO/Query.php
CRM/Contribute/BAO/Query.php
CRM/Core/BAO/Mapping.php
tests/phpunit/WebTest/Contact/SearchBuilderTest.php

index 304c597e51736a28ceaf6470da879996f930bf86..9007381a388e739045310001b09e885032643b81 100644 (file)
@@ -1365,7 +1365,8 @@ class CRM_Contact_BAO_Query {
       (substr($values[0], 0, 7) == 'member_') ||
       (substr($values[0], 0, 6) == 'grant_') ||
       (substr($values[0], 0, 7) == 'pledge_') ||
-      (substr($values[0], 0, 5) == 'case_')
+      (substr($values[0], 0, 5) == 'case_') ||
+      (substr($values[0], 0, 10) == 'financial_') 
     ) {
       return;
     }
index 73199efda7e88fc82220a805aa4013d3a19d3caa..2bcda8181cac0cf5a3daecf0b38c9c724fbfa6ee 100644 (file)
@@ -76,7 +76,7 @@ class CRM_Contribute_BAO_Query {
     }
 
     // get financial_type
-    if ( CRM_Utils_Array::value( 'financial_type', $query->_returnProperties ) ) {
+    if (CRM_Utils_Array::value('financial_type', $query->_returnProperties)) {
       $query->_select['financial_type']  = "civicrm_financial_type.name as financial_type";
       $query->_element['financial_type'] = 1;
       $query->_tables['civicrm_contribution'] = 1;
@@ -312,11 +312,11 @@ class CRM_Contribute_BAO_Query {
         case 'financial_type_id':
         case 'financial_type':
         $cType = $value;
-            $types = CRM_Contribute_PseudoConstant::financialType( );
-            $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause( "civicrm_contribution.financial_type_id",
+        $types = CRM_Contribute_PseudoConstant::financialType();
+        $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.financial_type_id",
           $op, $value, "Integer"
         );
-            $query->_qill[$grouping ][] = ts( 'Financial Type - %1', array( 1 => $types[$cType] ) );
+        $query->_qill[$grouping ][] = ts('Financial Type - %1', array(1 => $types[$cType]));
         $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
         return;
 
@@ -601,7 +601,7 @@ class CRM_Contribute_BAO_Query {
         break;
 
       case 'civicrm_accounting_code':
-         $from = " $side JOIN civicrm_entity_financial_account ON civicrm_entity_financial_account.entity_id = civicrm_contribution.financial_type_id AND civicrm_entity_financial_account.entity_table = 'civicrm_financial_type' ";
+        $from = " $side JOIN civicrm_entity_financial_account ON civicrm_entity_financial_account.entity_id = civicrm_contribution.financial_type_id AND civicrm_entity_financial_account.entity_table = 'civicrm_financial_type' ";
         $from .= " INNER JOIN civicrm_financial_account ON civicrm_financial_account.id = civicrm_entity_financial_account.financial_account_id ";
         $from .= " INNER JOIN civicrm_option_value cov ON cov.value = civicrm_entity_financial_account.account_relationship AND cov.name = 'Income Account is' ";
         $from .= " INNER JOIN civicrm_option_group cog ON cog.id = cov.option_group_id AND cog.name = 'account_relationship' ";
@@ -774,7 +774,7 @@ class CRM_Contribute_BAO_Query {
       ts('Financial Type'),
       array(
         '' => ts('- any -')) +
-      CRM_Contribute_PseudoConstant::financialType( )
+      CRM_Contribute_PseudoConstant::financialType()
     );
 
     $form->add('select', 'contribution_page_id',
index d931339530cd80f2d5d2c71d79ac12e58ebf3a3d..8f1094059f958886df2c6fd2019ba63fce2e8ff4 100644 (file)
@@ -1024,7 +1024,8 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
             }
           }
 
-          if ($v[0] == 'Contribution' && substr($fldName, 0, 7) != 'custom_') {
+          if ($v[0] == 'Contribution' && substr($fldName, 0, 7) != 'custom_' 
+            && substr($fldName, 0, 10) != 'financial_') {
             if (substr($fldName, 0, 13) != 'contribution_') {
               $fldName = 'contribution_' . $fldName;
             }
index 6c19291dabef2c9d2625d363975ae1a2d0d97fef..23f2302d504d59597a9a4b780cc641fdd301ed1e 100644 (file)
@@ -145,8 +145,7 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
     $this->_searchBuilder('Email',$householdEmail, $householdName,'=','1');
     $this->_advancedSearch($householdEmail, $householdName, 'Household','1','email');
 
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     // searching contacts whose email is not set
     $firstName1 = "00a1".substr(sha1(rand()), 0, 7);
@@ -155,8 +154,7 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
     // save contact
     $this->click("_qf_Contact_upload_view");
     $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     $firstName2 = "00a2".substr(sha1(rand()), 0, 7);
     $this->type("first_name", $firstName2);
@@ -164,8 +162,7 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
     // save contact
     $this->click("_qf_Contact_upload_view");
     $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/add", "reset=1&ct=Individual");
 
     $firstName3 = "00a3".substr(sha1(rand()), 0, 7);
     $this->type("first_name", $firstName3);
@@ -222,8 +219,7 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
 
   function _searchBuilder($field, $fieldValue = NULL, $name = NULL, $op = '=', $count = NULL) {
     // search builder using contacts(not using contactType)
-    $this->open($this->sboxPath . "civicrm/contact/search/builder?reset=1");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/search/builder", "reset=1");
     $this->enterValues(1, 1, 'Contacts', $field, NULL, $op, "$fieldValue");
     $this->click("id=_qf_Builder_refresh");
     $this->waitForPageToLoad($this->getTimeoutMsec());
@@ -261,7 +257,13 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
     if (is_array($value)) {
       $this->waitForElementPresent("css=#crm_search_value_{$set}_{$row} select option + option");
       foreach ($value as $val) {
-        $this->select("css=#crm_search_value_{$set}_{$row} select", "label=$val");
+        if ($op != 'IN') {
+          $select = 'select'; 
+        }
+        else {
+          $select = 'addSelection';           
+        }
+        $this->$select("css=#crm_search_value_{$set}_{$row} select", "label=$val");
       }
     }
     elseif ($value && substr($value, 0, 5) == 'date:') {
@@ -274,8 +276,7 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
 
   function _advancedSearch($fieldValue = NULL, $name = NULL, $contactType = NULL, $count = NULL, $field){
     //advanced search by selecting the contactType
-    $this->open($this->sboxPath . "civicrm/contact/search/advanced?reset=1");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage("contact/search/advanced", "reset=1");
     if (isset($contactType)){
       $this->select("id=crmasmSelect0", "value=$contactType");
     }
@@ -349,4 +350,74 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
     $this->waitForPageToLoad($this->getTimeoutMsec());
     $this->assertTrue($this->isTextPresent("$name has been created."));
   }
+
+  /*
+   * Webtest for CRM-12148
+   *
+   */
+  function testSearchBuilderfinancialType() {
+    // Logging in. Remember to wait for page to load. In most cases,
+    // you can rely on 30000 as the value that allows your test to pass, however,
+    // sometimes your test might fail because of this. In such cases, it's better to pick one element
+    // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
+    // page contents loaded and you can continue your test execution.
+    $this->webtestLogin();
+    
+    // add financial type
+    $financialTypeName1 = 'Financial Type' . substr(sha1(rand()), 0, 5);;
+    $financialTypeName2 = 'Financial Type' . substr(sha1(rand()), 0, 5);;
+    $financialType = array(
+      'name' => $financialTypeName1,
+      'is_reserved' => FALSE,
+      'is_deductible' => FALSE,
+    );
+    $this->addeditFinancialType($financialType);
+    $this->select('account_relationship', 'label=Income Account is');
+    $this->select('financial_account_id', 'label=Discounts');
+    $this->click('_qf_FinancialTypeAccount_next-botttom');
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $financialType['name'] = $financialTypeName2;
+    $this->addeditFinancialType($financialType);
+    $this->select('account_relationship', 'label=Income Account is');
+    $this->select('financial_account_id', 'label=Discounts');
+    $this->click('_qf_FinancialTypeAccount_next-botttom');
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+    //create 6 contribution
+    $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", "_qf_Contribution_upload");
+    for ($i = 1; $i <= 6; $i++) {
+      if ($i % 2 == 0) {
+        $financialType = $financialTypeName1;
+      }
+      else {
+        $financialType = $financialTypeName2;
+      }
+      // create new contact using dialog
+      $firstName = substr(sha1(rand()), 0, 7);
+      $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
+      $this->select('financial_type_id', $financialType);
+      $this->type('total_amount', 100 * $i);
+      $this->click('_qf_Contribution_upload_new');
+      $this->waitForPageToLoad($this->getTimeoutMsec());
+      $this->waitForElementPresent('_qf_Contribution_upload_new');
+    }
+    $this->openCiviPage("contact/search/builder", "reset=1", "_qf_Builder_refresh");
+      
+    $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName1));
+    $this->click('_qf_Builder_refresh');
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+    
+    $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts');
+      
+    $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']");
+    $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName2));
+    $this->click('_qf_Builder_refresh');
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts');
+      
+    $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']");
+    $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, 'IN', array($financialTypeName1, $financialTypeName2));
+    $this->click('_qf_Builder_refresh');
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->assertTrue($this->isTextPresent('6 Contacts'), 'Missing text: ' . '6 Contacts');
+  }
 }