diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 876e00809680..06216727c8fb 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -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'. diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index f0f653cced72..155f8e6c1369 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -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)); } } diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 50999a089b56..6bc629a735ca 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -1015,6 +1015,7 @@ public function postProcess() { else { $submittedLineItems = array($lineItem); } + $submittedLineItems = array_filter($submittedLineItems); $this->set('lineItem', $submittedLineItems); $this->set('lineItemParticipantsCount', array($primaryParticipantCount)); } diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index 1132dde1f6dc..d57e1eb6bd3c 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -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."); + } + } diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index c4aba681eea5..5e41fc68dca8 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -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; @@ -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', @@ -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);