diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 4b8907852751..cc133d64cbe0 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -1450,11 +1450,9 @@ public static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$ $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::ADD); } - foreach ($fields as $v) { - if (!empty($v['groupTitle'])) { - $groupTitle['groupTitle'] = $v['groupTitle']; - break; - } + if (!empty($fields)) { + $profile = civicrm_api3('UFGroup', 'getsingle', ['id' => $gid, ['return' => ['title', 'frontend_title']]]); + $groupTitle['groupTitle'] = $profile['frontend_title'] ?? $profile['title']; } $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index 4fa5ca7e8f72..782874b2bf0b 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -8,6 +8,8 @@ */ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { + use CRMTraits_Profile_ProfileTrait; + public function setUp() { $this->useTransaction(TRUE); parent::setUp(); @@ -351,4 +353,35 @@ public function testOnlineRegNoPrice() { $this->assertEquals($contribution['count'], '0', "Contribution should not be created for zero fee event registration when no price field selected."); } + /** + * Test form profile assignment. + * + * @throws \CRM_Core_Exception + * @throws \Exception + */ + public function testAssignProfiles() { + $event = $this->eventCreate(); + $this->createJoinedProfile(['entity_table' => 'civicrm_event', 'entity_id' => $event['id']]); + + /* @var \CRM_Event_Form_Registration_Confirm $form */ + $form = $this->getFormObject('CRM_Event_Form_Registration_Confirm'); + $form->set('params', [[]]); + $form->set('id', $event['id']); + $form->set('values', [ + 'event' => $event['values'][$event['id']], + 'location' => [], + 'custom_pre_id' => $this->ids['UFGroup']['our profile'], + ]); + $form->preProcess(); + + CRM_Event_Form_Registration_Confirm::assignProfiles($form); + + $smarty = CRM_Core_Smarty::singleton(); + $tplVar = $smarty->get_template_vars(); + $this->assertEquals([ + 'CustomPre' => ['First Name' => NULL], + 'CustomPreGroupTitle' => 'Public title', + ], $tplVar['primaryParticipantProfile']); + } + } diff --git a/tests/phpunit/CRMTraits/Profile/ProfileTrait.php b/tests/phpunit/CRMTraits/Profile/ProfileTrait.php index 082881b03206..3ac62c852a89 100644 --- a/tests/phpunit/CRMTraits/Profile/ProfileTrait.php +++ b/tests/phpunit/CRMTraits/Profile/ProfileTrait.php @@ -30,35 +30,50 @@ * * Trait for working with Price Sets in tests */ -trait CRMTraits_Financial_PriceSetTrait { +trait CRMTraits_Profile_ProfileTrait { /** - * Create a contribution with 2 line items. + * Add a profile to a contribution page. * - * This also involves creating t - * - * @param $params - * @param array $lineItemFinancialTypes - * Financial Types, if an override is intended. + * @param array $joinParams + * Must contain entity_id at minimum. + * @param array $ufGroupParams */ - protected function createContributionWithTwoLineItemsAgainstPriceSet($params, $lineItemFinancialTypes = []) { - $params = array_merge(['total_amount' => 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', - ]; + protected function createJoinedProfile($joinParams, $ufGroupParams = []) { + $this->createProfile($ufGroupParams); + $joinParams = array_merge([ + 'uf_group_id' => 'our profile', + 'entity_table' => 'civicrm_contribution_page', + 'weight' => 1, + ], $joinParams); + if (empty($joinParams['module'])) { + $joinParams['module'] = $joinParams['entity_table'] === 'civicrm_event' ? 'CiviEvent' : 'CiviContribute'; + } + if ($joinParams['module'] !== 'CiviContribute' && empty ($joinParams['module_data'])) { + $params['module_data'] = [$joinParams['module'] => []]; } - $this->callAPISuccess('order', 'create', $params); + $this->callAPISuccess('UFJoin', 'create', $joinParams); + } + + /** + * Create a profile. + * + * @param $ufGroupParams + */ + protected function createProfile($ufGroupParams) { + $profile = $this->callAPISuccess('UFGroup', 'create', array_merge([ + 'group_type' => 'Contact', + 'title' => 'Back end title', + 'frontend_title' => 'Public title', + 'name' => 'our profile', + + ], $ufGroupParams)); + $this->ids['UFGroup'][$profile['values'][$profile['id']]['name']] = $profile['id']; + + $this->callAPISuccess('UFField', 'create', [ + 'uf_group_id' => $profile['id'], + 'field_name' => 'first_name', + ]); } }