Skip to content

Commit

Permalink
Fix unit test so price set params are valid
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jan 21, 2020
1 parent e6568db commit 2d6f64f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
16 changes: 6 additions & 10 deletions tests/phpunit/CRM/Event/Form/ParticipantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand Down
20 changes: 14 additions & 6 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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']]);
Expand Down

0 comments on commit 2d6f64f

Please sign in to comment.