From f70a6752553b01ea9b1fe34e0ec31467b0f1abbf Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 30 Jun 2013 15:08:01 +1200 Subject: [PATCH] remove obsolete code from api - add test to check no regression --- api/v3/Contribution.php | 27 ----------------------- tests/phpunit/api/v3/ContributionTest.php | 18 +++++++++++---- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index 057edc8fb2..3c8622c54b 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -261,34 +261,7 @@ function _civicrm_api3_contribution_get_spec(&$params) { */ function _civicrm_api3_contribute_format_params($params, &$values, $create = FALSE) { //legacy way of formatting from v2 api - v3 way is to define metadata & do it in the api layer - require_once 'api/v3/utils.php'; _civicrm_api3_filter_fields_for_bao('Contribution', $params, $values); - - foreach ($params as $key => $value) { - // ignore empty values or empty arrays etc - if (CRM_Utils_System::isNull($value)) { - continue; - } - // note that this is legacy handling - these should be handled at the api layer - switch ($key) { - case 'financial_type' :// should be dealt with either api pseudoconstant in validate_integer fn - $contributionTypeId = CRM_Utils_Array::key ( ucfirst ( $value ), CRM_Contribute_PseudoConstant::financialType() ); - if ($contributionTypeId) { - if (CRM_Utils_Array::value('financial_type_id', $values) && $contributionTypeId != $values['financial_type_id']) { - throw new Exception("Mismatched Financial Type and Financial Type Id"); - } - $values ['financial_type_id'] = $contributionTypeId; - } - else { - throw new Exception("Invalid Financial Type"); - } - break; - - default: - break; - } - } - return array(); } diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index d61611a1bc..1f7eeb98b6 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -506,8 +506,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->_checkFinancialRecords($contribution, 'offline'); $this->contributionGetnCheck($params, $contribution['id']); } - /* - * + /** + * test create with valid payment instument */ function testCreateContributionWithPaymentInstrument() { $params = $this->_params + array('payment_instrument' => 'EFT'); @@ -776,7 +776,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { } - /* + /** * Function tests that additional financial records are created when online contribution is created */ function testCreateContributionOnline() { @@ -809,7 +809,17 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->_checkFinancialRecords($contribution, 'online'); } - /* + /** + * in the interests of removing financial type / contribution type checks from + * legacy format function lets test that the api is doing this for us + */ + function testCreateInvalidFinancialType() { + $params = $this->_params; + $params['financial_type_id'] = 99999; + $result = $this->callAPIFailure($this->_entity, 'create', $params, "'99999' is not a valid option for field financial_type_id"); + } + + /** * Function tests that additional financial records are created when online contribution with pay later option * is created */ -- 2.25.1