From 2d6f64f44a23639d4f48d6f35bf9788d3146b3fd Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 21 Jan 2020 10:15:49 +1300 Subject: [PATCH] Fix unit test so price set params are valid --- .../CRM/Event/Form/ParticipantTest.php | 16 ++++++--------- tests/phpunit/CiviTest/CiviUnitTestCase.php | 20 +++++++++++++------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/tests/phpunit/CRM/Event/Form/ParticipantTest.php b/tests/phpunit/CRM/Event/Form/ParticipantTest.php index 69c720d52b0c..a4d906228241 100644 --- a/tests/phpunit/CRM/Event/Form/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/Form/ParticipantTest.php @@ -70,9 +70,7 @@ public function testSubmitUnpaidPriceChangeWhileStillPending() { 'role_id' => 1, 'event_id' => $form->_eventId, 'priceSetId' => $this->_ids['price_set'], - 'price_' . $this->_ids['price_field'][0] => [ - $this->_ids['price_field_value'][0] => 1, - ], + 'price_' . $this->_ids['price_field'][0] => $this->_ids['price_field_value'][0], 'is_pay_later' => 1, 'amount_level' => 'Too much', 'fee_amount' => 55, @@ -109,14 +107,14 @@ public function testSubmitUnpaidPriceChangeWhileStillPending() { $lineItem = CRM_Price_BAO_LineItem::getLineItems($participants['id'], 'participant'); // Participants is updated to 0 but line remains. $this->assertEquals(0, $lineItem[1]['subTotal']); - $this->assertEquals(100, $lineItem[2]['subTotal']); + $this->assertEquals(1550.55, $lineItem[2]['subTotal']); $financialItems = $this->callAPISuccess('FinancialItem', 'get', []); $sum = 0; foreach ($financialItems['values'] as $financialItem) { $sum += $financialItem['amount']; } - $this->assertEquals(100, $sum); + $this->assertEquals(1550.55, $sum); } /** @@ -300,7 +298,7 @@ public function testParticipantOfflineReceipt($thousandSeparator) { */ protected function getForm($eventParams = []) { if (!empty($eventParams['is_monetary'])) { - $event = $this->eventCreatePaid($eventParams); + $event = $this->eventCreatePaid($eventParams, [['name' => 'big', 'amount' => 1550.55]]); } else { $event = $this->eventCreate($eventParams); @@ -452,10 +450,8 @@ private function getSubmitParams(int $eventID, int $paymentProcessorID): array { 'billing_postal_code-5' => 10545, 'billing_country_id-5' => 1228, 'payment_processor_id' => $paymentProcessorID, - 'priceSetId' => '6', - 'price_7' => [ - 13 => 1, - ], + 'priceSetId' => $this->_ids['price_set'], + 'price_' . $this->_ids['price_field'][0] => $this->_ids['price_field_value'][1], 'amount_level' => 'Too much', 'fee_amount' => $this->formatMoneyInput(1550.55), 'total_amount' => $this->formatMoneyInput(1550.55), diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 8d416d4a0232..68f77a6ec7f1 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -1044,13 +1044,15 @@ public function eventCreate($params = []) { * * @param array $params * + * @param array $options + * * @return array * * @throws \CRM_Core_Exception */ - protected function eventCreatePaid($params) { + protected function eventCreatePaid($params, $options = [['name' => 'hundy', 'amount' => 100]]) { $event = $this->eventCreate($params); - $this->priceSetID = $this->eventPriceSetCreate(55, 0, 'Radio'); + $this->priceSetID = $this->ids['PriceSet'][] = $this->eventPriceSetCreate(55, 0, 'Radio', $options); CRM_Price_BAO_PriceSet::addTo('civicrm_event', $event['id'], $this->priceSetID); $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($this->priceSetID, TRUE, FALSE); $priceSet = CRM_Utils_Array::value($this->priceSetID, $priceSet); @@ -2629,11 +2631,13 @@ protected function assertLike($expectedSQL, $actualSQL, $message = 'different sq * @param int $minAmt * @param string $type * + * @param array $options + * * @return int * Price Set ID. * @throws \CRM_Core_Exception */ - protected function eventPriceSetCreate($feeTotal, $minAmt = 0, $type = 'Text') { + protected function eventPriceSetCreate($feeTotal, $minAmt = 0, $type = 'Text', $options = [['name' => 'hundy', 'amount' => 100]]) { // creating price set, price field $paramsSet['title'] = 'Price Set'; $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set'); @@ -2663,9 +2667,13 @@ protected function eventPriceSetCreate($feeTotal, $minAmt = 0, $type = 'Text') { 'financial_type_id' => $this->getFinancialTypeId('Event Fee'), ]; if ($type === 'Radio') { - $paramsField['is_enter_qty'] = 0; - $paramsField['option_value'][2] = $paramsField['option_weight'][2] = $paramsField['option_amount'][2] = 100; - $paramsField['option_label'][2] = $paramsField['option_name'][2] = 'hundy'; + foreach ($options as $index => $option) { + $paramsField['is_enter_qty'] = 0; + $optionID = $index + 2; + $paramsField['option_value'][$optionID] = $paramsField['option_weight'][$optionID] = $paramsField['option_amount'][$optionID] = $option['amount']; + $paramsField['option_label'][$optionID] = $paramsField['option_name'][$optionID] = $option['name']; + } + } $this->callAPISuccess('PriceField', 'create', $paramsField); $fields = $this->callAPISuccess('PriceField', 'get', ['price_set_id' => $this->_ids['price_set']]);