-
-
Notifications
You must be signed in to change notification settings - Fork 818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixing batch search by payment method #12707
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5712c3b
fixing batch search by payment method
tanyabouman b746e1b
added unit test of payment method search in getBatchFinancialItems
tanyabouman 65bd91f
fixed formatting errors in unit test
tanyabouman 9ff4158
optimised with suggested changes
tanyabouman 6a325bd
fixed formatting errors
tanyabouman 4804d6e
fixed the rest of the bug
tanyabouman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
/** | ||
* File for the BatchTest class | ||
* | ||
* (PHP 5) | ||
* | ||
* @package CiviCRM | ||
* | ||
* This file is part of CiviCRM | ||
* | ||
* CiviCRM is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License | ||
* as published by the Free Software Foundation; either version 3 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* CiviCRM is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* Test CRM/Batch/BAO/Batch.php getBatchFinancialItems | ||
* | ||
* @package CiviCRM | ||
* @group headless | ||
*/ | ||
class CRM_Batch_BAO_BatchTest extends CiviUnitTestCase { | ||
|
||
/** | ||
* This test checks that a batch search | ||
* by payment method works. | ||
* This function could later be expanded to include | ||
* checks that other types of searches are also | ||
* working. | ||
* | ||
* It creates two contributions, one with payment method credit | ||
* card and one with payment method check. After performing a | ||
* search by payment method for checks, it makes sure that the | ||
* results are only contributions made by check. | ||
*/ | ||
public function testGetBatchFinancialItems() { | ||
|
||
// create two contributions: one check and one credit card | ||
|
||
$contactId = $this->individualCreate(array('first_name' => 'John', 'last_name' => 'Doe')); | ||
$contribParams = array( | ||
'contact_id' => $contactId, | ||
'total_amount' => 1, | ||
'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'), | ||
'financial_type_id' => 1, | ||
'contribution_status_id' => 1, | ||
'receive_date' => '20080522000000', | ||
'receipt_date' => '20080522000000', | ||
'trxn_id' => '22ereerwww322323', | ||
'id' => NULL, | ||
'fee_amount' => 0, | ||
'net_amount' => 1, | ||
'currency' => 'USD', | ||
'skipCleanMoney' => TRUE, | ||
); | ||
$contribCheck = CRM_Contribute_BAO_Contribution::create($contribParams); | ||
$contribParams = array( | ||
'contact_id' => $contactId, | ||
'total_amount' => 1, | ||
'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Credit Card'), | ||
'financial_type_id' => 1, | ||
'contribution_status_id' => 1, | ||
'receive_date' => '20080523000000', | ||
'receipt_date' => '20080523000000', | ||
'trxn_id' => '22ereerwww323323', | ||
'id' => NULL, | ||
'fee_amount' => 0, | ||
'net_amount' => 1, | ||
'currency' => 'USD', | ||
'skipCleanMoney' => TRUE, | ||
); | ||
$contribCC = CRM_Contribute_BAO_Contribution::create($contribParams); | ||
|
||
//create an empty batch to use for the search, and run the search | ||
|
||
$batchParams = array('title' => 'Test Batch'); | ||
$batchParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Open'); | ||
$batch = CRM_Batch_BAO_Batch::create($batchParams); | ||
$entityId = $batch->id; | ||
$returnvalues = array( | ||
'civicrm_financial_trxn.payment_instrument_id as payment_method', | ||
); | ||
$notPresent = TRUE; | ||
$params['contribution_payment_instrument_id'] | ||
= CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'); | ||
$resultChecksOnly = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityId, $returnvalues, $notPresent, $params, TRUE); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimise it further: $result = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityId, $returnvalues, $notPresent, $params, TRUE)->fetchAll();
$this->assertEquals(count($result), 1, 'In line' . __LINE__);
$this->assertEquals($result[0]['payment_method'], CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'), 'In line' . __LINE__); And you will no longer need L100-113 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
//test that the search results make sense | ||
|
||
while ($resultChecksOnly->fetch()) { | ||
error_log("fetching"); | ||
$resultChecksOnlyCount[] = $resultChecksOnly->id; | ||
$key = 'payment_method'; | ||
$paymentMethod = CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $resultChecksOnly->$key); | ||
$this->assertEquals($paymentMethod, 'Check'); | ||
} | ||
if (isset($resultChecksOnlyCount)) { | ||
$totalChecksOnly = count($resultChecksOnlyCount); | ||
$this->assertEquals($totalChecksOnly, 1); | ||
} | ||
else { | ||
$this->fail("Search results expected."); | ||
} | ||
|
||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, except it gave me an error.
Failure in api call for contribution create: Duplicate error - existing contribution record(s) have a matching Transaction ID or Invoice ID. Contribution record ID(s) are: 1
So I added unique invoice ids as well.