From 1f0d8c9224bd2291a066b7cb5b9e8ff4bd3ab850 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Sun, 5 Jan 2014 20:02:08 +0530 Subject: [PATCH] --CRM-13848, used UX pattern for financial type to allow multiple account type selections. Also added webtest to check the improvement. --- CRM/Contact/Form/Search/Advanced.php | 11 ++- CRM/Contribute/BAO/Query.php | 10 +- CRM/Contribute/Form/Search.php | 13 ++- .../CRM/Contribute/Form/Search/Common.tpl | 12 +++ .../WebTest/Contribute/StandaloneAddTest.php | 96 +++++++++++++++++++ 5 files changed, 134 insertions(+), 8 deletions(-) diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index 0b6cc47d61..a852131f44 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -354,7 +354,16 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search { $this->_formValues['contact_tags'][$value] = 1; } } - + + // CRM-13848 + $financialType = CRM_Utils_Array::value('financial_type_id', $this->_formValues); + if ($financialType && is_array($financialType)) { + unset($this->_formValues['financial_type_id']); + foreach($financialType as $notImportant => $typeID) { + $this->_formValues['financial_type_id'][$typeID] = 1; + } + } + $taglist = CRM_Utils_Array::value('contact_taglist', $this->_formValues); if ($taglist && is_array($taglist)) { diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 082c134546..7d9255329f 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -314,7 +314,7 @@ class CRM_Contribute_BAO_Query { $val[] = $k; } } - if (count($val) > 1) { + if (count($val) > 0) { // Overwrite $value so it works with an IN where statement. $op = 'IN'; $value = '(' . implode(',', $val) . ')'; @@ -331,7 +331,7 @@ class CRM_Contribute_BAO_Query { $names = array(); if (isset($val) && is_array($val)) { foreach($val as $id) { - $names[] = $types[$id]; + $names[] = CRM_Utils_Array::value($id, $types); } } else { @@ -821,11 +821,11 @@ class CRM_Contribute_BAO_Query { CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array('labelColumn' => 'name')) ); + // CRM-13848 $form->add('select', 'financial_type_id', ts('Financial Type'), - array( - '' => ts('- any -')) + - CRM_Contribute_PseudoConstant::financialType() + CRM_Contribute_PseudoConstant::financialType(), FALSE, + array('id' => 'financial_type_id', 'multiple' => 'multiple', 'title' => ts('- select -')) ); $form->add('select', 'contribution_page_id', diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index 2af83257fe..40e9c60e33 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -371,6 +371,15 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form { } $config = CRM_Core_Config::singleton(); + // CRM-13848 + $financialType = CRM_Utils_Array::value('financial_type_id', $this->_formValues); + if ($financialType && is_array($financialType)) { + unset($this->_formValues['financial_type_id']); + foreach($financialType as $notImportant => $typeID) { + $this->_formValues['financial_type_id'][$typeID] = 1; + } + } + $tags = CRM_Utils_Array::value('contact_tags', $this->_formValues); if ($tags && !is_array($tags)) { unset($this->_formValues['contact_tags']); @@ -380,7 +389,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form { if ($tags && is_array($tags)) { unset($this->_formValues['contact_tags']); foreach($tags as $notImportant => $tagID) { - $this->_formValues['contact_tags'][$tagID] = 1; + $this->_formValues['contact_tags'][$tagID] = 1; } } @@ -395,7 +404,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form { if ($group && is_array($group)) { unset($this->_formValues['group']); foreach($group as $notImportant => $groupID) { - $this->_formValues['group'][$groupID] = 1; + $this->_formValues['group'][$groupID] = 1; } } diff --git a/templates/CRM/Contribute/Form/Search/Common.tpl b/templates/CRM/Contribute/Form/Search/Common.tpl index 1a0167249f..140b5209c1 100644 --- a/templates/CRM/Contribute/Form/Search/Common.tpl +++ b/templates/CRM/Contribute/Form/Search/Common.tpl @@ -119,6 +119,18 @@
{$form.financial_type_id.html|crmAddClass:twenty} + {* CRM-13848 *} + {literal} + + {/literal}
diff --git a/tests/phpunit/WebTest/Contribute/StandaloneAddTest.php b/tests/phpunit/WebTest/Contribute/StandaloneAddTest.php index 0b6f343b81..d8c43b85f2 100644 --- a/tests/phpunit/WebTest/Contribute/StandaloneAddTest.php +++ b/tests/phpunit/WebTest/Contribute/StandaloneAddTest.php @@ -183,6 +183,102 @@ class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase { } } + function testfinancialTypeSearch() { + $this->webtestLogin(); + + $financialType = array( + 'name' => 'Financial type' . substr(sha1(rand()), 0, 7), + 'is_reserved' => FALSE, + 'is_deductible' => FALSE, + ); + + $this->addeditFinancialType($financialType); + $this->addStandaloneContribution($financialType); + $this->addStandaloneContribution($financialType); + + $this->openCiviPage("contribute/search", "reset=1", "_qf_Search_refresh"); + // select group + $this->select("crmasmSelect2", "label={$financialType['name']}"); + $this->clickLink("_qf_Search_refresh"); + $this->assertElementContainsText("xpath=//div[@id='search-status']/table/tbody/tr[1]/td[1]", "2 Result"); + $this->assertElementContainsText("xpath=//div[@id='search-status']/table/tbody/tr[1]/td[2]", "Financial Type IN {$financialType['name']}"); + + $this->openCiviPage("contact/search/advanced", "reset=1", "_qf_Advanced_refresh-top"); + $this->click('CiviContribute'); + $this->waitForElementPresent("crmasmSelect5"); + + // select group + $this->select("crmasmSelect5", "label={$financialType['name']}"); + $this->clickLink("_qf_Advanced_refresh-top"); + $this->assertElementContainsText("xpath=//div[@id='search-status']//table/tbody/tr[1]/td[1]", "2 Contacts"); + $this->assertElementContainsText("xpath=//div[@id='search-status']//table/tbody/tr[1]/td[2]", "Financial Type IN {$financialType['name']}"); + } + + function addStandaloneContribution($financialType) { + + $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload"); + + // create new contact using dialog + $firstName = substr(sha1(rand()), 0, 7); + $this->webtestNewDialogContact($firstName, "Contributor", $firstName . "@example.com"); + + // select financial type + $this->select("financial_type_id", "label={$financialType['name']}"); + + // fill in Received Date + $this->webtestFillDate('receive_date'); + + // source + $this->type("source", "Mailer 1"); + + // total amount + $this->type("total_amount", "100"); + + // select payment instrument type = Check and enter chk number + $this->select("payment_instrument_id", "value=4"); + $this->waitForElementPresent("check_number"); + $this->type("check_number", "check #1041"); + + $this->type("trxn_id", "P20901X1" . rand(100, 10000)); + + //Additional Detail section + $this->click("AdditionalDetail"); + $this->waitForElementPresent("thankyou_date"); + + $this->type("note", "This is a test note."); + $this->type("non_deductible_amount", "10"); + $this->type("fee_amount", "0"); + $this->type("net_amount", "0"); + $this->type("invoice_id", time()); + $this->webtestFillDate('thankyou_date'); + + // Clicking save. + $this->click("_qf_Contribution_upload"); + $this->waitForPageToLoad($this->getTimeoutMsec()); + + // Is status message correct? + $this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!"); + + // verify if Membership is created + $this->waitForElementPresent("xpath=//div[@id='Contributions']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); + + //click through to the Membership view screen + $this->click("xpath=//div[@id='Contributions']//table/tbody/tr[1]/td[8]/span/a[text()='View']"); + $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); + + $expected = array( + 'Financial Type' => $financialType['name'], + 'Total Amount' => '$ 100.00', + 'Contribution Status' => 'Completed', + 'Paid By' => 'Check', + 'Check Number' => 'check #1041', + ); + + foreach ($expected as $label => $value) { + $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody//tr/td[1][text()='$label']/../td[2]", preg_quote($value)); + } + } + function testAjaxCustomGroupLoad() { $this->webtestLogin(); $triggerElement = array('name' => 'financial_type_id', 'type' => 'select'); -- 2.25.1