Skip to content

Commit

Permalink
dev/drupal#72 fix display of profiles on events to use front end titles
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Aug 4, 2019
1 parent 0f47621 commit b3a1e0e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 29 deletions.
8 changes: 3 additions & 5 deletions CRM/Event/BAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
33 changes: 33 additions & 0 deletions tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {

use CRMTraits_Profile_ProfileTrait;

public function setUp() {
$this->useTransaction(TRUE);
parent::setUp();
Expand Down Expand Up @@ -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']);
}

}
63 changes: 39 additions & 24 deletions tests/phpunit/CRMTraits/Profile/ProfileTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
}

}

0 comments on commit b3a1e0e

Please sign in to comment.