From ea888902e2092dd45fac67d195aaca572cd6cf89 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 3 Jun 2014 23:14:40 +1200 Subject: [PATCH] CRM-14778 handle missing name field Conflicts: CRM/Price/BAO/PriceSet.php --- CRM/Price/BAO/PriceField.php | 4 +-- CRM/Price/BAO/PriceSet.php | 39 ++++++++++++++++++--------- tests/phpunit/api/v3/PriceSetTest.php | 15 +++++++++++ 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/CRM/Price/BAO/PriceField.php b/CRM/Price/BAO/PriceField.php index 39ab84d7cb..93d2872b9a 100644 --- a/CRM/Price/BAO/PriceField.php +++ b/CRM/Price/BAO/PriceField.php @@ -55,7 +55,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField { * @access public * @static */ - static function &add(&$params) { + static function add(&$params) { $priceFieldBAO = new CRM_Price_BAO_PriceField(); $priceFieldBAO->copyValues($params); @@ -89,7 +89,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField { return $priceField; } - $options = $optionsIds = array(); + $optionsIds = array(); $maxIndex = CRM_Price_Form_Field::NUM_OPTION; if ($priceField->html_type == 'Text') { diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 621f2aac28..910d07496e 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -56,6 +56,9 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { * @static */ static function create(&$params) { + if(empty($params['id']) && empty($params['name'])) { + $params['name'] = CRM_Utils_String::munge($params['title'], '_', 242); + } $priceSetBAO = new CRM_Price_BAO_PriceSet(); $priceSetBAO->copyValues($params); if (self::eventPriceSetDomainID()) { @@ -102,17 +105,16 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { * * @param string $entity * - * @return id $priceSetID + * @return array $defaultPriceSet default price set * * @access public * @static * */ public static function getDefaultPriceSet($entity = 'contribution') { - if ($entity == 'contribution') { - $entityName = 'default_contribution_amount'; - } - else if ($entity == 'membership') { + + $entityName = 'default_contribution_amount'; + if ($entity == 'membership') { $entityName = 'default_membership_type_amount'; } @@ -155,8 +157,8 @@ WHERE ps.name = '{$entityName}' /** * Return a list of all forms which use this price set. * - * @param int $id id of price set - * @param str $simpleReturn - get raw data. Possible values: 'entity', 'table' + * @param int $id id of price set + * @param bool|string $simpleReturn - get raw data. Possible values: 'entity', 'table' * * @return array */ @@ -377,13 +379,13 @@ WHERE ct.id = cp.financial_type_id AND } /** - * Find a price_set_id associatied with the given option value or field ID + * Find a price_set_id associated with the given option value or field ID * * @param array $params (reference) an assoc array of name/value pairs * array may contain either option id or * price field id * - * @return price set id on success, null otherwise + * @return integer|NULL price set id on success, null otherwise * @static * @access public */ @@ -463,7 +465,6 @@ WHERE ct.id = cp.financial_type_id AND public static function getSetDetail($setID, $required = TRUE, $validOnly = FALSE) { // create a new tree $setTree = array(); - $select = $from = $where = $orderBy = ''; $priceFields = array( 'id', @@ -548,6 +549,16 @@ WHERE id = %1"; return $setTree; } + + /** + * @param CRM_Core_Form $form + * @param $id + * @param string $entityTable + * @param bool $validOnly + * @param null $priceSetId + * + * @return bool|false|int|null + */ static function initSet(&$form, $id, $entityTable = 'civicrm_event', $validOnly = FALSE, $priceSetId = NULL) { if (!$priceSetId) { $priceSetId = self::getFor($entityTable, $id); @@ -784,7 +795,9 @@ WHERE id = %1"; /** * Function to build the price set form. * - * @return None + * @param CRM_Core_Form $form + * + * @return void * @access public */ static function buildPriceSet(&$form) { @@ -917,7 +930,7 @@ WHERE id = %1"; /** * Get field ids of a price set * - * @param int id Price Set id + * @param int $id Price Set id * * @return array of the field ids * @@ -1183,7 +1196,7 @@ WHERE ps.id = %1 return false; } - /* + /** * Copy priceSet when event/contibution page is copied * * @params string $baoName BAO name diff --git a/tests/phpunit/api/v3/PriceSetTest.php b/tests/phpunit/api/v3/PriceSetTest.php index 29bada876c..08d4d29295 100644 --- a/tests/phpunit/api/v3/PriceSetTest.php +++ b/tests/phpunit/api/v3/PriceSetTest.php @@ -54,6 +54,9 @@ class api_v3_PriceSetTest extends CiviUnitTestCase { function tearDown() { } + /** + * + */ public function testCreatePriceSet() { $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); @@ -61,6 +64,18 @@ class api_v3_PriceSetTest extends CiviUnitTestCase { $this->getAndCheck($this->_params, $result['id'], $this->_entity); } + /** + * Check that no name doesn't cause failure + */ + public function testCreatePriceSetNoName() { + $params = $this->_params; + unset($params['name']); + $result = $this->callAPISuccess($this->_entity, 'create', $params); + } + + /** + * + */ public function testGetBasicPriceSet() { $getParams = array( 'name' => 'default_contribution_amount', -- 2.25.1