From bc2bc079a12ada78b900f4f545bc7894125a854d Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Tue, 1 Apr 2014 19:45:43 +0530 Subject: [PATCH] SyntaxConformanceTest handling Encoding and Decoding --- CRM/Financial/BAO/FinancialAccount.php | 12 +++++++----- CRM/Financial/BAO/FinancialType.php | 10 ++++++---- tests/phpunit/api/v3/SyntaxConformanceTest.php | 14 +++++++------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/CRM/Financial/BAO/FinancialAccount.php b/CRM/Financial/BAO/FinancialAccount.php index dcf52d2c2e..9d98426c40 100644 --- a/CRM/Financial/BAO/FinancialAccount.php +++ b/CRM/Financial/BAO/FinancialAccount.php @@ -96,11 +96,13 @@ class CRM_Financial_BAO_FinancialAccount extends CRM_Financial_DAO_FinancialAcco * @return object */ static function add(&$params, &$ids = array()) { - $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); - $params['is_deductible'] = CRM_Utils_Array::value('is_deductible', $params, FALSE); - $params['is_tax'] = CRM_Utils_Array::value('is_tax', $params, FALSE); - $params['is_header_account'] = CRM_Utils_Array::value('is_header_account', $params, FALSE); - $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE); + if(empty($params['id'])) { + $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); + $params['is_deductible'] = CRM_Utils_Array::value('is_deductible', $params, FALSE); + $params['is_tax'] = CRM_Utils_Array::value('is_tax', $params, FALSE); + $params['is_header_account'] = CRM_Utils_Array::value('is_header_account', $params, FALSE); + $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE); + } if (!empty($params['is_default'])) { $query = 'UPDATE civicrm_financial_account SET is_default = 0 WHERE financial_account_type_id = %1'; $queryParams = array(1 => array($params['financial_account_type_id'], 'Integer')); diff --git a/CRM/Financial/BAO/FinancialType.php b/CRM/Financial/BAO/FinancialType.php index 72c4cf421b..4fc6d1e23a 100644 --- a/CRM/Financial/BAO/FinancialType.php +++ b/CRM/Financial/BAO/FinancialType.php @@ -96,9 +96,11 @@ class CRM_Financial_BAO_FinancialType extends CRM_Financial_DAO_FinancialType { * @return object */ static function add(&$params, &$ids = array()) { - $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false); - $params['is_deductible'] = CRM_Utils_Array::value('is_deductible', $params, false); - $params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, false); + if(empty($params['id'])) { + $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false); + $params['is_deductible'] = CRM_Utils_Array::value('is_deductible', $params, false); + $params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, false); + } // action is taken depending upon the mode $financialType = new CRM_Financial_DAO_FinancialType(); @@ -108,7 +110,7 @@ class CRM_Financial_BAO_FinancialType extends CRM_Financial_DAO_FinancialType { } $financialType->save(); // CRM-12470 - if (empty($ids['financialType'])) { + if (empty($ids['financialType']) && empty($params['id'])) { $titles = CRM_Financial_BAO_FinancialTypeAccount::createDefaultFinancialAccounts($financialType); $financialType->titles = $titles; } diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index cc28bb2d3c..80422b27e0 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -1065,8 +1065,8 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'field' => 'description', 'value' => 'setValueDescription: TheRest <> CiviCRM', )); - $this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue - //$this->assertEquals('setValueDescription: TheRest <> CiviCRM', $setValueDescriptionResult['values']['description']); + //$this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue + $this->assertEquals('setValueDescription: TheRest <> CiviCRM', $setValueDescriptionResult['values']['description']); } /** @@ -1126,11 +1126,11 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'field' => 'description', 'value' => 'setValueDescription: TheRest <> CiviCRM', )); - $this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue - //$this->assertAPISuccess($setValueDescriptionResult); - //$this->assertDBQuery('setValueDescription: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array( - // 1 => array($eventId, 'Integer') - //)); + //$this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue + $this->assertAPISuccess($setValueDescriptionResult); + $this->assertDBQuery('setValueDescription: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array( + 1 => array($eventId, 'Integer') + )); } } -- 2.25.1