From: Edsel Date: Wed, 8 Feb 2017 14:33:22 +0000 (+0530) Subject: CRM-19964 Added unit test X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c91b1cc3c3e1d80f98e0b6f38d50d3b48938cfa3;p=civicrm-core.git CRM-19964 Added unit test ---------------------------------------- * CRM-19964: Event registration creates contribution without line item https://issues.civicrm.org/jira/browse/CRM-19964 --- diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index 1132dde1f6..c8a2ec31b0 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -164,4 +164,69 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { $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 be created for zero fee event registration."); + } + } diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index c4aba681ee..5e41fc68dc 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3396,7 +3396,7 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) * * @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 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) $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 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) '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);