Skip to content

Commit

Permalink
Start to use function rather than multiple queries for event details,…
Browse files Browse the repository at this point in the history
… add test
  • Loading branch information
eileenmcnaughton committed Jan 18, 2020
1 parent 3ecd083 commit f84f92f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
19 changes: 18 additions & 1 deletion CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1838,15 +1838,17 @@ public static function buildEventFeeForm(&$form) {
* @param $params
*
* @return array
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
protected function preparePaidEventProcessing($params): array {
$participantStatus = CRM_Event_PseudoConstant::participantStatus();
$contributionParams = ['skipCleanMoney' => TRUE];
$lineItem = [];
$additionalParticipantDetails = [];
if (Civi::settings()->get('deferred_revenue_enabled')) {
$eventStartDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eventId, 'start_date');
$eventStartDate = $this->getEventValue('start_date');
if (strtotime($eventStartDate) > strtotime(date('Ymt'))) {
$contributionParams['revenue_recognition_date'] = date('Ymd', strtotime($eventStartDate));
}
Expand Down Expand Up @@ -2000,4 +2002,19 @@ protected function isPaymentOnExistingContribution(): bool {
return ($this->_id && $this->_action & CRM_Core_Action::UPDATE) && $this->_paymentId;
}

/**
* Get the value for a field relating to the event.
*
* @param string $fieldName
*
* @return mixed
* @throws \CiviCRM_API3_Exception
*/
protected function getEventValue(string $fieldName) {
if (!isset($this->_event)) {
$this->_event = civicrm_api3('Event', 'getsingle', ['id' => $this->_eventId]);
}
return $this->_event[$fieldName];
}

}
32 changes: 29 additions & 3 deletions tests/phpunit/CRM/Event/Form/ParticipantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ public function testSubmitWithPayment($thousandSeparator) {
$form = $this->getForm(['is_monetary' => 1, 'financial_type_id' => 1]);
$form->_mode = 'Live';
$form->_quickConfig = TRUE;
$form->_fromEmails = [
'from_email_id' => ['[email protected]' => 1],
];
$paymentProcessorID = $this->processorCreate(['is_test' => 0]);
$form->submit($this->getSubmitParams($form->_eventId, $paymentProcessorID));
$participants = $this->callAPISuccess('Participant', 'get', []);
Expand Down Expand Up @@ -315,6 +312,9 @@ protected function getForm($eventParams = []) {
$form->_single = TRUE;
$form->_contactID = $form->_contactId = $contactID;
$form->setCustomDataTypes();
$form->_fromEmails = [
'from_email_id' => ['[email protected]' => 1],
];
$form->_eventId = $event['id'];
if (!empty($eventParams['is_monetary'])) {
$form->_bltID = 5;
Expand Down Expand Up @@ -466,4 +466,30 @@ private function getSubmitParams(int $eventID, int $paymentProcessorID): array {
return $submitParams;
}

/**
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testSubmitWithDeferredRecognition() {
Civi::settings()->set('deferred_revenue_enabled', TRUE);
$futureDate = date('Y') + 1 . '-09-20';
$form = $this->getForm(['is_monetary' => 1, 'financial_type_id' => 1, 'start_date' => $futureDate]);
$form->_quickConfig = TRUE;

$form->submit([
'register_date' => date('Ymd'),
'status_id' => 1,
'role_id' => 1,
'event_id' => $form->_eventId,
'record_contribution' => TRUE,
'amount' => 100,
'amount_level' => 'blah',
'financial_type_id' => 1,
]);
$contribution = $this->callAPISuccessGetSingle('Contribution', []);
// Api doesn't retrieve it & we don't much want to change that as we want to feature freeze BAO_Query.
$this->assertEquals($futureDate . ' 00:00:00', CRM_Core_DAO::singleValueQuery("SELECT revenue_recognition_date FROM civicrm_contribution WHERE id = {$contribution['id']}"));
}

}

0 comments on commit f84f92f

Please sign in to comment.