Skip to content

Commit

Permalink
Merge pull request #9774 from JMAConsulting/CRM-19964
Browse files Browse the repository at this point in the history
CRM-19964 Event registration creates contribution without line item
  • Loading branch information
eileenmcnaughton authored Feb 14, 2017
2 parents e974e38 + 3747988 commit b5ca366
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 6 deletions.
1 change: 1 addition & 0 deletions CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ public static function formRule($values, $files, $self) {
if (empty($values['payment_instrument_id'])) {
$errorMsg['payment_instrument_id'] = ts('Payment Method is a required field.');
}
CRM_Price_BAO_PriceField::priceSetValidation($values['priceSetId'], $values, $errorMsg);
}

// validate contribution status for 'Failed'.
Expand Down
6 changes: 3 additions & 3 deletions CRM/Event/Form/Registration/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,9 @@ public function postProcess() {
!$this->_allowWaitlist && !$this->_requireApproval
) {
// transactionID & receive date required while building email template
$this->assign('trxn_id', $value['trxn_id']);
$this->assign('receive_date', CRM_Utils_Date::mysqlToIso($value['receive_date']));
$this->set('receiveDate', CRM_Utils_Date::mysqlToIso($value['receive_date']));
$this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $value));
$this->assign('receive_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $value)));
$this->set('receiveDate', CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $value)));
$this->set('trxnId', CRM_Utils_Array::value('trxn_id', $value));
}
}
Expand Down
1 change: 1 addition & 0 deletions CRM/Event/Form/Registration/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ public function postProcess() {
else {
$submittedLineItems = array($lineItem);
}
$submittedLineItems = array_filter($submittedLineItems);
$this->set('lineItem', $submittedLineItems);
$this->set('lineItemParticipantsCount', array($primaryParticipantCount));
}
Expand Down
65 changes: 65 additions & 0 deletions tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,69 @@ public function testTaxMultipleParticipant() {
$this->assertEquals($contribution['total_amount'], 440, 'Invalid Tax amount.');
}

/**
* Test online registration for event with no price options selected as per CRM-19964.
*/
public function testOnlineRegNoPrice() {
$paymentProcessorID = $this->processorCreate(array('is_default' => TRUE, 'user_name' => 'Test', 'is_test' => FALSE));
$paymentProcessorID = $this->processorCreate(array('is_default' => TRUE, 'user_name' => 'Test', 'is_test' => TRUE));
$params = array(
'start_date' => date('YmdHis', strtotime('+ 1 week')),
'end_date' => date('YmdHis', strtotime('+ 1 year')),
'registration_start_date' => date('YmdHis', strtotime('- 1 day')),
'registration_end_date' => date('YmdHis', strtotime('+ 1 year')),
'payment_processor_id' => $paymentProcessorID,
'is_monetary' => TRUE,
'financial_type_id' => 'Event Fee',
);
$event = $this->eventCreate($params);
$priceFieldOptions = array(
'option_label' => 'Price Field',
'option_value' => 100,
'is_required' => FALSE,
'html_type' => 'Text',
);
$this->createPriceSet('event', $event['id'], $priceFieldOptions);

$priceField = $this->callAPISuccess('PriceField', 'get',
array(
'label' => 'Price Field',
)
);
// Create online event registration.
CRM_Event_Form_Registration_Confirm::testSubmit(array(
'id' => $event['id'],
'contributeMode' => 'direct',
'registerByID' => $this->createLoggedInUser(),
'params' => array(
array(
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
'first_name' => 'Bruce',
'last_name' => 'Wayne',
'email-Primary' => 'bruce@gotham.com',
'price_' . $priceField['id'] => '',
'priceSetId' => $priceField['values'][$priceField['id']]['price_set_id'],
'payment_processor_id' => $paymentProcessorID,
'amount' => 0,
'bypass_payment' => '',
'MAX_FILE_SIZE' => '33554432',
'is_primary' => 1,
'is_pay_later' => 0,
'campaign_id' => NULL,
'defaultRole' => 1,
'participant_role_id' => '1',
'tax_amount' => NULL,
'ip_address' => '127.0.0.1',
'invoiceID' => '57adc34957a29171948e8643ce906332',
'button' => '_qf_Register_upload',
'scriptFee' => '',
'scriptArray' => '',
),
),
));
$contribution = $this->callAPISuccess('Contribution', 'get', array('invoice_id' => '57adc34957a29171948e8643ce906332'));
$this->assertEquals($contribution['count'], '0', "Contribution should not be created for zero fee event registration when no price field selected.");
}

}
7 changes: 4 additions & 3 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3396,7 +3396,7 @@ protected function createParticipantWithContribution() {
*
* @return array
*/
protected function createPriceSet($component = 'contribution_page', $componentId = NULL) {
protected function createPriceSet($component = 'contribution_page', $componentId = NULL, $priceFieldOptions = array()) {
$paramsSet['title'] = 'Price Set' . substr(sha1(rand()), 0, 7);
$paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']);
$paramsSet['is_active'] = TRUE;
Expand All @@ -3408,7 +3408,7 @@ protected function createPriceSet($component = 'contribution_page', $componentId
$this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title',
'id', $paramsSet['title'], 'Check DB for created priceset'
);
$paramsField = array(
$paramsField = array_merge(array(
'label' => 'Price Field',
'name' => CRM_Utils_String::titleToVar('Price Field'),
'html_type' => 'CheckBox',
Expand All @@ -3424,7 +3424,8 @@ protected function createPriceSet($component = 'contribution_page', $componentId
'price_set_id' => $priceSet['id'],
'is_enter_qty' => 1,
'financial_type_id' => $this->getFinancialTypeId('Event Fee'),
);
), $priceFieldOptions);

$priceField = CRM_Price_BAO_PriceField::create($paramsField);
if ($componentId) {
CRM_Price_BAO_PriceSet::addTo('civicrm_' . $component, $componentId, $priceSetId);
Expand Down

0 comments on commit b5ca366

Please sign in to comment.