From 73dc8be2b15a6ef0a6b7821f88d32a1ebe18cc17 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Tue, 15 Nov 2016 14:45:42 +0530 Subject: [PATCH] CRM-19626 - Event Registration page allows registration even if no number (or the number 0) has been entered in any ticket quantity boxes --- CRM/Event/Form/Registration.php | 9 ++- .../CRM/Event/Form/RegistrationTest.php | 74 +++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/CRM/Event/Form/RegistrationTest.php diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 9d9eddde34..05ef72b26f 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -1322,7 +1322,7 @@ WHERE v.option_group_id = g.id $feeBlock = $priceSetDetails['fields']; } - $optionMaxValues = $fieldSelected = array(); + $optionMaxValues = $fieldSelected = $priceFieldCheck = array(); foreach ($params as $pNum => $values) { if (!is_array($values) || $values == 'skip') { continue; @@ -1345,6 +1345,11 @@ WHERE v.option_group_id = g.id continue; } + // Make an array for selected price fields. + if (!empty($priceFieldId) && !empty($value)) { + $priceFieldCheck[] = $priceFieldId; + } + $fieldSelected[$pNum] = TRUE; if (!$hasOptMaxValue || !is_array($value)) { @@ -1374,7 +1379,7 @@ WHERE v.option_group_id = g.id } //validate for price field selection. - if (empty($fieldSelected[$pNum])) { + if (empty($fieldSelected[$pNum]) || empty($priceFieldCheck)) { $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).'); } } diff --git a/tests/phpunit/CRM/Event/Form/RegistrationTest.php b/tests/phpunit/CRM/Event/Form/RegistrationTest.php new file mode 100644 index 0000000000..74c4393aca --- /dev/null +++ b/tests/phpunit/CRM/Event/Form/RegistrationTest.php @@ -0,0 +1,74 @@ +controller = new CRM_Core_Controller(); + + $feeAmt = 100; + $priceSetId = $this->eventPriceSetCreate($feeAmt); + $priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId)); + $form->_feeBlock = $priceSet['fields']; + $priceField = $this->callAPISuccess('PriceField', 'get', array('price_set_id' => $priceSetId)); + $params = array( + array( + 'priceSetId' => $priceSetId, + ), + ); + // Check empty values for price fields. + foreach (array_keys($priceField['values']) as $fieldId) { + $params[0]['price_' . $fieldId] = NULL; + } + $form->set('priceSetId', $priceSetId); + $form->set('priceSet', $priceSet); + $form->set('name', 'CRM_Event_Form_Registration'); + $errors = CRM_Event_Form_Registration::validatePriceSet($form, $params); + + //Assert the validation Error. + $expectedResult = array( + array( + '_qf_default' => 'Select at least one option from Event Fee(s).', + ), + ); + $this->checkArrayEquals($expectedResult, $errors); + } + +} -- 2.25.1