From 58f5a267b11b532c085b1725f18bc02b602bde04 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 26 Aug 2019 02:26:44 +1200 Subject: [PATCH] Add minimal test for testExportFinancialBatch This adds the minimal test suggested as needed for https://github.com/civicrm/civicrm-core/pull/14621 In the process I needed to add some api defaults --- api/v3/Batch.php | 10 ++++++++-- tests/phpunit/CRM/Batch/BAO/BatchTest.php | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/api/v3/Batch.php b/api/v3/Batch.php index 36b5ee35df53..9e93ad9f4e1f 100644 --- a/api/v3/Batch.php +++ b/api/v3/Batch.php @@ -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'); @@ -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; @@ -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); diff --git a/tests/phpunit/CRM/Batch/BAO/BatchTest.php b/tests/phpunit/CRM/Batch/BAO/BatchTest.php index c6b57a81d6ab..0bda3569ccab 100644 --- a/tests/phpunit/CRM/Batch/BAO/BatchTest.php +++ b/tests/phpunit/CRM/Batch/BAO/BatchTest.php @@ -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. @@ -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() { @@ -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); + } + }