From 301906abaafd7a39587336a18c3ccf9d70ebde5d Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 5 Aug 2019 08:02:21 +1200 Subject: [PATCH] Preliminary cleanup - use CRM_Core_Exception, fix comments --- CRM/Core/BAO/UFGroup.php | 5 +- CRM/Event/BAO/Event.php | 4 ++ CRM/Event/Form/Registration/Confirm.php | 10 +-- api/api.php | 1 + .../CRMTraits/Profile/ProfileTrait.php | 64 +++++++++++++++++++ 5 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 tests/phpunit/CRMTraits/Profile/ProfileTrait.php diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 2aabfc253b..c7d985b299 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -283,7 +283,8 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup { * * @return array * The fields that belong to this ufgroup(s) - * @throws \Exception + * + * @throws \CRM_Core_Exception */ public static function getFields( $id, @@ -366,7 +367,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup { } if (empty($fields) && !$validGroup) { - CRM_Core_Error::fatal(ts('The requested Profile (gid=%1) is disabled OR it is not configured to be used for \'Profile\' listings in its Settings OR there is no Profile with that ID OR you do not have permission to access this profile. Please contact the site administrator if you need assistance.', + throw new CRM_Core_Exception(ts('The requested Profile (gid=%1) is disabled OR it is not configured to be used for \'Profile\' listings in its Settings OR there is no Profile with that ID OR you do not have permission to access this profile. Please contact the site administrator if you need assistance.', [1 => implode(',', $profileIds)] )); } diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index cf52a5f32c..4b89078527 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -1431,6 +1431,10 @@ WHERE civicrm_event.is_active = 1 * Formatted array of key value. * * @param array $profileFields + * + * @throws \CRM_Core_Exception + * @throws \API_Exception + * @throws \CiviCRM_API3_Exception */ public static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$profileFields = []) { if ($gid) { diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index e3f603bdd2..db2829ef08 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -1210,11 +1210,13 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { } /** - * Assign Profiles. + * Assign Profiles to the template. * - * @param CRM_Core_Form $form + * @param CRM_Event_Form_Registration_Confirm $form + * + * @throws \Exception */ - public static function assignProfiles(&$form) { + public static function assignProfiles($form) { $participantParams = $form->_params; $formattedValues = $profileFields = []; $count = 1; @@ -1227,7 +1229,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { $prefix1 = ''; $prefix2 = ''; } - if ($participantValue != 'skip') { + if ($participantValue !== 'skip') { //get the customPre profile info if (!empty($form->_values[$prefix2 . 'custom_pre_id'])) { $values = $groupName = []; diff --git a/api/api.php b/api/api.php index 9b1a00941d..5d67281e45 100644 --- a/api/api.php +++ b/api/api.php @@ -36,6 +36,7 @@ function civicrm_api($entity, $action, $params, $extra = NULL) { * Array to be passed to function. * * @throws CiviCRM_API3_Exception + * * @return array */ function civicrm_api3($entity, $action, $params = []) { diff --git a/tests/phpunit/CRMTraits/Profile/ProfileTrait.php b/tests/phpunit/CRMTraits/Profile/ProfileTrait.php new file mode 100644 index 0000000000..082881b032 --- /dev/null +++ b/tests/phpunit/CRMTraits/Profile/ProfileTrait.php @@ -0,0 +1,64 @@ + 300, 'financial_type_id' => 'Donation'], $params); + $priceFields = $this->createPriceSet('contribution'); + foreach ($priceFields['values'] as $key => $priceField) { + $financialTypeID = (!empty($lineItemFinancialTypes) ? array_shift($lineItemFinancialTypes) : $priceField['financial_type_id']); + $params['line_items'][]['line_item'][$key] = [ + 'price_field_id' => $priceField['price_field_id'], + 'price_field_value_id' => $priceField['id'], + 'label' => $priceField['label'], + 'field_title' => $priceField['label'], + 'qty' => 1, + 'unit_price' => $priceField['amount'], + 'line_total' => $priceField['amount'], + 'financial_type_id' => $financialTypeID, + 'entity_table' => 'civicrm_contribution', + ]; + } + $this->callAPISuccess('order', 'create', $params); + } + +} -- 2.25.1