From db23237852ce460cbbdeda509607e2ffc92485d8 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 19 Oct 2014 23:50:01 +1300 Subject: [PATCH] SyntaxConformanceTest fix pricefieldvalue to pass singlevaluealter --- CRM/Price/BAO/PriceFieldValue.php | 42 ++++++++++++++----- .../phpunit/api/v3/SyntaxConformanceTest.php | 6 ++- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/CRM/Price/BAO/PriceFieldValue.php b/CRM/Price/BAO/PriceFieldValue.php index c3e0a7d7ea..57a9d91cb9 100644 --- a/CRM/Price/BAO/PriceFieldValue.php +++ b/CRM/Price/BAO/PriceFieldValue.php @@ -80,15 +80,15 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue { * @static */ static function create(&$params, $ids = array()) { - + $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids)); if (!is_array($params) || empty($params)) { return; } - if(empty($params['id']) && empty($params['name'])) { + if(!$id && empty($params['name'])) { $params['name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 242)); } - if ($id = CRM_Utils_Array::value('id', $ids) && !empty($params['weight'])) { + if ($id && !empty($params['weight'])) { if (isset($params['name']))unset($params['name']); $oldWeight = NULL; @@ -100,18 +100,40 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue { $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceFieldValue', $oldWeight, $params['weight'], $fieldValues); } else { - if (!$id && empty($params['name'])) { - $params['name'] = CRM_Utils_String::munge(CRM_Utils_Array::value('label', $params), '_', 64); - } - if (empty($params['weight'])) { - $params['weight'] = 1; + if (!$id) { + self::setDefaults($params); + if (empty($params['name'])) { + $params['name'] = CRM_Utils_String::munge(CRM_Utils_Array::value('label', $params), '_', 64); + } } } - $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0); - return self::add($params, $ids); } + /** + * Get defaults for new entity + * @return array + */ + static function getDefaults() { + return array( + 'is_active' => 1, + 'weight' => 1, + ); + + } + + /** + * Set defaults when creating new entity + * @param $params + */ + static function setDefaults(&$params) { + foreach (self::getDefaults() as $key => $value) { + if (empty($params[$key])) { + $params[$key] = $value; + } + } + } + /** * Takes a bunch of params that are needed to match certain criteria and * retrieves the relevant objects. diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index 70237b9c57..0c13c37cfe 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -350,7 +350,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'ParticipantPayment', 'LineItem', 'PriceField', - 'PriceFieldValue', 'PledgePayment', 'ContributionPage', 'Phone', @@ -499,6 +498,11 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'cant_return' => array( ), ), + 'PriceFieldValue' => array( + 'cant_update' => array( + 'weight', //won't update as there is no 1 in the same price set + ), + ), ); if(empty($knownFailures[$entity]) || empty($knownFailures[$entity][$key])){ return array(); -- 2.25.1