From b19a403d771544b388e201c2fd34822b10d57bfd Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 30 Oct 2019 23:14:01 +1300 Subject: [PATCH] [NFC] code cleanup on test class --- .../CRM/Event/BAO/ChangeFeeSelectionTest.php | 74 +++++++++++++------ 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php b/tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php index 622d37612a..7c7b3defb5 100644 --- a/tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php +++ b/tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php @@ -59,6 +59,9 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { /** * Set up for test. + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ public function setUp() { parent::setUp(); @@ -86,11 +89,11 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { * @param string $type * * @return int + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception * @todo resolve this with parent function. */ protected function priceSetCreate($type = 'Radio') { - $feeTotal = 55; - $minAmt = 0; $paramsSet['title'] = 'Two Options' . substr(sha1(rand()), 0, 4); $paramsSet['name'] = CRM_Utils_String::titleToVar('Two Options') . substr(sha1(rand()), 0, 4); $paramsSet['is_active'] = FALSE; @@ -98,7 +101,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { $priceSet = CRM_Price_BAO_PriceSet::create($paramsSet); - if ($type == 'Text') { + if ($type === 'Text') { $paramsField = [ 'label' => 'Text Price Field', 'name' => CRM_Utils_String::titleToVar('text_price_field'), @@ -118,14 +121,15 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { ]; } else { + /** @noinspection UnNecessaryDoubleQuotesInspection */ $paramsField = [ 'label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Two Options'), 'html_type' => 'Radio', //'price' => $feeTotal, - 'option_label' => ['1' => 'Expensive Room', '2' => "Cheap Room", '3' => 'Very Expensive', '4' => 'No Fee'], + 'option_label' => ['1' => 'Expensive Room', '2' => 'Cheap Room', '3' => 'Very Expensive', '4' => 'No Fee'], 'option_value' => ['1' => 'E', '2' => 'C', '3' => 'V', '4' => 'N'], - 'option_name' => ['1' => 'Expensive', '2' => "Cheap", "3" => "Very Expensive", '3' => 'No Fee'], + 'option_name' => ['1' => 'Expensive', '2' => 'Cheap', '3' => 'Very Expensive'], 'option_weight' => ['1' => 1, '2' => 2, '3' => 3, '4' => 4], 'option_amount' => ['1' => $this->_expensiveFee, '2' => $this->_cheapFee, '3' => $this->_veryExpensive, '4' => $this->_noFee], 'option_count' => [1 => 1, 2 => 1, 3 => 1, 4 => 1], @@ -182,7 +186,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { WHERE contribution_id = {$contributionId}"; $dao = CRM_Core_DAO::executeQuery($query); - $this->assertTrue($dao->fetch(), "Succeeded retrieving invoicetotal"); + $this->assertTrue($dao->fetch(), 'Succeeded retrieving invoice total'); return $dao->total; } @@ -202,7 +206,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { "; $dao = CRM_Core_DAO::executeQuery($query); - $this->assertTrue($dao->fetch(), "Succeeded retrieving total Income"); + $this->assertTrue($dao->fetch(), 'Succeeded retrieving total Income'); return $dao->total; } @@ -218,6 +222,10 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { /** * Prepare records for editing. + * + * @param null $actualPaidAmt + * + * @throws \CRM_Core_Exception */ public function registerParticipantAndPay($actualPaidAmt = NULL) { $params = [ @@ -225,7 +233,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $this->_eventId, - 'register_date' => date('Y-m-d') . " 00:00:00", + 'register_date' => date('Y-m-d') . ' 00:00:00', 'role_id' => 1, 'status_id' => 1, 'source' => 'Event_' . $this->_eventId, @@ -235,18 +243,18 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { $participant = $this->callAPISuccess('Participant', 'create', $params); $this->_participantId = $participant['id']; - $actualPaidAmt = $actualPaidAmt ? $actualPaidAmt : $this->_expensiveFee; + $actualPaidAmt = $actualPaidAmt ?: $this->_expensiveFee; $contributionParams = [ 'total_amount' => $actualPaidAmt, - 'source' => 'Testset with information', + 'source' => 'Test set with information', 'currency' => 'USD', - 'receipt_date' => date('Y-m-d') . " 00:00:00", + 'receipt_date' => date('Y-m-d') . ' 00:00:00', 'contact_id' => $this->_contactId, 'financial_type_id' => 4, 'payment_instrument_id' => 4, 'contribution_status_id' => 1, - 'receive_date' => date('Y-m-d') . " 00:00:00", + 'receive_date' => date('Y-m-d') . ' 00:00:00', 'skipLineItem' => 1, 'partial_payment_total' => $this->_expensiveFee, 'partial_amount_to_pay' => $actualPaidAmt, @@ -271,43 +279,50 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { } + /** + * @throws \CRM_Core_Exception + */ public function testCRM19273() { $this->registerParticipantAndPay(); $priceSetParams['price_' . $this->priceSetFieldID] = $this->cheapFeeValueID; $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant'); - CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee); + CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem); $this->balanceCheck($this->_cheapFee); $priceSetParams['price_' . $this->priceSetFieldID] = $this->expensiveFeeValueID; $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant'); - CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee); + CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem); $this->balanceCheck($this->_expensiveFee); $priceSetParams['price_' . $this->priceSetFieldID] = $this->veryExpensiveFeeValueID; $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant'); - CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee); + CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem); $this->balanceCheck($this->_veryExpensive); } /** * CRM-21245: Test that Contribution status doesn't changed to 'Pending Refund' from 'Partially Paid' if the partially paid amount is lower then newly selected fee amount + * + * @throws \CRM_Core_Exception */ public function testCRM21245() { $this->registerParticipantAndPay(50); - $partiallyPaidContribuitonStatus = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Partially paid'); - $this->assertEquals($this->callAPISuccessGetValue('Contribution', ['id' => $this->_contributionId, 'return' => 'contribution_status_id']), $partiallyPaidContribuitonStatus); + $partiallyPaidContributionStatus = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Partially paid'); + $this->assertEquals($this->callAPISuccessGetValue('Contribution', ['id' => $this->_contributionId, 'return' => 'contribution_status_id']), $partiallyPaidContributionStatus); $priceSetParams['price_' . $this->priceSetFieldID] = $this->veryExpensiveFeeValueID; $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant'); CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem); - $this->assertEquals($this->callAPISuccessGetValue('Contribution', ['id' => $this->_contributionId, 'return' => 'contribution_status_id']), $partiallyPaidContribuitonStatus); + $this->assertEquals($this->callAPISuccessGetValue('Contribution', ['id' => $this->_contributionId, 'return' => 'contribution_status_id']), $partiallyPaidContributionStatus); } /** * Test that proper financial items are recorded for cancelled line items + * + * @throws \CRM_Core_Exception */ public function testCRM20611() { $this->registerParticipantAndPay(); @@ -360,6 +375,9 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { /** * Test to ensure that correct financial records are entered on text price field fee change on event registration + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ public function testCRM21513() { $this->_priceSetID = $this->priceSetCreate('Text'); @@ -373,7 +391,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $this->_eventId, - 'register_date' => date('Y-m-d') . " 00:00:00", + 'register_date' => date('Y-m-d') . ' 00:00:00', 'role_id' => 1, 'status_id' => 1, 'source' => 'Event_' . $this->_eventId, @@ -383,14 +401,14 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { $this->_participantId = $participant['id']; $contributionParams = [ 'total_amount' => 10, - 'source' => 'Testset with information', + 'source' => 'Test set with information', 'currency' => 'USD', - 'receipt_date' => date('Y-m-d') . " 00:00:00", + 'receipt_date' => date('Y-m-d') . ' 00:00:00', 'contact_id' => $this->_contactId, 'financial_type_id' => 4, 'payment_instrument_id' => 4, 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Pending'), - 'receive_date' => date('Y-m-d') . " 00:00:00", + 'receive_date' => date('Y-m-d') . ' 00:00:00', 'skipLineItem' => 1, ]; @@ -412,12 +430,12 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { // CASE 2: Choose text price qty 3 (x$10 = $30 amount) $priceSetParams['price_' . $this->priceSetFieldID] = 3; $lineItem = CRM_Price_BAO_LineItem::getLineItems($participant['id'], 'participant'); - CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $participant['id'], 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, 0); + CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $participant['id'], 'participant', $this->_contributionId, $this->_feeBlock, $lineItem); // CASE 3: Choose text price qty 2 (x$10 = $20 amount) $priceSetParams['price_' . $this->priceSetFieldID] = 2; $lineItem = CRM_Price_BAO_LineItem::getLineItems($participant['id'], 'participant'); - CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $participant['id'], 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, 0); + CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $participant['id'], 'participant', $this->_contributionId, $this->_feeBlock, $lineItem); $financialItems = $this->callAPISuccess('FinancialItem', 'Get', [ 'entity_table' => 'civicrm_line_item', @@ -462,6 +480,8 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { /** * CRM-17151: Test that Contribution status change to 'Completed' if balance is zero. + * + * @throws \CRM_Core_Exception */ public function testCRM17151() { $this->registerParticipantAndPay(); @@ -487,6 +507,8 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { /** * Test that recording a refund when fee selection is 0 works + * + * @throws \CRM_Core_Exception */ public function testRefundWithFeeAmount0() { $this->registerParticipantAndPay(); @@ -540,6 +562,8 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { /** * dev-financial-40: Test that partial payment entries in entity-financial-trxn table to ensure that reverse transaction is entered + * + * @throws \CRM_Core_Exception */ public function testPartialPaymentEntries() { $this->registerParticipantAndPay($this->_expensiveFee); @@ -579,6 +603,8 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { /** * dev-financial-40: Test that refund payment entries in entity-financial-trxn table to ensure that reverse transaction is entered on fee change to lesser amount + * + * @throws \CRM_Core_Exception */ public function testRefundPaymentEntries() { $this->registerParticipantAndPay($this->_expensiveFee); -- 2.25.1