From 289c8051f573034052ad92970a79a7d519018f6a Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Tue, 19 Mar 2013 02:13:57 +0530 Subject: [PATCH] --fixed for CRM-12148 and fixed formatting --- CRM/Contact/BAO/Query.php | 3 +- CRM/Contribute/BAO/Query.php | 12 +-- CRM/Core/BAO/Mapping.php | 3 +- .../WebTest/Contact/SearchBuilderTest.php | 93 ++++++++++++++++--- 4 files changed, 92 insertions(+), 19 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 304c597e51..9007381a38 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -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; } diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 73199efda7..2bcda8181c 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -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', diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index d931339530..8f1094059f 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -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; } diff --git a/tests/phpunit/WebTest/Contact/SearchBuilderTest.php b/tests/phpunit/WebTest/Contact/SearchBuilderTest.php index 6c19291dab..23f2302d50 100644 --- a/tests/phpunit/WebTest/Contact/SearchBuilderTest.php +++ b/tests/phpunit/WebTest/Contact/SearchBuilderTest.php @@ -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'); + } } -- 2.25.1