Skip to content

Commit

Permalink
Merge pull request #15136 from eileenmcnaughton/batch_test
Browse files Browse the repository at this point in the history
Add minimal test for testExportFinancialBatch
  • Loading branch information
seamuslee001 authored Aug 26, 2019
2 parents b1d4dff + 58f5a26 commit 31ca831
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
10 changes: 8 additions & 2 deletions api/v3/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
* @param array $params
*
* @return array
* @throws \API_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
function civicrm_api3_batch_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Batch');
Expand All @@ -56,8 +58,10 @@ function _civicrm_api3_batch_create_spec(&$params) {
$params['entity_table']['api.default'] = "civicrm_batch";
$params['entity_table']['type'] = CRM_Utils_Type::T_STRING;
$params['entity_table']['title'] = 'Batch Entity Table - remove?';

$params['modified_date']['api.default'] = "now";
$params['created_id']['api.default'] = 'user_contact_id';
$params['created_date']['api.default'] = 'now';
$params['modified_id']['api.default'] = 'user_contact_id';
$params['modified_date']['api.default'] = 'now';
$params['status_id']['api.required'] = 1;
$params['title']['api.required'] = 1;
$params['status_id']['api.required'] = 1;
Expand All @@ -82,6 +86,8 @@ function civicrm_api3_batch_get($params) {
*
* @return array
* Array of deleted values.
* @throws \API_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
function civicrm_api3_batch_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
Expand Down
23 changes: 23 additions & 0 deletions tests/phpunit/CRM/Batch/BAO/BatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
*/
class CRM_Batch_BAO_BatchTest extends CiviUnitTestCase {

/**
* Cleanup after test.
*
* @throws \CRM_Core_Exception
*/
public function tearDown() {
parent::tearDown();
$this->quickCleanup(['civicrm_batch']);
}

/**
* This test checks that a batch search
* by payment method works.
Expand All @@ -42,6 +52,8 @@ class CRM_Batch_BAO_BatchTest extends CiviUnitTestCase {
* 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.
*
* @throws \CRM_Core_Exception
*/
public function testGetBatchFinancialItems() {

Expand Down Expand Up @@ -104,4 +116,15 @@ public function testGetBatchFinancialItems() {
$this->assertEquals(count($result), 1, 'In line' . __LINE__);
}

/**
* Test testExportFinancialBatch.
*/
public function testExportFinancialBatch() {
$this->createLoggedInUser();
$batchParams = ['title' => 'Test Batch'];
$batchParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Exported');
$batch = $this->callAPISuccess('Batch', 'create', $batchParams);
CRM_Batch_BAO_Batch::exportFinancialBatch([$batch['id']], 'CSV', NULL);
}

}

0 comments on commit 31ca831

Please sign in to comment.